Hmisc::rcorr 给出 0 p 值,但 cor.test 不给出

问题描述 投票:0回答:1

我需要获取矩阵的相关性和 p 值,因此我尝试了 Hmisc 包中的 rcorr 。问题是我的一对 pvalue 为 0,这给了我 1.036733e-59 和 cor.test 函数。

我对每个函数都使用了 pearson。

这是一个可重现的示例。

library(Hmisc)
A <- c(6.32451531850417,6.396670829087,6.86361544161307,6.69938199174752,13.165463943882,6.90981191583279,13.1464308794264,6.52552248884005,6.08631376117103,6.61690829991384,6.77722148405774,6.49620534991742,6.5518962525994,6.2497899855603,6.8646997315825,6.69081335429442,6.70869072803975,6.87789921476436,6.56641042358147,6.84013201548233,6.69568254965127,6.70640778501988,6.62246110671344,6.67829056829049,6.65799888115762,6.24141301052501,6.69746610666983,6.68902124059975,6.64539017705934,6.81328563238539,7.06715007760963,6.75490752235589,6.49012918187287,12.7208750140264,6.73382593460874,6.35761704581448,7.28515563569873,6.67369856749724,6.66992764180906,6.40471908440153,6.30772659143547,6.45098473518897,6.60578485189021,6.50990123242974,6.40449000722152,6.50128036958986,6.66306523170188,6.45702244416934,6.28566653849103,6.42625738798208,6.88706148070107,6.35110357440403,6.68612827575002,6.58213967827742,6.37737813156623,6.38199814182166,6.7091244513399,6.46266526892103,6.46052608198987,6.57481275927555,6.60832078443043,6.75222494716443,6.55842628702281,6.67547286814189,6.51448496000258,6.67177207392162,6.69153307744344,6.69836071289889,6.6615217504183,6.63805883879528,6.36018525770115,6.50727400620095,6.38370628835495,6.81563624248625,6.62298705858254,6.41641698679136,6.29103959938316,6.64396635235954,6.76381424552375,6.51339014760998,6.63043442032935,6.93781852637583,6.59535594885934,7.0997394675434,6.19171479075248,6.28123555799257,6.43057159585162,6.5869614799051)
B <- c(3.9995637786823,3.48601398807956,4.03812725251975,3.81851391342822,11.7502675850666,3.98407110753864,11.8300601767337,3.59623022007111,3.47594268425866,3.39485541409169,3.96156903705731,3.84385038139104,4.40329546631133,3.69704624452915,3.87264919566187,3.90460396437268,3.45875737518772,3.95915349682997,4.37078882304428,3.79514714207642,3.85315638891753,3.82101134020264,3.76652556154815,3.78168978057991,4.38817115664092,3.67188258569308,3.93083752538972,4.09512848434603,3.76017250778245,3.93149619446255,3.73967734750671,3.79329645229012,3.72530038941995,11.6296199270195,3.76362438867387,3.52361952114506,5.05916028061208,3.78174363576111,3.77862237861648,3.96446993299436,3.95420785742674,3.65350904888874,3.74208843021492,3.7864852643104,3.34969922277165,3.76699340323312,3.90279649287842,3.48792692835044,3.54100392028721,3.73429478892297,4.07755160257201,3.71095088992823,3.96086251069495,3.62303629160269,3.50473542630912,3.45494734742944,3.62764756649661,3.50045819158303,4.75363129670227,3.66796624908498,4.41415957987699,3.61676764219056,4.35208487010989,3.63812742107392,3.61369595503799,3.6738293973286,3.79492785542216,4.89013596433762,3.70204962677728,3.52121048655018,3.59305187045436,3.58411383210404,3.50590908471792,3.73025791048932,4.0143103011064,3.6584374210132,3.72337929455363,3.7766291637304,3.55626499087112,4.11134785621808,4.03941383606145,3.81034661576582,4.15448306192498,4.73600249458588,3.57585585559837,3.76987550019725,3.72667260885011,3.55088410428519)
C <- c(5.0828344582765,5.44171716119668,5.50349616275127,6.20354287213394,6.99263387581131,5.53286444824163,6.66169084634442,5.16933585666197,4.99851910038837,5.18468358275925,5.94408569177543,5.38879105718559,5.1963019014005,4.90579273695638,5.40610158292019,5.97408534843616,5.6634072236913,5.71035471476711,5.30554917408064,5.60513350695794,5.59638539269362,5.54571609819415,5.26763404068582,5.88068748660826,5.20462261826007,5.28737753968805,5.41548211806564,5.23988511286448,5.45891799263611,5.33513304020226,5.38926947164349,5.78004326608306,5.53385821088178,6.70309488254236,5.72120763082083,5.43668800424696,5.31591419975872,5.55446882414854,5.39756885193532,5.34660398519912,4.98008442404427,5.07080405039416,5.03893220932515,5.11538656986937,5.19477846798434,5.27241946711687,5.15677380833086,5.20070799769709,5.611572982919,4.83939324104591,5.36607457080691,5.21935359026813,5.70039096365024,5.29675323855941,5.02690902121225,5.04349564595055,5.17171742744466,5.21386568112692,5.25785400845595,4.77688955147304,5.89435056128631,5.44712026551928,5.31047450193841,5.11339046941959,5.23862350238358,5.39464522888807,5.24658651925926,5.13548147374252,5.04054442277134,5.0942112627996,4.8247921182326,5.21145125468889,5.25857361278046,5.01095797437389,5.6214184959344,5.07188964223442,5.17615526987811,5.3227559035551,5.43031530449701,5.27626866543545,5.45060599999116,5.2667271685913,5.12852923511888,5.2622926326258,5.35048009048626,4.92554974015645,5.14856255783588,5.75558021935756)
mtx <- cbind(A,B,C)
rcorrelation <- rcorr(mtx, type="pearson")
rcorrelation$P["A","B"] # 0
rcorrelation$P["A","C"] # 2.220446e-16
cor.test(A,B, method="pearson")$p.value # 1.036733e-59
cor.test(A,C, method="pearson")$p.value # 2.181905e-16

如何使用 rcorr 将 1.036733e-59 作为 p 值?

我有一个最大的矩阵,并且某些 p 值有很多 0,我需要对它们进行排名,即使它们都接近 0...

谢谢

PS:具有 2 个功能的一对 A/C 存在很小(较小?)的差异,但这不是我目前的问题...

r correlation hmisc
1个回答
0
投票

差异(顺便说一下,差异是无限小的)可能是由于相关测试的实施方式不同所致。 AFAICT

rcorr
使用 Fortran,而
cor.test
最常使用一些用 C 实现的东西。
rcorr
中测试的实现在某些情况下返回精确的 0,而
cor.test
返回超过 60 位十进制数字的值。

如果您想模仿

rcorr
的行为,即获取矩阵中所有列对的 p 值,您可以使用
combn
apply
执行以下操作:

get_corr_p <- function(x) {
  # the x argument is a vector of length two with the variable names
  cor.test(get(x[1]), get(x[2]))$p.value
}
apply(combn(c("A", "B", "C"), 2), 2, get_corr_p)

但正如 @Roland 所指出的,对 p 值进行排名没有意义。从概念上讲,您可以使用 p 值来检查是否存在错误拒绝假设的风险(在本例中相关系数等于 0)。通常,此风险的阈值设置为 5%,因此如果 p<0.05 then the risk of saying "there is a correlation" and that not being true is low enough, and we can make that statement. There is no such thing as "more significant", either the difference is significant or it isn't (given the threshold you selected). It is a yes/no thing, so it makes no sense to rank p-values.

© www.soinside.com 2019 - 2024. All rights reserved.