如何获得数据的工作corrplot?

发布于 2025-01-29 07:42:11 字数 396 浏览 2 评论 0原文

我正在尝试获取数据变量的Corrplot,这些变量是二进制,连续和分类变量的组合。但是,当我运行此代码时,它会不断给我错误。当我加载数据框时,称为DF2的错误是:Corrplot中的错误(DF2):矩阵不在[-1,1]!中。我该如何解决?

当我计算相关性时,我也会得到某些变量,即使它们是数字和整数值 1

附加了我的数据变量的示例,其中hh_code是用于标识的列: 2

如何我在r中获得了我的数据变量之间的相关性?谢谢!

I am trying to get the corrplot for my data variables which are a combination of binary, continuous and categorical variables. However, when I run this code, it keeps giving me errors. The error when i load my data frame, called df2, is: Error in corrplot(df2) : The matrix is not in [-1, 1]!. How can I solve this?

When I compute the correlation I also get that for certain variables, I only receive NA's, even though they are numeric and integer values 1.

Attached an example of my data variables, where hh_code is the column used for identification: 2

How can I get the correlation between variables for my data in R? Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谁的新欢旧爱 2025-02-05 07:42:12

如果您有一个表格,而其他列则是数字的,则可以使用函数ggally :: ggpairs来获取有关这些变量之间关联的概述:

library(GGally)
#> Loading required package: ggplot2
#> Registered S3 method overwritten by 'GGally':
#>   method from   
#>   +.gg   ggplot2
data <- ggplot2::mpg[c(1,3,4,7,8)]
ggpairs(data)
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

“”

preprex软件包(v2.0.0)

如果您需要更严格一些,则可以使用统计测试来获得列/变量之间的显着关系(如果其假设成立):

协方差x曲目y测试r函数
数字人数相关性cor.test(x,y,method =“ pearson”)
二进制数字t测试t.t.t.t.t.t.t.t.t.t.t.t.t.t.t.t.t.t.t.t.t.t.t.t.t.t.t.t.t.t.t.t.t.t.t.t.t.t.t.test(x,y)
ordinal(有序因素)序列(有序因子)Spearman相关性cor.test(as.numeric(x),as.numeric(y),method =“ spearman”)
exporial(许多级别)数字ANOVAanova anova (lm(y〜x))

If you have a table in which some columns are numeric and others are categorical, you can use the function GGally::ggpairs to get an overview about the associations between these variables:

library(GGally)
#> Loading required package: ggplot2
#> Registered S3 method overwritten by 'GGally':
#>   method from   
#>   +.gg   ggplot2
data <- ggplot2::mpg[c(1,3,4,7,8)]
ggpairs(data)
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

Created on 2022-05-17 by the reprex package (v2.0.0)

If you need a little bit more rigour, you can use statistical tests to get significant relationships between columns / variables (if their assumptions hold):

covariate xoutcome ytestR function
numericnumericPerson correlationcor.test(x,y, method = "pearson")
binarynumerict testt.test(x, y)
ordinal (ordered factor)ordinal (ordered factor)Spearman correlationcor.test(as.numeric(x), as.numeric(y), method="spearman")
categorial (many levels)numericANOVAanova(lm(y ~ x))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文