pitakakariki / simr

Power Analysis of Generalised Linear Mixed Models by Simulation
68 stars 19 forks source link

`powerCurve` output does not indicate errors #222

Open mattansb opened 2 years ago

mattansb commented 2 years ago

powerCurve output does not indicate errors, which makes debugging scripts using simr difficult - 100% errors are displayed as 0.00 power.

library(simr)

(Make some missing data to recreate the same error in #204 )

mtcars[2:5, 2] <- NA

(m <- lm(mpg ~ cyl, data = mtcars))
#> 
#> Call:
#> lm(formula = mpg ~ cyl, data = mtcars)
#> 
#> Coefficients:
#> (Intercept)          cyl  
#>      38.829       -3.036

While powerSim’s printing indicates errors:

powerSim(m)
#> Power for predictor 'cyl', (95% confidence interval):
#>        0.00% ( 0.00,  0.37)
#> 
#> Test: t-test
#> 
#> Based on 1000 simulations, (0 warnings, 1000 errors)
#> alpha = 0.05, nrow = 28
#> 
#> Time elapsed: 0 h 0 m 1 s
#> 
#> nb: result might be an observed power calculation

powerCurve’s does not:

(pc <- powerCurve(m))
#> Power for predictor 'cyl', (95% confidence interval),
#> by largest value of cyl:
#>       8:  0.00% ( 0.00,  0.37) - 28 rows
#> 
#> Time elapsed: 0 h 0 m 1 s

# nor
summary(pc)
#>   nrow nlevels successes trials mean lower       upper
#> 1   28       3         0   1000    0     0 0.003682084