在 R 中将数据帧转换为 cor.mat 数据类型
我有一个属于数据帧数据类型的相关矩阵。
#creates correlation matrix of dataframe data type
eff_1971 <- c(NA, .56, .25, .25, .22, -.47, -.01, -.06)
eff_1972 <- c(.56, NA, .23, .23, .25, .47, -.01, .03)
annual_earnings_1970 <- c(.25, .23, NA, .88, .83, -.02, -.28, -.14)
annual_earnings_1971 <- c(.25, .23, .88, NA, .88, -.02, .21, -.29)
annual_earnings_1972 <- c(.22, .25, .83, .88, NA, .03, .06, .21)
change_eff_1971_1972 <- c(-.47, .47, -.02, -0.02, 0.03, NA, 0.0, .1)
change_ann_earn_1970_1971 <- c(-.01, -.01, -.28, .21, .06, 0.0, NA, -.29)
change_ann_earn_1971_1972 <- c(-.06, .03, -.14, -.29, .21, .10, -.29, NA)
df <- data.frame(eff_1971,
eff_1972,
annual_earnings_1970,
annual_earnings_1971,
annual_earnings_1972,
change_eff_1971_1972,
change_ann_earn_1970_1971,
change_ann_earn_1971_1972)
rownames(df) <- c("eff_1971","eff_1972","annual_earnings_1970",
"annual_earnings_1971", "annual_earnings_1972", "change_eff_1971_1972",
"change_ann_ear_1970_1971", "change_ann_earn_1971_1972")
如何将其转换为 cor.mat
数据类型?我想使用 cor2cov 将此相关矩阵转换为协方差矩阵。
非常感谢!
I have a correlation matrix that is a dataframe data type.
#creates correlation matrix of dataframe data type
eff_1971 <- c(NA, .56, .25, .25, .22, -.47, -.01, -.06)
eff_1972 <- c(.56, NA, .23, .23, .25, .47, -.01, .03)
annual_earnings_1970 <- c(.25, .23, NA, .88, .83, -.02, -.28, -.14)
annual_earnings_1971 <- c(.25, .23, .88, NA, .88, -.02, .21, -.29)
annual_earnings_1972 <- c(.22, .25, .83, .88, NA, .03, .06, .21)
change_eff_1971_1972 <- c(-.47, .47, -.02, -0.02, 0.03, NA, 0.0, .1)
change_ann_earn_1970_1971 <- c(-.01, -.01, -.28, .21, .06, 0.0, NA, -.29)
change_ann_earn_1971_1972 <- c(-.06, .03, -.14, -.29, .21, .10, -.29, NA)
df <- data.frame(eff_1971,
eff_1972,
annual_earnings_1970,
annual_earnings_1971,
annual_earnings_1972,
change_eff_1971_1972,
change_ann_earn_1970_1971,
change_ann_earn_1971_1972)
rownames(df) <- c("eff_1971","eff_1972","annual_earnings_1970",
"annual_earnings_1971", "annual_earnings_1972", "change_eff_1971_1972",
"change_ann_ear_1970_1971", "change_ann_earn_1971_1972")
How can I convert this to a cor.mat
data type? I want to convert this correlation matrix into a covariance matrix using cor2cov
.
Thanks so much!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论