【问题标题】:R: How to create result table of the results of multiple statistics tests?R:如何创建多个统计测试结果的结果表?
【发布时间】:2020-02-25 18:55:04
【问题描述】:

我是 R 语言的初学者。

我使用以下代码对 R 中的一列数据进行了多次卡方检验:

apply(mydata, 2, chisq.test, p=expected.probability)

得到了多个这样的结果:

$Primary Tumor

给定概率的卡方检验

数据:newX[, i] X-squared = 515108, df = 6, p-value

$Primary Tumor_1

给定概率的卡方检验

数据:newX[, i] X-squared = 583205, df = 6, p-value

$Primary Tumor_2

给定概率的卡方检验

数据:newX[, i] X-squared = 58089, df = 6, p-value

可以提取我测试的 50 个样本的肿瘤数、x 平方结果、df 和 p 值的结果表吗?

我可以在 Excel 中复制和粘贴,但我想学习更大样本的代码。

谢谢:)

【问题讨论】:

    标签: r statistics bioinformatics chi-squared


    【解决方案1】:

    您可以看到 chisq 测试的名称:

    names(chisq.test(matrix(1:4,ncol=2)))
    [1] "statistic" "parameter" "p.value"   "method"    "data.name" "observed" 
    [7] "expected"  "residuals" "stdres" 
    

    您需要的值是统计量(chisq)、参数(df)、p.value。

    所以我们模拟数据:

    mydata = matrix(rpois(100,50),ncol=10)
    colnames(mydata) = paste0("tumor",1:10)
    

    并写一个更精细的函数在测试后取出这些参数

    res = apply(mydata,2,function(x){
    chisq.test(x,p=rep(0.1,10))[c("statistic","parameter","p.value")]
    })
    

    我们将其设为 data.frame:

    df = data.frame(id=names(res),do.call(rbind,res))
    df
    
                 id statistic parameter   p.value
    tumor1   tumor1  4.322896         9 0.8889048
    tumor2   tumor2  5.285714         9 0.8087245
    tumor3   tumor3  2.803063         9 0.9715936
    tumor4   tumor4   8.62578         9 0.4725097
    tumor5   tumor5  13.22846         9 0.1525381
    tumor6   tumor6  8.653768         9 0.4698283
    tumor7   tumor7  7.666667         9 0.5680554
    tumor8   tumor8  5.919132         9 0.7479838
    tumor9   tumor9  8.051335         9 0.5289813
    tumor10 tumor10  13.46875         9 0.1425173
    

    【讨论】:

    • 感谢您的回复!它真的很有帮助:)
    • 我可以问更多问题吗?我对 50 个样本进行了卡方检验,这是否意味着我必须使用调整后的 p 值(例如 FDR)而不是 p 值来校正多个测试?
    • 没问题 :) 理论上是的。使用我上面的示例,您可以执行 p.adjust(df$p.value,"BH")。 BH 表示 benjamini hochberg 校正。如果您有类似的问题,请告诉我
    • 我应该把 p.adjust(df$p.value,"BH") 放在哪里?而不是正常的p值?我试过 'test
    • 嗨@KimSoYon,使用上面的例子,结果应该在df中;所以你做 df$padj = p.adjust(df$p.value,"BH") ;调整后的p值在表中
    【解决方案2】:

    试试这个

    df <- apply(mydata, 2, chisq.test, p=expected.probability)
    

    只需将其分配给可以从您的环境访问的变量...检查这个问题也可以帮助您。 chi square test for each row in data frame

    【讨论】:

    • 感谢您的帮助!我现在明白了:)
    • 接受正确的答案,以便其他人也能看到 :)
    猜你喜欢
    • 2019-01-04
    • 2021-12-17
    • 2015-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-21
    • 2020-07-09
    相关资源
    最近更新 更多