简体   繁体   English

尝试计算相关矩阵时如何解释此错误的含义?

[英]How can I interpret the meaning of this error when trying to compute a correlation matrix?

I have been trying to make what I thought should be a simple correlation matrix.我一直在尝试制作我认为应该是一个简单的相关矩阵。 I have the following data:我有以下数据:

cormetric2 <- structure(list(rich = c(24.03017241, 22.3), spatial = c(20.16163793,  18.71), abund = c(13.69612069, 12.71),
               rare = c(12.14439655,  11.27), div = c(8.265086207, 7.67), nature = c(8.006465517, 7.43 ),
               other = c(7.747844828, 7.19), endem = c(3.362068966, 3.12), agm = c(2.068965517, 1.92),
               umbsp = c(0.517241379, 0.48)), class = "data.frame", row.names = c("GlobalOld",  "GlobalNew"))

I have used the following code:我使用了以下代码:

corrplot(cormetric2, type = "upper", order = "hclust", 
         tl.col = "black", tl.srt = 45)

corrplot(cormetric2, type="upper")

Both returned the following error message:两者都返回以下错误消息:

Error in if (any(corr < cl.lim[1]) || any(corr > cl.lim[2])) {: missing value where TRUE/FALSE needed if (any(corr < cl.lim[1]) || any(corr > cl.lim[2])) {: 需要 TRUE/FALSE 的缺失值

What is the meaning of this error message?这个错误信息是什么意思? I do not have any zeros in my dataset, which looks like this:我的数据集中没有任何零,如下所示:

head(cormetric2)
          rich  spatial    abund    rare      div   nature    other    endem      agm     umbsp
GlobalOld: 24.03017 20.16164 13.69612 12.1444 8.265086 8.006466 7.747845 3.362069 2.068966 0.5172414
GlobalNew: 22.30000 18.71000 12.71000 11.2700 7.670000 7.430000 7.190000 3.120000 1.920000 0.4800000

How can I create the correlation plot?如何创建关联 plot?

By default, the corrplot , checks the corr object as a correlation matrix.默认情况下, corrplot检查corr object 作为相关矩阵。 Based on the input, it is not a correlation matrix or even a matrix.根据输入,它不是相关矩阵,甚至不是矩阵。 It is a data.frame .它是一个data.frame We could convert to matrix with as.matrix and specify is.corr = FALSE based on the documentation of ?corrplot我们可以使用as.matrix转换为matrix ,并根据?corrplot的文档指定is.corr = FALSE

corr - The correlation matrix to visualize, must be square if order is not "original". corr - 要可视化的相关矩阵,如果 order 不是“原始”,则必须是正方形。 For general matrix, please using is.corr = FALSE to convert.对于一般矩阵,请使用 is.corr = FALSE 进行转换。

library(corrplot)
corrplot(as.matrix(cormetric2), is.corr = FALSE, type = "upper")

-output -输出

在此处输入图像描述

data数据

cormetric2 <- structure(list(rich = c(24.03017241, 22.3),
 spatial = c(20.16163793, 
18.71), abund = c(13.69612069, 12.71), rare = c(12.14439655, 
11.27), div = c(8.265086207, 7.67), nature = c(8.006465517, 7.43
), other = c(7.747844828, 7.19), endem = c(3.362068966, 3.12), 
    agm = c(2.068965517, 1.92), umbsp = c(0.517241379, 0.48)), 
    class = "data.frame", row.names = c("GlobalOld", 
"GlobalNew"))

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

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