我正在尝试使用 RglmmTMB
函数来改变零膨胀泊松模型的固定和随机效应。我想将修改后的固定效果输入到powerSim
函数中。这是数据:
sample <- as.data.frame(cbind(1:50, (rep(1:10, each = 5))))
#randomize interventions by clinic
ru1 <- cbind(rbinom(10, 1, 0.5), 1:10)
ru2 <- cbind(rbinom(10, 1, 0.5), 1:10)
#merge randomization id with original sample
sample <- merge(sample, ru1, by = "V2") %>% merge(ru2)
#add days
sample <- as.data.frame(cbind(sample, scale(rep(-546:546, each = 50))))
#order by clinic and prescriber
sample <- sample[order(sample$V2, sample$V1.x),]
#simulate ZIP distribution for days supply
set.seed(789)
sample <- cbind(sample, ifelse(rbinom(54650, 1, p = 0.5) > 0, 0, rpois(54650, 5)))
#rename variables
sample <- rename(sample, pres = V1.x, clinic = V2, aj = V1.y, def = V1,
days = `scale(rep(-546:546, each = 50))`,
dayssply = `ifelse(rbinom(54650, 1, p = 0.5) > 0, 0, rpois(54650, 5))`)
#days truncated
sample$days_ <- ifelse(0 > sample$days, 0, sample$days)
#model
m1 <- glmmTMB(dayssply ~ aj*days_ + (1|clinic/pres), zi = ~ aj*days_,
data = sample, family = poisson)
经过大量的试验和错误,我终于想出了如何使用 fixef 函数指定条件固定效果:
fixef(m1)$cond [["aj"]]
但是,当我尝试将其更改为功率分析所需的固定效应时,我收到“cond 不是固定效应的名称”的错误。不确定这是否是与语法相关的问题,或者 fixef 是否不适用于零膨胀模型。
我还想使用 VarCorr 更改随机效应的方差。