Search code examples
rrandomnormal-distributionmontecarlo

Normality tests repeating 1000 times in R: Shapiro Wilk, Jarque Bera, Lilliefors


students and professionals,

I am currently trying to program normality tests for random sample sizes (T=10,30,50,100,500).

The functions I use for the normality tests are the following:

sim1 <- rnorm(10)

sw10 <- shapiro.test(sim1)

and this for every sample size

This results in a list with test information that has to be interpreted with confidence levels 90%, 95% and 99%.

The problem I am facing is that I need to repeat this process 1000 times.. But using the same sample sim1 does not help in this case while the same p-values are computed.

so do I use the following?

rsw10 <- replicate(shapiro.test(rnorm(10))

Plus I have to compute relative rejection frequencies, how do I extract that information?

Best regards


Solution

  • If I get you correct, it goes something like, you have the number of reps first, followed by the function:

    sim = replicate(1000,shapiro.test(rnorm(10)))
    

    rejections go like, assuming an alpha of 0.05 :

    table(sim["p.value",]<0.05)
    
    FALSE  TRUE 
      961    39