gpt4 book ai didi

r - 两个相关系数差异的显着性检验

转载 作者:行者123 更新时间:2023-12-04 11:40:29 24 4
gpt4 key购买 nike

您如何测试两个相关系数是否显着不同 - 在 GNU R 中?

也就是说,如果相同变量(例如年龄和收入)之间的影响在两个不同的总体(子样本)中是不同的。

有关背景信息,请参阅 How do I compare correlation coefficients of the same variables across different groupsSignificance test on the difference of Spearman's correlation coefficient (均在 CrossValidated)。

最佳答案

如果您想比较多对系数(基于 Significance of the difference between two correlation coefficientsQuantitative Analysis and Politics, PDF ),这里有一个适用于 GNU R 的现成函数:

cor.diff.test = function(r1, r2, n1, n2, alternative = c("two.sided", "less", "greater")) {

Z1 = 0.5 * log( (1+r1)/(1-r1) )
Z2 = 0.5 * log( (1+r2)/(1-r2) )

diff = Z1 - Z2
SEdiff = sqrt( 1 / (n1 - 3) + 1 / (n2 - 3))
diff.Z = diff / SEdiff

if (alternative == "less") {
return(pnorm(diff.Z, lower.tail=F))
} else if (alternative == "greater") {
return(pnorm(-diff.Z, lower.tail=F))
} else if (alternative == "two.sided") {
return(2 * pnorm( abs(diff.Z), lower.tail=F))
} else {
warning(paste("Invalid alterantive", alternative), domain=NA)
return(NA)
}
}

关于r - 两个相关系数差异的显着性检验,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14519006/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com