1

我想知道是否有可能对 GAM 的事后测试进行功率分析?我对实现所需功效所需的样本量特别感兴趣。

我的 GAM 看起来像这样:

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")

我使用包进行了事后测试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)))

我一直在探索几个包,但似乎它们都不适合我想要实现的目标。是否有一个包或一种方法来计算达到所需功效所需的样本量?

4

0 回答 0