'Chi-square Goodness of Fit for a Test of Normality in r
I want to test for normality of a set of data using Chi-Square Goodness of Fit Test in R just the way I tested for Shapiro- wilk test. I have my sample sizes to be 10, 20,50 and 100 while my 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
Solution 1:[1]
You need to make sure the chi test get non negative values. Try replacing the table calculation with this code:
table(replicate(1000,chisq.test(x=abs(rnorm(x)),p=c(rep(1/x,x))))["p.value",] < 0.05)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | AugtPelle |
