在 R 中将数据帧转换为 cor.mat 数据类型

发布于 2025-01-10 07:01:20 字数 1272 浏览 1 评论 0原文

我有一个属于数据帧数据类型的相关矩阵。

#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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文