Nordstokke and Zumbo (2007) simulation

Author

Phil Chalmers

Simulation from:

Simulation code

library(SimDesign)

Design <- createDesign(df = c(1000, 7.4, 2.2, .83), # skewness levels 0 to 3
                       sample_size = c(24,48,96),
                       sample_size_ratio = 1:3,
                       var_ratio = c(5:1, 1/2, 1/3, 1/4, 1/5))
Design

#-------------------------------------------------------------------

Generate <- function(condition, fixed_objects = NULL) {
    Attach(condition)
    N1 <- sample_size * sample_size_ratio / (sample_size_ratio + 1)
    N2 <- sample_size - N1
    DV <- c(rchisq(N1, df) * sqrt(var_ratio), rchisq(N2, df))
    dat <- data.frame(DV=DV, group=c(rep('G1', N1), rep('G2', N2)))
    dat
}

Analyse <- function(condition, dat, fixed_objects = NULL) {
    BF <- with(dat, levene.test(DV, group, location = 'median'))$p.value
    Levene <- with(dat, levene.test(DV, group, location = 'mean'))$p.value
    F <- var.test(DV ~ group, dat)$p.value
    ret <- c(BF=BF, Levene=Levene, F=F)
    ret
}

Summarise <- function(condition, results, fixed_objects = NULL) {
    ret <- EDR(results, alpha = .05)
    ret
}

#-------------------------------------------------------------------

# save results to the drive
res <- runSimulation(design=Design, replications=5000, generate=Generate,
                     analyse=Analyse, summarise=Summarise, parallel=TRUE,
                     packages='lawstat', filename='Nordstokke_Zumbo2007')
res
# A tibble: 324 × 11
        df sample_size sample_size_ratio var_ratio     BF Levene      F
     <dbl>       <dbl>             <int>     <dbl>  <dbl>  <dbl>  <dbl>
 1 1000             24                 1         5 0.4988 0.6046 0.7074
 2    7.4           24                 1         5 0.4262 0.5818 0.6778
 3    2.2           24                 1         5 0.295  0.5196 0.6498
 4    0.83          24                 1         5 0.156  0.4636 0.634 
 5 1000             48                 1         5 0.9    0.9202 0.9618
 6    7.4           48                 1         5 0.8224 0.8766 0.9218
 7    2.2           48                 1         5 0.63   0.7848 0.8518
 8    0.83          48                 1         5 0.327  0.6422 0.7866
 9 1000             96                 1         5 0.9992 0.9996 0.9998
10    7.4           96                 1         5 0.9888 0.992  0.9952
# ℹ 314 more rows
# ℹ 4 more variables: REPLICATIONS <int>, SIM_TIME <chr>, COMPLETED <chr>,
#   SEED <int>

Extras

# Type I errors
TypeI <- subset(res, var_ratio == 1)
Table1 <- TypeI[order(TypeI$df, TypeI$sample_size), ]
Table1
# A tibble: 36 × 11
      df sample_size sample_size_ratio var_ratio     BF Levene      F
   <dbl>       <dbl>             <int>     <dbl>  <dbl>  <dbl>  <dbl>
 1  0.83          24                 1         1 0.0486 0.2276 0.4062
 2  0.83          24                 2         1 0.0522 0.2302 0.4026
 3  0.83          24                 3         1 0.045  0.201  0.378 
 4  0.83          48                 1         1 0.0462 0.2094 0.4316
 5  0.83          48                 2         1 0.0492 0.2126 0.4148
 6  0.83          48                 3         1 0.0432 0.2004 0.4248
 7  0.83          96                 1         1 0.0478 0.2018 0.4544
 8  0.83          96                 2         1 0.045  0.197  0.4504
 9  0.83          96                 3         1 0.043  0.1892 0.4332
10  2.2           24                 1         1 0.044  0.1408 0.2254
# ℹ 26 more rows
# ℹ 4 more variables: REPLICATIONS <int>, SIM_TIME <chr>, COMPLETED <chr>,
#   SEED <int>
# Power
Power <- subset(res, var_ratio != 1)
Power
# A tibble: 288 × 11
        df sample_size sample_size_ratio var_ratio     BF Levene      F
     <dbl>       <dbl>             <int>     <dbl>  <dbl>  <dbl>  <dbl>
 1 1000             24                 1         5 0.4988 0.6046 0.7074
 2    7.4           24                 1         5 0.4262 0.5818 0.6778
 3    2.2           24                 1         5 0.295  0.5196 0.6498
 4    0.83          24                 1         5 0.156  0.4636 0.634 
 5 1000             48                 1         5 0.9    0.9202 0.9618
 6    7.4           48                 1         5 0.8224 0.8766 0.9218
 7    2.2           48                 1         5 0.63   0.7848 0.8518
 8    0.83          48                 1         5 0.327  0.6422 0.7866
 9 1000             96                 1         5 0.9992 0.9996 0.9998
10    7.4           96                 1         5 0.9888 0.992  0.9952
# ℹ 278 more rows
# ℹ 4 more variables: REPLICATIONS <int>, SIM_TIME <chr>, COMPLETED <chr>,
#   SEED <int>