方差系数的密度图

时间:2013-09-17 10:56:47

标签: r covariance

我有两个RMA标准化为

的数据帧
  set.seed(1) 
  X <- data.frame(matrix(rnorm(20), nrow=10))
  Y <- data.frame(matrix(rnorm(20), nrow=10))

列是基因表达水平,行是基因。如何在单个图中绘制X的基因表达水平的协方差的密度分布和基因表达水平Y的协方差的分布。它是这样的,但我想研究整个数据框的分布而不是列。enter link description here

我尝试使用

       plot (density(X), col="red",ylim=c(0,3.5),xlim=c(-1,2)) 
       lines (density(Y), col="green") 

但是我收到了错误

       Error in density.default() : argument 'x' must be numeric

1 个答案:

答案 0 :(得分:0)

我仍然不确定,我理解正确。

set.seed(1) 
X <- data.frame(matrix(rnorm(20), nrow=10))
Y <- data.frame(matrix(rnorm(20), nrow=10))

#CV
d1 <- density(sapply(X, function(x) sd(x)/mean(x)))
d2 <- density(sapply(Y, function(x) sd(x)/mean(x)))

plot(d1, ylim=c(0,max(d1$y,d2$y)), xlim=range(d1$x,d2$x), col="green", xlab="", main="")
par(new=TRUE)
plot(d2, ylim=c(0,max(d1$y,d2$y)), xlim=range(d1$x,d2$x), col="red", xlab="", main="")
par(new=FALSE)

#covariance
d3 <- density(cov(X))
d4 <- density(cov(Y))

plot(d3, ylim=c(0,max(d3$y,d4$y)), xlim=range(d3$x,d4$x), col="green", xlab="", main="")
par(new=TRUE)
plot(d4, ylim=c(0,max(d3$y,d4$y)), xlim=range(d3$x,d4$x), col="red", xlab="", main="")
par(new=FALSE)