【发布时间】:2019-03-16 01:49:18
【问题描述】:
我有这样的数据
name col1 col2 col3
1 a 43.78 43.80 43.14
2 b 43.84 43.40 42.85
3 c 37.92 37.64 37.54
4 d 31.72 31.62 31.74
我们称它为 df
df<-structure(list(name = structure(1:4, .Label = c("a", "b", "c",
"d"), class = "factor"), col1 = c(43.78, 43.84, 37.92, 31.72),
col2 = c(43.8, 43.4, 37.64, 31.62), col3 = c(43.14, 42.85,
37.54, 31.74)), class = "data.frame", row.names = c(NA, -4L
))
现在我想计算行 d 和其他行之间的 R2 和调整后的 R2
如果我想查看所有组合,我可以执行以下相关操作
out <- cor(t(df[, -1]))
out[upper.tri(out, diag = TRUE)] <- NA
rownames(out) <- colnames(out) <- df$name
out <- na.omit(reshape::melt(t(out)))
out <- out[ order(out$X1, out$X2), ]
这给了我这个
X1 X2 value
5 a b 0.8841255
9 a c 0.6842705
13 a d -0.6491118
10 b c 0.9457125
14 b d -0.2184630
15 c d 0.1105508
但我只想要在第 d 行和其他行之间,并且我想要同时拥有相关系数和调整后的 R2
【问题讨论】:
标签: r