sample_sizes <- c(10, 20)
standard_deviations <- 1
Design <- createDesign(N1=sample_sizes,
N2=sample_sizes,
SD=standard_deviations)
Design
Generate <- function(condition, fixed_objects){
Attach(condition)
group1 <- rnorm(N1)
group2 <- rnorm(N2, sd=SD)
dat <- data.frame(group = c(rep('g1', N1), rep('g2', N2)),
DV = c(group1, group2))
dat
}
# functions to throw warnings
fn1 <- function(){
if(sample(c(TRUE, FALSE), 1, prob = c(.1, .9))) warning('Show this warning')
1
}
fn2 <- function(){
if(sample(c(TRUE, FALSE), 1, prob = c(.1, .9))) warning('Show a different warning')
1
}
Analyse <- function(condition, dat, fixed_objects){
if(with(condition, N1 != N2)){
out1 <- fn1()
out2 <- fn2()
}
c(ret = 1)
}
Summarise <- function(condition, results, fixed_objects) {
ret <- colMeans(results)
ret
}
# print warning messages and their frequency
res <- runSimulation(design=Design, replications=10, generate=Generate,
analyse=Analyse, summarise=Summarise)
res |> select(N1, N2, SD, WARNINGS)
SimWarnings(res)
SimWarnings(res, subset=FALSE)
Run the code above in your browser using DataLab