我正在对我的数据集进行分析,示例数据框 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
Run Code Online (Sandbox Code Playgroud)
我想检查变量之间的相关性,所以我使用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)
Run Code Online (Sandbox Code Playgroud)
由于结果不是我所期望的,我想仔细检查该方法是否有效。为了测试这一点,我想简单地将一些变量对放入lm(). 我的假设是lm()摘要中的 R2 应与我的corplot. 但事实并非如此。
1/我的假设有什么问题?为什么lm()R2不对应rcor()或cor()r?2/ 什么是合适的测试来检查我提供的相关性corplot是否值得信赖?如果我们的结果显示与文献相矛盾的内容(就像这里的情况一样),运行备份测试总是好的。
简单线性回归的 R\xc2\xb2 不是相关性,而是自变量和因变量之间相关性的平方。
\nx <- 1:5\ny <- rnorm(5)\n\ncor(x, y)^2\n# 0.001016668\nsummary(lm(y ~ x))$r.squared\n# 0.001016668\nRun Code Online (Sandbox Code Playgroud)\n