使用了WGCNA示例數(shù)據(jù),計(jì)算了矩陣兩兩相關(guān)性,發(fā)現(xiàn)其中有use這個(gè)參數(shù)當(dāng)中的設(shè)置變化時(shí),其結(jié)果也有所變化。記錄一下。
使用的數(shù)據(jù)
使用的是WGCNA官方文檔提供的數(shù)據(jù)

使用不同參數(shù)計(jì)算矩陣相關(guān)性
使用use = 'p'參數(shù)
> cor_data <- cor(datExpr,use = 'p', method = 'pearson')
> cor_data[1:5,1:5]
MMT00000044 MMT00000046 MMT00000051 MMT00000076 MMT00000080
MMT00000044 1.00000000 -0.03797242 0.09326526 0.24716099 0.13636580
MMT00000046 -0.03797242 1.00000000 -0.56393957 -0.02934881 -0.06291723
MMT00000051 0.09326526 -0.56393957 1.00000000 0.06120014 -0.05422173
MMT00000076 0.24716099 -0.02934881 0.06120014 1.00000000 -0.02327867
MMT00000080 0.13636580 -0.06291723 -0.05422173 -0.02327867 1.00000000
使用use = "everything" 參數(shù)
> cor_data <- cor(datExpr, method = "pearson",use = "everything" )
> cor_data[1:5,1:5]
MMT00000044 MMT00000046 MMT00000051 MMT00000076 MMT00000080
MMT00000044 1.00000000 -0.03797242 0.09326526 NA 0.13636580
MMT00000046 -0.03797242 1.00000000 -0.56393957 NA -0.06291723
MMT00000051 0.09326526 -0.56393957 1.00000000 NA -0.05422173
MMT00000076 NA NA NA 1 NA
MMT00000080 0.13636580 -0.06291723 -0.05422173 NA 1.00000000
使用use = "all.obs"提示錯(cuò)誤,有遺漏值
> cor_data <- cor(datExpr, method = "pearson",use = "all.obs" )
Error in cor(datExpr, method = "pearson", use = "all.obs") :
cov/cor中有遺漏值
使用use = "complete.obs"
> cor_data <- cor(datExpr, method = "pearson",use = "complete.obs" )
> cor_data[1:5,1:5]
MMT00000044 MMT00000046 MMT00000051 MMT00000076 MMT00000080
MMT00000044 1.00000000 0.02925872 -0.1375516 0.62442994 0.14064180
MMT00000046 0.02925872 1.00000000 -0.5110969 0.03828571 0.19707483
MMT00000051 -0.13755164 -0.51109691 1.0000000 0.11570214 -0.18874582
MMT00000076 0.62442994 0.03828571 0.1157021 1.00000000 -0.04126554
MMT00000080 0.14064180 0.19707483 -0.1887458 -0.04126554 1.00000000
使用use = "na.or.complete"
> cor_data <- cor(datExpr, method = "pearson",use = "na.or.complete" )
> cor_data[1:5,1:5]
MMT00000044 MMT00000046 MMT00000051 MMT00000076 MMT00000080
MMT00000044 1.00000000 0.02925872 -0.1375516 0.62442994 0.14064180
MMT00000046 0.02925872 1.00000000 -0.5110969 0.03828571 0.19707483
MMT00000051 -0.13755164 -0.51109691 1.0000000 0.11570214 -0.18874582
MMT00000076 0.62442994 0.03828571 0.1157021 1.00000000 -0.04126554
MMT00000080 0.14064180 0.19707483 -0.1887458 -0.04126554 1.00000000
使用use = "pairwise.complete.obs"參數(shù)
> cor_data <- cor(datExpr, method = "pearson",use = "pairwise.complete.obs" )
> cor_data[1:5,1:5]
MMT00000044 MMT00000046 MMT00000051 MMT00000076 MMT00000080
MMT00000044 1.00000000 -0.03797242 0.09326526 0.24716099 0.13636580
MMT00000046 -0.03797242 1.00000000 -0.56393957 -0.02934881 -0.06291723
MMT00000051 0.09326526 -0.56393957 1.00000000 0.06120014 -0.05422173
MMT00000076 0.24716099 -0.02934881 0.06120014 1.00000000 -0.02327867
MMT00000080 0.13636580 -0.06291723 -0.05422173 -0.02327867 1.00000000
對(duì)各個(gè)參數(shù)的意義進(jìn)行學(xué)習(xí)
查閱官方文檔,給出的解釋如下
If use is "everything", NAs will propagate conceptually, i.e., a resulting value will be NA whenever one of its contributing observations is NA.
If use is "all.obs", then the presence of missing observations will produce an error. If use is "complete.obs" then missing values are handled by casewise deletion (and if there are no complete cases, that gives an error).
"na.or.complete" is the same unless there are no complete cases, that gives NA. Finally, if use has the value "pairwise.complete.obs" then the correlation or covariance between each pair of variables is computed using all complete pairs of observations on those variables. This can result in covariance or correlation matrices which are not positive semi-definite, as well as NA entries if there are no complete pairs for that pair of variables. For cov and var, "pairwise.complete.obs" only works with the "pearson" method. Note that (the equivalent of) var(double(0), use = *) gives NA for use = "everything" and "na.or.complete", and gives an error in the other cases.
翻譯一下
如果使用的是 "all.obs",那么存在缺失的觀察值會(huì)產(chǎn)生一個(gè)錯(cuò)誤。如果使用的是 "complete.obs",那么缺失值將通過(guò)個(gè)案刪除來(lái)處理(如果沒(méi)有完整的個(gè)案,則會(huì)產(chǎn)生錯(cuò)誤)。
如果使用值為 "pairwise.complete.obs",那么每對(duì)變量之間的相關(guān)性或協(xié)方差將使用這些變量上的所有完整觀測(cè)對(duì)進(jìn)行計(jì)算。這可能導(dǎo)致協(xié)方差或相關(guān)矩陣不是正半無(wú)限的,如果沒(méi)有完整的變量對(duì),也可能導(dǎo)致NA條目。
對(duì)于cov和var,"pairwise.complete.obs "只適用于 "pearson "方法。注意,(相當(dāng)于)var(double(0), use = *)對(duì)于use = "everything "和 "na.or.complete "給出了NA,而在其他情況下給出了一個(gè)錯(cuò)誤。
大致可以這么理解
all.obs:假設(shè)不存在缺失數(shù)據(jù),遇到缺失數(shù)據(jù)時(shí)將報(bào)錯(cuò)
everything:遇到缺失數(shù)據(jù)時(shí),相關(guān)系數(shù)的計(jì)算結(jié)果將設(shè)為missing
complete.obs:遇到缺失數(shù)據(jù)時(shí),行刪除
pairwise.complete.obs:成對(duì)刪除
大致先這樣理解了