I wonder if there is a possibility of doing power analysis for post-hoc test for GAM? I am specifically interested in a sample size necessary to achieve a desired power.
My GAM looks like this:
library(mgcv)
set.seed(123)
n = 500
dat <- data.frame(
"y" = rnbinom( n, size = 2.594, mu = 144.629),
"fac" = as.factor(rep(c("x","y"), n)[1:n]),
"fac2" = as.factor(rep(c("a","b","c"), n)[1:n]),
"fac3" = as.factor(rep(c("p","q","r"), n)[1:n]),
"x1" = rnorm(n, mean = 0, sd=1.02),
"x2" = as.factor(rep(1:5, each = n/5)))
gam1 <- mgcv::gam(y ~ fac*fac2*fac3 +
s(x2, bs = "re") +
s(x1, bs = "tp"), data= dat, family = nb, method = "REML")
I did the post-hoc test using a package emmeans
:
library(emmeans)
pairs(emmeans(gam1, ~ fac|fac2|fac3, nesting = NULL))
emm2 <- contrast(pairs(emmeans(gam1, ~ fac|fac2|fac3, nesting = NULL)), by = NULL,
method = list( c(1,0,0,0,0,0,0,0,0) - c(0,0,0,0,1,0,0,0,0),
c(1,0,0,0,0,0,0,0,0) - c(0,0,0,0,0,0,0,0,1)))
I have been exploring several packages, but it seems that none of them is suitable for what I would like to achieve. Is there a package or a way of calculating the sample size necessary to achieve a desired power?