- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
之前的一篇文章解释了如何在 R 中对所有数据对执行卡方循环:Chi Square Analysis using for loop in R .我想使用此代码对 Spearman 相关性执行相同的操作。
我已经尝试更改一些变量,并且能够使用以下代码计算 pearson 相关变量:
library(plyr)
combos <- combn(ncol(fullngodata),2)
adply(combos, 2, function(x) {
test <- cor.test(fullngodata[, x[1]], fullngodata[, x[2]])
out <- data.frame("Row" = colnames(fullngodata)[x[1]]
, "Column" = colnames(fullngodata[x[2]])
, "cor" = round(test$statistic,3)
, "df"= test$parameter
, "p.value" = round(test$p.value, 3)
)
return(out)
})
但由于我处理的是有序尺度的数据,因此我需要使用 Spearman 相关性。
我以为我可以通过添加 method="spearman"命令来获取这些数据,但这似乎不起作用。如果我使用代码:
library(plyr)
combos <- combn(ncol(fullngodata),2)
adply(combos, 2, function(x) {
test <- cor.test(fullngodata[, x[1]], fullngodata[, x[2]], method="spearman")
out <- data.frame("Row" = colnames(fullngodata)[x[1]]
, "Column" = colnames(fullngodata[x[2]])
, "Chi.Square" = round(test$statistic,3)
, "df"= test$parameter
, "p.value" = round(test$p.value, 3)
)
return(out)
})
我收到回复:
Error in data.frame(Row = colnames(fullngodata)[x[1]], Column =
colnames(fullngodata[x[2]]), :
arguments imply differing number of rows: 1, 0
In addition: Warning message:
In cor.test.default(fullngodata[, x[1]], fullngodata[, x[2]], method = "spearman") :
Cannot compute exact p-values with ties
我做错了什么?
最佳答案
试试 ltm
包中的 rcor.test
函数。
mat <- matrix(rnorm(1000), 100, 10, dimnames = list(NULL, LETTERS[1:10]))
rcor.test(mat, method = "spearman")
A B C D E F G H I J
A ***** -0.035 0.072 0.238 -0.097 0.007 -0.010 -0.031 0.039 -0.090
B 0.726 ***** -0.042 -0.166 0.005 0.025 0.007 -0.231 0.005 0.006
C 0.473 0.679 ***** 0.046 0.074 -0.020 0.091 -0.183 -0.040 -0.084
D 0.017 0.098 0.647 ***** -0.060 -0.151 -0.175 -0.068 0.039 0.181
E 0.338 0.960 0.466 0.553 ***** 0.254 0.055 -0.031 0.072 -0.059
F 0.948 0.805 0.843 0.133 0.011 ***** -0.014 -0.121 0.153 0.048
G 0.923 0.941 0.370 0.081 0.588 0.892 ***** -0.060 -0.050 0.011
H 0.759 0.021 0.069 0.501 0.756 0.230 0.555 ***** -0.053 -0.193
I 0.700 0.963 0.690 0.701 0.476 0.130 0.621 0.597 ***** -0.034
J 0.373 0.955 0.406 0.072 0.561 0.633 0.910 0.055 0.736 *****
upper diagonal part contains correlation coefficient estimates
lower diagonal part contains corresponding p-values
关于r - R 中的 Spearman 相关环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7767184/
我有一个如下所示的数据框: Samples GENE GEN1 GEN2 GEN3 GEN4 GEN5 Sample1 21.0 160 110 3.90 2.62 16.5 Sa
我有两个维度相等的矩阵(p 和 e),我想在同名的列之间建立斯 PIL 曼相关。我想在矩阵 (M) 中输出对相关性 我使用了 Psych 库中的 corr.test() 函数,这是我所做的: libr
我有两个维度相等的矩阵(p 和 e),我想在同名的列之间建立斯 PIL 曼相关。我想在矩阵 (M) 中输出对相关性 我使用了 Psych 库中的 corr.test() 函数,这是我所做的: libr
我正在尝试使用 estpost 和 community-contributed 命令将 Spearman 相关矩阵导出到 rtf 或 Excel 文件中 esttab。 但是,我收到以下错误: inv
我正在寻找一种方法来计算 Spearman 秩相关 $\rho$ 的多变量版本。有没有我可以使用的现成的 Python 实现? 最佳答案 scipy 中有一个. 关于python - 多变量 Spea
之前的一篇文章解释了如何在 R 中对所有数据对执行卡方循环:Chi Square Analysis using for loop in R .我想使用此代码对 Spearman 相关性执行相同的操作。
我想将方法2、3、4的排名结果与方法1进行比较。在这方面,我想使用Spearman Rho系数。我还想知道方法2、3、4的结果与方法1是否有显着关系。那么该怎么做呢? database datab
我想将方法2、3、4的排名结果与方法1进行比较。在这方面,我想使用Spearman Rho系数。我还想知道方法2、3、4的结果与方法1是否有显着关系。那么该怎么做呢? database datab
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于 Stack Overflow 来说是偏离主题的,因为
为了使我的问题可重现,我使用鸢尾花数据集(10 任意行,所有列标准标准化)和最小神经网络模型(预测花瓣宽度(使用萼片长度、萼片宽度和花瓣长度)通过修改我在互联网上找到的 MNIST 示例来实现。向下滚
我正在为面试官计算 Spearman 相关系数。它适用于 Interviewer_1...我不明白 Scipy 如何打断 interviewer_2 没有相关性/0/nan。 import panda
我想使用滚动窗口计算 DataFrame 两列之间的 Spearman 和/或 Pearson 相关性。 我试过df['corr'] = df['col1'].rolling(P).corr(df['
我想计算 spearman rank correlation使用 Python 和最有可能的 scipy 实现 (scipy.stats.spearmanr)。 手头的数据看起来像下面的方式(字典):
corrgram 库提供了绘制优雅相关图的机会。但是,文档中没有简单的方法可以在同一张图上同时获得 Spearman 和 Pearson 相关性。 也许计算两个系数的相关矩阵并将它们粘贴是一种选择,但
问题 我需要计算 Pearson 和 Spearman 相关性,并将其用作 tensorflow 中的指标。 对于 Pearson,这是微不足道的: tf.contrib.metrics.stream
我需要为具有不同长度的向量对(例如 5 元素向量到 20 元素向量)计算斯 PIL 曼等级相关性(使用 corr 函数)。每个长度的对数通常在 300 对以上。我使用 waitbar 跟踪进度。我注意
我正在使用下面的代码关联两个数据框。基本上,从一个数据框 (a) 中选择一组列,从另一个数据框 (b) 中选择一列。它工作得很好,除了我需要用长矛手的选项来做。我将不胜感激任何意见或想法。谢谢...
使用以下代码在 R 中构建 ggpairs 图。 df 是一个包含 6 个连续变量和一个 的数据框群 多变的 ggpairs(df[,-1],columns = 1:ncol(df[,-1]), ma
我想知道 R 中用于计算 Spearman rho 的 cor.test 函数是否tie-corrected。我在 official R documentation 中找不到直接的答案. 领带校正的
我有一个包含三个箱线图的图,我需要使用 ggplot2 或 ggpubr 显示箱线图对之间的 Spearman 相关性。 很容易绘制类似的图,但具有成对的 p 值。例如, library(ggpubr
我是一名优秀的程序员,十分优秀!