# Desgagne, A. and Lafaye de Micheaux, P.  (2017), A Powerful and
# Interpretable Alternative to the Jarque-Bera Test of Normality Based on
# 2nd-Power Skewness and Kurtosis, using the Rao's score test on the APD
# family, \emph{Journal of Applied Statistics}, .

# Regenerate results of Appendix~C from desgagne2017 (page ??)
nbcores <- 1 # Could increase this value if multiple cores were available
law.index <- 2 # H_0 is the Normal distribution
Mpow <- 10 ^ 5
Mlevel <- 10 ^ 6
vectn <- c(10, 20, 50, 100, 200)
levels <- 0.05
stat.indices <- c(26, 36, 21, 29, 3, 4, 6, 8, 2, 37, 7, 30, 17)
# 26 CS Chen-Shapiro
# 36 XAPD
# 21 W Shapiro-Wilk
# 29 BCMR
# 3 Z_C Zhang
# 4 Z_A Zhang
# 6 K^2 D Agostino-Pearson
# 8 DH Doornik-Hansen
# 2 AD^* Anderson-Darling
# 37 ZEPD
# 7 Jarque-Bera
# 30 \beta_3^2 Coin
# 17 T_w Bonett-Seier
alter <- list(stat26 = 3, stat36 = 3, stat21 = 4, stat29 = 3, stat3 = 3,
              stat4 = 3, stat6 = 3, stat8 = 3, stat2 = 3, stat37 = 0,
              stat7 = 3, stat30 = 3, stat17 = 0)

# Table C.1
set.seed(1)
law.indices <- c(rep(39, 19), rep(8, 14))
parlaws <- list(law39 = c(0.0, 1.0, 0.5, 0.1), law39 = c(0.0, 1.0, 0.5, 0.2),
                law39 = c(0.0, 1.0, 0.5, 0.3), law39 = c(0.0, 1.0, 0.5, 0.4),
                law39 = c(0.0, 1.0, 0.5, 0.5), law39 = c(0.0, 1.0, 0.5, 0.6),
                law39 = c(0.0, 1.0, 0.5, 0.7), law39 = c(0.0, 1.0, 0.5, 0.8),
                law39 = c(0.0, 1.0, 0.5, 0.9), law39 = c(0.0, 1.0, 0.5, 1.0), 
                law39 = c(0.0, 1.0, 0.5, 1.1), law39 = c(0.0, 1.0, 0.5, 1.2),
                law39 = c(0.0, 1.0, 0.5, 1.3), law39 = c(0.0, 1.0, 0.5, 1.4),
                law39 = c(0.0, 1.0, 0.5, 1.5), law39 = c(0.0, 1.0, 0.5, 1.6),
                law39 = c(0.0, 1.0, 0.5, 1.7), law39 = c(0.0, 1.0, 0.5, 1.8),
                law39 = c(0.0, 1.0, 0.5, 1.9), # modAPD
                law8 = 1.0, law8 = 2.0, law8 = 3.0, law8 = 4.0, law8 = 5.0,
                law8 = 6.0, law8 = 7.0, law8 = 8.0, law8 = 9.0, law8 = 10.0,
                law8 = 12.0, law8 = 15.0, law8 = 20.0, law8 = 30.0) # Student-t
critval.C1 <- many.crit(law.index, stat.indices, M = Mlevel, vectn,
                        levels, alter, law.pars = NULL, parstats = NULL)
res.power.C1 <- powcomp.fast(law.indices, stat.indices, vectn, Mpow, levels,
                             critval = critval.C1, alter, parlaws = parlaws,
                             parstats = NULL, nbclus = nbcores)
options(width = 200)
print(res.power.C1)

# Table C.2
set.seed(1)
law.indices <- c(rep(39, 18), 4, rep(6, 7))
parlaws <- list(law39 = c(0.0, 1.0, 0.5, 2.6), law39 = c(0.0, 1.0, 0.5, 2.8),
                law39 = c(0.0, 1.0, 0.5, 3.0), law39 = c(0.0, 1.0, 0.5, 3.2),
                law39 = c(0.0, 1.0, 0.5, 3.5), law39 = c(0.0, 1.0, 0.5, 3.8),
                law39 = c(0.0, 1.0, 0.5, 4.1), law39 = c(0.0, 1.0, 0.5, 4.4),
                law39 = c(0.0, 1.0, 0.5, 4.7), law39 = c(0.0, 1.0, 0.5, 5.0),
                law39 = c(0.0, 1.0, 0.5, 5.5), law39 = c(0.0, 1.0, 0.5, 6.0),
                law39 = c(0.0, 1.0, 0.5, 7.0), law39 = c(0.0, 1.0, 0.5, 8.0),
                law39 = c(0.0, 1.0, 0.5, 9.0), law39 = c(0.0, 1.0, 0.5, 10.0),
                law39 = c(0.0, 1.0, 0.5, 15.0), law39 = c(0.0, 1.0, 0.5, 20.0), # modAPD
                law4 = c(0.0, 1.0), # Logistic
                law6 = c(0.6, 0.6), law6 = c(0.8, 0.8), law6 = c(1.0, 1.0),
                law6 = c(1.5, 1.5), law6 = c(2.0, 2.0), law6 = c(2.5, 2.5),
                law6 = c(3.0, 3.0)) # Beta
critval.C2 <- many.crit(law.index, stat.indices, M = Mlevel, vectn, levels,
                        alter, law.pars = NULL, parstats = NULL)
res.power.C2 <- powcomp.fast(law.indices, stat.indices, vectn, Mpow, levels,
                             critval = critval.C2, alter, parlaws = parlaws,
                             parstats = NULL, nbclus = nbcores)
options(width = 200)
print(res.power.C2)

# Table C.3
set.seed(1)
law.indices <- c(rep(39, 6), rep(6, 4), rep(9, 4), rep(5, 6), 26, 10, rep(11, 4))
parlaws <- list(law39 = c(0.0, 1.0, 0.1, 2.0), law39 = c(0.0, 1.0, 0.2, 2.0),
                law39 = c(0.0, 1.0, 0.3, 2.0), law39 = c(0.0, 1.0, 0.35, 2.0),
                law39 = c(0.0, 1.0, 0.4, 2.0), law39 = c(0.0, 1.0, 0.45, 2.0), # modAPD 
                law6 = c(2.0, 1.0), law6 = c(2.0, 5.0), law6 = c(4.0, 0.5),
                law6 = c(5.0, 1.0), # Beta 
                law9 = 1.0, law9 = 2.0, law9 = 4.0, law9 = 10.0, # Chi-squared
                law5 = c(2.0, 1.0), law5 = c(3.0, 1.0), law5 = c(5.0, 1.0),
                law5 = c(9.0, 1.0), law5 = c(15.0, 1.0), law5 = c(100.0, 1.0), # Gamma
                law26 = c(1.0, 1.0), # Gumbel
                law10 = c(0.0, 1.0), # Lognormal
                law11 = c(0.5, 1.0), law11 = c(1.0, 1.0), law11 = c(2.0, 1.0),
                law11 = c(3.0, 1.0)) # Weibull
critval.C3 <- many.crit(law.index, stat.indices, M = Mlevel, vectn, levels,
                        alter, law.pars = NULL, parstats = NULL)
res.power.C3 <- powcomp.fast(law.indices, stat.indices, vectn, Mpow, levels,
                             critval = critval.C3, alter, parlaws = parlaws,
                             parstats = NULL, nbclus = nbcores)
options(width = 200)
print(res.power.C3)


# LaTex output : latex.output=TRUE 


