gpt4 book ai didi

对 R 中数据框的每一行运行 Fisher 测试

转载 作者:行者123 更新时间:2023-12-04 05:10:11 25 4
gpt4 key购买 nike

我有一个由~3k 调查人员进行的~50k 测量的数据框。

INVESTIGATOR_ID \\\ SAMPLE_ID \\\ MEASUREMENT1000            \\\ 38942     \\\ 20.11000            \\\ 38942     \\\ 10.21001            \\\ 38432     \\\ 5.61002            \\\ 553       \\\ 10.6...

My goal is to compare sample measurements per investigator to measurements from the entire data set:

  1. For each investigator, count those measurements that are +/- one standard deviation from the measurement mean collected by that investigator.
  2. For the entire data frame, count those measurements that are +/- one standard deviation from the mean.
  3. For each investigator that has sample measurements +/- one standard deviation from the mean, run a Fisher's exact test to determine if the number of samples is significant (compared to the entire data frame).

I've used the Plyr library (ddply) to summarise the data by INVESTIGATOR_ID. Merging data together, the end result is a data frame, where each row consists of an investigator ID, the number of samples measured by that investigator, number of samples measured by that investigator +/- 1 SD, 15000, and 50000 (where 15000 and 50000 are the corresponding sample numbers +/- 1 SD and the total number of samples for the entire data frame).

INVESTIGATOR_ID \\\ NUMBER_OF_SAMPLES \\\ NUMBER_OF_SAMPLES_SD \\\ 15000 \\\ 50000

如何获取数据框的每一行,转换字段 c(2:5)到矩阵,运行 Fisher 检验,然后创建结果的新数据框?

感谢您的任何建议。

最佳答案

类似的东西(改编自我的脚本,可能需要更多修改以满足您的需要):

get_fisher <- function(df){
mat <- matrix(as.numeric(df[c(2:5)]), ncol=2)
f <- fisher.test(as.table(mat), alt="two.sided")
return(c(df[1], f$p.value))
}

fishers <- apply(df, 1, get_fisher)

关于对 R 中数据框的每一行运行 Fisher 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14983579/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com