0

我希望在 R 中计算一个运行窗口 Spearman 相关性。到目前为止,我一直在使用runningfrom gtoolspackage,但我只能从中得到 Pearson 相关性。我试图修改fun参数,但无法让它产生任何错误。

我的输入是一个data.frame:

row.names   Small   Large
1   1   97.80341    88.71192
2   2   97.46807    87.96206
3   3   97.18862    88.13904
4   4   97.76615    87.67329
5   5   97.09081    87.52425
6   6   97.16067    87.85493
7   7   97.73820    88.43712

等等,这是我试图操纵的基本运行命令:

corr_table <- running (mytable$Large, mytable$Small,fun=cor, width=20, by=10, allow.fewer=FALSE, pad=FALSE, align="left")

我的第二个问题是如何添加每个“窗口”的 pvalue ?

谢谢!

4

1 回答 1

0

OK 找到了解决这两个问题的方法:

corr_table <- running (mytable$Large, mytable$Small,fun=cor.test, method="spearman", width=60, by=30, allow.fewer=FALSE, pad=FALSE, align="left")
newlist <- t(corr_table)
newlist <- as.matrix (newlist)
y <- newlist[,4]
x <- seq(from=1, to=92) #change the "to" according to number of values in Y
pvalue <- newlist[,3]
plot(x,y, xlim=c(1,92),ylim=c(-1,1), col=ifelse(pvalue < 0.05, "red", "black")) #change the "xlim" according to number of values in Y 
于 2015-06-22T11:42:41.107 回答