R语言进行的变量相关性显著性检验 |
您所在的位置:网站首页 › 求两组数据的相关系数公式是 › R语言进行的变量相关性显著性检验 |
R语言进行的变量相关性显著性检验
在计算好相关系数以后,如何对它们进行统计显著性检验呢? 常用的原假设为变量间不相关(即总体的相关系数为0)。可以使用cor.test()函数对单个的Pearson、Spearman和Kendall相关系数进行检验。 简化后的使用格式为: cor.test(x,y,alternative="……",method="……") 其中x和y为要检验相关性的变量,alternative则用来指定进行单侧检验或双侧检验,取值为two.side、less、greater,而method用以指定要计算的相关类型(“pearson”、“Kendall”、“spearman”). 当研究的假设为总体的相关系数小于0时,请使用alternative=“less”; 在研究的假设为总体的相关系数大于0时,应该使用alternative=“greater”; 在默认情况下,假设为总体相关系数不等于0,alternative=“two.side”. 例如语句:cor.test(states[,3],states[,5]) 遗憾的是,cor.test每次只能检验一种相关关系,而corr.test()函数可以一次做更多事情。 使用格式: corr.test(x,use=,method) use=的取值可以为pairwise或complete,其中pairwise表示对缺失值执行成对删除,而complete表示对缺失值执行行删除; 参数method取值可为“pearson ”、“spearson”、“kendall”. 另外,在多元正态性的假设下,psych包中的pcor.test()函数可以用来检验在一个或多个额外变量时两个变量之间的条件独立性。 使用格式: pcor.test(r,q,n) 其中r是偏相关系数矩阵; q为要控制的变量数u(以数值表示位置); n为样本大小。 实战 pearson检验输入下面的命令实现检验: cor.test(data $ x, data $ y,alternative = “two.sided”,method = “pearson”,conf.level = 0.95) 结果为: Pearson's product-moment correlation data: data $ x and data $ y t = 5.0618, df = 98, p-value = 1.946e-06 alternative hypothesis: true correlation is not equal to 0 95 percent confidence interval: 0.2842595 0.5981865 sample estimates: cor 0.4552588从中可以看出二者的相关性系数为0.4552588,检验p值为1.946e-06 |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |