# NOT RUN {
set.seed(12)
mu <- c(0, 0, 1, 2)
n <- c(5, 4, 5, 5)
parms <- list(mean=0, sd=1)
powerOneWayTests(mu, n, parms, test = "cuzickTest",
alternative = "two.sided", replicates = 1E4)
## Compare power estimation for
## one-way ANOVA with balanced design
## as given by functions
## power.anova.test, pwr.anova.test
## and powerOneWayTest
groupmeans <- c(120, 130, 140, 150)
SEsq <- 500 # within-variance
n <- 10
k <- length(groupmeans)
df <- n * k - k
SSQ.E <- SEsq * df
SSQ.A <- n * var(groupmeans) * (k - 1)
sd.errfn <- sqrt(SSQ.E / (n * k - 1))
R2 <- c("R-squared" = SSQ.A / (SSQ.A + SSQ.E))
cohensf <- sqrt(R2 / (1 - R2))
names(cohensf) <- "Cohens f"
## R stats power function
power.anova.test(groups = k,
between.var = var(groupmeans),
within.var = SEsq,
n = n)
## pwr power function
pwr.anova.test(k = k, n = n, f = cohensf, sig.level=0.05)
## this Monte-Carlo based estimation
set.seed(200)
powerOneWayTests(mu = groupmeans,
n = n,
parms = list(mean=0, sd=sd.errfn),
test = "oneway.test",
var.equal = TRUE,
replicates = 5E3)
## Compare with effect sizes
R2
cohensf
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab