【问题标题】:Comparison between lm() and cor() - why the results are not correspondinglm() 和 cor() 之间的比较 - 为什么结果不对应
【发布时间】:2020-10-07 16:04:08
【问题描述】:

我正在对我的数据集进行分析,示例数据框 df:

   DOY     species replicate position      SLA      PAR      temp    A1200    susPQ    susNPQ      FvFm      
1:  46 LINGONBERRY         1      LOW 65.75638 19.70906 -2.850833 0.569690 2.147297 0.9321771 0.5263661 562.1016 0.011440    28.02628
2:  46 LINGONBERRY         2      LOW 59.45028 19.78096 -2.850833 0.893840 2.511543 1.0516496 0.5503916 533.6136 0.028930    25.40703
3:  46 LINGONBERRY         3      LOW 59.51058 17.52833 -2.850833 0.731765 2.278927 1.0678274 0.5242824 549.6316 0.020185    46.16188
4:  46        PINE         1      LOW 35.90156 20.85151 -2.850833 1.518910 2.319431 2.2168853 0.4189484 392.6067 0.059280    47.79101
5:  46        PINE         1      TOP 27.29495 90.27197 -2.850833 1.780420 1.739912 1.5691443 0.4037803 418.3636 0.032890    59.03595
6:  46        PINE         2      LOW 34.38626 27.86268 -2.850833 1.959910

我想检查变量之间的相关性,所以我使用cor()rcor() 函数。

cor.df <-corrplot(cor(df[,c(1,5:19)], method = "pearson"), method = "number", type = "upper", 
                  tl.col = "black")   

df_matrix <- as.matrix(df[,c(1,5:19)])
rcor.df <- rcorr(df_matrix, type ="pearson")

cor.df_R <-corrplot(rcor.df$r, method = "number", type = "upper", tl.col = "black", 
                    p.mat = rcor.df$P, sig.level = 0.001) 

r-correlation plot for my variables with "unsignificant" correlations crossed

由于结果不是我所期望的,我想再次检查该方法是否有效。为了测试这一点,我想简单地将一些变量对放入lm()。我的假设是来自lm() 摘要的 R2 应该与在我的corplot 中提供的值相同。但是,事实并非如此。

1/ 我的假设有什么问题?为什么lm() R2 不对应rcor()cor() r? 2/ 什么是合适的测试来检查我在corplot 中提供的相关性是否值得信赖?运行备份测试总是好的,以防我们的结果显示与文献相矛盾(就像这里的情况一样)。

【问题讨论】:

  • 如果没有可重现的例子,我只能猜测。也许这与处理缺失值有关?
  • 您可以将cor()^2 与 R^2 进行比较。

标签: r correlation lm


【解决方案1】:

简单线性回归的R²不是相关性,而是自变量与因变量之间相关性的平方

x <- 1:5
y <- rnorm(5)

cor(x, y)^2
# 0.001016668
summary(lm(y ~ x))$r.squared
# 0.001016668

【讨论】:

  • 这回答了我的问题!我喜欢解决方案如此简单。谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-02-24
  • 2016-08-20
  • 2014-01-19
相关资源
最近更新 更多