1

这是我第三次尝试解释我的问题。希望这次我能做对,这是一个很难解释的问题。

我有90x19 矩阵,其中 90 行中的每一行都是在某个波长上​​进行的一系列 19 次测量。90 个波长从 400 到 700。然后我有一个长度为19x1 的向量

我想创建一个矩阵,其中每个单元格显示每个波长组合的总和(对于矩阵的所有 19 个值)和 19x1 向量之间的 Pearson 相关系数。

绘制这个表面看起来就像这样

在此处输入图像描述

如果您需要更多信息或更好的解释,请告诉我。这里真的需要一些帮助!:)

最好的

向量如下:

v<-c(116, 100, 148, 132, 81, 136, 145, 116, 87, 126, 62, 124, 129, 
108, 127, 134, 142, 99, 132)

数据帧头如下:

data<-structure(list(`1` = c(2, 2, 2, 2), `2` = c(1, 1, 1, 1), `3` = c(2, 
2, 2, 2), `4` = c(2, 2, 2, 3), `5` = c(13, 14, 14, 15), `6` = c(2, 
2, 2, 2), `7` = c(2, 2, 2, 2), `8` = c(0, 0, 0, 0), `9` = c(5, 
5, 5, 5), `10` = c(0, 0, 0, 0), `11` = c(114, 119, 122, 125), 
    `12` = c(8, 8, 8, 8), `13` = c(7, 7, 7, 8), `14` = c(10, 
    10, 10, 10), `15` = c(12, 12, 12, 12), `16` = c(6, 6, 6, 
    6), `17` = c(4, 4, 4, 4), `18` = c(17, 18, 18, 19), `19` = c(13, 
    14, 14, 14)), .Names = c("1", "2", "3", "4", "5", "6", "7", 
"8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", 
"19"), row.names = c("402.37700182806", "405.70862540288", "409.04076825642", 
"412.37342090064"), class = "data.frame")
4

1 回答 1

1

我模拟了数据(没有相关性),但看看这是否是你想要的:

nr=90
data<-data.frame(matrix(runif(nr*19,2,15),nrow=nr,ncol=19))
row.names(data)<-round(seq(400,700, length.out = nrow(data)),4)

cm=matrix(NA,nrow(data),nrow(data))
for (i in 1:nrow(data))
  for(j in i:nrow(data))cm[j,i]<- cor(apply(data[c(j,i),],2,sum),v)

colnames(cm)<-row.names(cm)<-round(as.numeric(row.names(data)),0)

#Build the plot    
library(lattice)
library(reshape)

cmd<-cbind(var=as.numeric(row.names(data)),data.frame(cm))
cmd<-cbind(melt(cmd, id=c("var")),var2=rep(as.numeric(row.names(data)),each=nrow(data)))

levelplot(value~var*var2,data=cmd,  
          col.regions=colorRampPalette(c("blue","green", "red")),
          at=seq(-1,1,0.1),
          xlab="x", ylab="x", main="")

在此处输入图像描述

于 2016-05-31T01:58:54.970 回答