简体   繁体   English

是否可以在 R 中过滤 corrplot/cormatrix?

[英]Is it possible to filter a corrplot/cormatrix in R?

I have a dataset that contains a number of different variables, each with it's own subset of groups.我有一个包含许多不同变量的数据集,每个变量都有自己的组子集。 I've also got a target variable.我也有一个目标变量。 I want to establish which groups are correlated with the response and have managed to create a series of correlation matrices for each variable and the response, and also, corresponding correlation plots using the cor function and corrplot function respsectively in R.我想确定哪些组与响应相关,并设法为每个变量和响应创建一系列相关矩阵,以及在 ZE1C425268E68385D1AB5074C17A94F14Z 和 corrplot function 中分别使用 function 和 corrplot function 分别创建一系列相关矩阵。

For the purpose of what I'm doing, I'm not interested in whether variables are correlated with each other, I'm just interested in whether they are correlated with the response variable.就我所做的而言,我对变量是否相互关联不感兴趣,我只对它们是否与响应变量相关感兴趣。 Is there a way of filtering the correlation matrix prior to plotting so as to only include the variables against the target variable有没有办法在绘图之前过滤相关矩阵,以便仅包含针对目标变量的变量

cor(x) function, when given one argument (matrix or a data.frame) computes correlations between all pairs of variables present in the columns. cor(x) function,当给定一个参数(矩阵或 data.frame)时,计算列中存在的所有变量对之间的相关性。 However the same function can accept two arguments: cor(x, y) , in which case it only computes correlations between pairs x and y.然而,同样的 function 可以接受两个 arguments: cor(x, y) ,在这种情况下,它只计算 x 和 y 对之间的相关性。

So in your case you can provide all your group variables as x, and the response variable as y, and then plot the result (assuming "response" is in the last column):因此,在您的情况下,您可以将所有组变量提供为 x,将响应变量提供为 y,然后提供 plot 结果(假设“响应”在最后一列中):

cors <- cor(dat[,-ncol(dat)], dat[,ncol(dat)])
corrplot::corrplot(cors)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM