我想在R
中使用Chi-Square Goodness of Fit Test
来测试一组数据的正态性,就像我测试Shapiro-wilk测试一样。我的样本量是10, 20,50 and 100
,而我的replicate is 1000
## Shapiro- wilk test [sw]
x <- rnorm(x, 0, 1)
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 947 53
# 20 945 55
# 50 943 57
# 100 943 57
您需要确保chi测试得到非负值。尝试用以下代码替换表格计算:
table(replicate(1000,chisq.test(x=abs(rnorm(x)),p=c(rep(1/x,x))))["p.value",] < 0.05)