繁体   English   中英

R中的图相关矩阵

[英]Plot correlation matrix in R

我有一个包含矩阵的csv文件:

version getSize() length() ... power
0         23000    23421        0.8
0           ..      ..           ..
1           ..      ..           ..
1           ..      ..           ..

我想通过将均值函数应用于列的类似版本进行汇总。 这些列太多,无法编写它们。 我还想计算相关矩阵,并将功率列绑定到图的侧面。 我的代码是这样的:

matrix <- read.csv("/home/francesco/University/UoA/matrix.csv", header=TRUE, sep=",", fileEncoding="windows-1252")
power <- matrix[,"power"]
binded <- cbind(matrix,power)
aggregated <- aggregate(. ~ version, data = binded, mean)
corMatrix <- cor(aggregated, method="spearman")
library(lattice)
levelplot(corMatrix)

剧情很混乱,我得到这个警告:

Warning message:
In cor(aggregated, method = "spearman") : standard deviation is zero

以下是matrix.csv的简短摘录:

version,native_drawBitmap,nPrepareDirty,nDrawDisplayList,startGC,power
00083,8,88,308,12,0.8967960131052847
00083,0,176,404,1,0.867644513259528
00084,8,88,307,10,0.8980234065469381
00084,0,181,408,1,0.871799879659241

有人知道我在做什么错吗?

提前致谢

好吧,有了您的示例数据, native_drawBitmap列变为全4。 由于这没有方差,因此您无法与任何其他变量计算成对相关,并且会得到错误。 如果您忽略此列,它将起作用。 这是一个例子。

#sample data in friendly copy/paste-able format
mm<-data.frame(
    version = c(83, 83, 84, 84), 
    native_drawBitmap = c(8, 0, 8, 0),
    nPrepareDirty = c(88, 176, 88, 181), 
    nDrawDisplayList = c(308, 404, 307, 408), 
    startGC = c(12, 1, 10, 1), 
    power = c(0.896796013105285, 0.867644513259528, 
        0.898023406546938, 0.871799879659241)
)

# these are not needed and don't make sence. Why are you
#trying to re-add the column from mm back onto mm?
# power <- mm[,"power"]
# binded <- cbind(mm,power)
aggregated <- aggregate(. ~ version, data = mm, mean)

#error
corMatrix <- cor(aggregated, method="spearman")
#no error
corMatrix <- cor(aggregated[,-2], method="spearman")

汇总后,数据中的其他列可能没有变化。 确保找到并删除它们。

暂无
暂无

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

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