【问题标题】:Calculating a statistic for multiple studies in R计算 R 中多项研究的统计量
【发布时间】:2018-07-04 13:52:31
【问题描述】:

我有一个数据集,我想在其中应用几个测试,例如 KS 两个样本。所以我试图找到一种算法,可以将 KS 两个样本测试应用于所有样本。基本思路是:

假设我有一个包含这些观察结果的数据集:

       1 2 3 4
Study1 9 1 2 6
Study2 5 6 7 8
Study3 4 3 2 1
Study4 8 7 6 5
Study5 1 3 5 7
Study6 2 4 6 8
Study7 1 3 6 9
Study8 2 4 7 1
Study9 2 5 8 4
Study10 3 6 8 5

我可以通过以下方式将 KS 测试应用于每项研究:

ks.test(as.numeric(as.vector(df[1,])),as.numeric(as.vector(df[1,])))
ks.test(as.numeric(as.vector(df[1,])),as.numeric(as.vector(df[2,])))
ks.test(as.numeric(as.vector(df[1,])),as.numeric(as.vector(df[3,])))
                                   ...
ks.test(as.numeric(as.vector(df[1,])),as.numeric(as.vector(df[10,])))
ks.test(as.numeric(as.vector(df[2,])),as.numeric(as.vector(df[1,])))
                                   ...
ks.test(as.numeric(as.vector(df[10,])),as.numeric(as.vector(df[10,])))

这将产生 10x10 的 p 值,我的目标是将其用作距离的度量。

所以我正在寻找一种算法,它可以对 n x n 样本运行 KS 测试,然后在 n x n 矩阵中输出 p 值。

【问题讨论】:

    标签: r p-value kolmogorov-smirnov


    【解决方案1】:

    您正在寻找outer:

    outer(1:10, 1:10, Vectorize(function(i,j) {ks.test(as.numeric(as.vector(df[i,])),as.numeric(as.vector(df[j,])))$p.value}))
    

    【讨论】:

    • 我收到此错误:Error in dim(robj) <- c(dX, dY) : dims [product 100] do not match the length of object [500] In addition: There were 50 or more warnings (use warnings() to see the first 50)
    • 警告是什么?
    • 所有 50 个都一样:Warning messages: 1: In ks.test(as.numeric(as.vector(df[i, ])), as.numeric(as.vector(df[j, ... : cannot compute exact p-value with ties
    • 啊。道歉 - 你应该选择 p 值。我修改了答案
    • 非常感谢!虽然错误仍然存​​在,但效果很好
    猜你喜欢
    • 1970-01-01
    • 2010-09-22
    • 2015-01-29
    • 1970-01-01
    • 2021-07-26
    • 1970-01-01
    • 2020-11-02
    • 2013-10-27
    • 2016-06-27
    相关资源
    最近更新 更多