R:复制样本向量而不仅仅是样本 [英] R: Replicate Vector of Sample Instead of Just a Sample
本文介绍了R:复制样本向量而不仅仅是样本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想用 R
做我对 10
的样本大小做的事情,对样本集做同样的事情
I want to use R
to do what I do to sample size of 10
to do the same to set of samples
我有什么我得到了以下 R
代码,用于复制 Shapiro 测试的正态性 这里
What I have
I got the below R
code of replicating a Shapiro test for normality here
sim = replicate(1000,shapiro.test(rnorm(10)))
## rejections go like, assuming an alpha of 0.05 :
table(sim["p.value",] < 0.05)
拒绝的结果是这样的,假设 alpha 为 0.05:
Result of rejections go like, assuming an alpha of 0.05 :
假 | 真的 |
---|---|
948 | 52 |
我想要的
而不是仅对 10
的样本大小进行计数测试,我希望它在样本向量上进行,例如 (10, 20,50, 100),结果是这样的:
Instead of carrying the count test on just a sample size of 10
I want it carried out on a vector of samples say (10, 20,50, 100) with a result with something like this:
. | 假 | 真的 |
---|---|---|
10 | 948 | 52 |
20 | 970 | 30 |
50 | 956 | 44 |
100 | 944 | 36 |
推荐答案
使用循环 - sapply
并在 rnorm
Use a loop - sapply
and pass those values in rnorm
out <- t(sapply(c(10, 20, 50, 100), function(x)
table(replicate(1000, shapiro.test(rnorm(x)))["p.value",] < 0.05)))
row.names(out) <- c(10, 20, 50, 100)
-输出
out
FALSE TRUE
10 953 47
20 942 58
50 960 40
100 951 49
这篇关于R:复制样本向量而不仅仅是样本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文