r - R中的P值排列
问题描述
我在 r 中很新
我在 R 中执行置换测试以确定某些 SNP 的出现百分比是否是偶然的 我的数据集一个 52K 值的向量我通过 Loop 进行测试,如下所示:
R1_H <- R1[,12] #extract the vector from a dataframe
niter=100000 #set the number of iterations
out <- rep(0,length(R1_H))
for (i in 1:niter){
out = out + (R1_H <= sample(R1_H)) #compare my ocurrence against a
#sample of the entire population
}
pvalue=out/niter #determine the pvalue
R1$pvalueF = pvalue #print the pvalue
问题是这种方式极其缓慢且耗费资源。有人认为更有效的方法吗?非常感谢
解决方案
我不完全确定你在做什么。但有几点。R 具有replicate
专门为此类事物设计的内置功能。您可以使用的一种选择是:
my_vector <- replicate(niter,
expr = (R1_H <= sample(R1_H, replace = T)))
这将重复多次expr
。niter
在这种情况下,它将进行替换采样并返回一个矩阵,其中包含 R1_H 和 10k 列中的数据点数。然后你可以做类似的事情:
mean(colMeans(my_vector))
获取您尝试报告的“pvalue”。
推荐阅读
- json - Flutter JSON 从字符串转换或如何从对话流中获取 JSON 数据
- angular - Angular SSR 不断加载并因 ERR_EMPTY_RESPONSE 而失败,而命令行上没有任何控制台错误
- npm - 没有更多参数的“npm install -g”到底是做什么的?
- javascript - 如何使用 Transform 和 Transition 将 3 个小节 (⚊) 转换为“-X”
- linux - 如何在树莓派中重置环境变量?
- gitlab - 在 GitLab GUI 中启用预提交挂钩
- url - 如何使用 youtube api 从 bash 中的 ID 生成播放列表?
- node.js - Lambda INSERT INTO MySql 函数正在添加到数据库但仍然超时
- python - Python在可能不同的起始子字符串的子字符串之间拆分字符串
- flutter - 在颤动中处理后台消息时,Firebase Cloud Message 崩溃