I have conducted a controlled interrupted time series analysis within a GLMM framework. I have run the analysis in both the control and treatment groups separately to quantify the basic effects:
# Treatment group
its.trt <- glmmTMB(out ~ ar1(time + 0 | id) + post + time_post + (1 | id) + offset(log(exposure)),
data = df,
family = poisson)
# Control group
its.tau <- glmmTMB(out ~ ar1(time + 0 | id) + post + time_post + (1 | id) + offset(log(exposure)),
data = df,
weights = wts,
family = poisson)
I have also run the analysis in both groups to determine whether differences exist between the two groups:
# Controlled ITS
cits <- glmmTMB(out ~ ar1(time + 0 | id) + post + time_post + group + time_group + post_group + time_post_group + (1 | id) + offset(log(exposure)),
data = df,
weights = wts,
family = poisson)
I would now like to run the analysis within a GAMM framework.
Question 1: To do so, which variables should be smoothed? Is it simply the time variable:
# Treatment group
its.trt <- bam(out ~ s(time) + post + time_post + s(id, bs = "re") + offset(log(exposure)),
data = df,
family = poisson)
# Control group
its.tau <- bam(out ~ s(time) + post + time_post + s(id, bs = "re") + offset(log(exposure)),
data = df,
weights = wts,
family = poisson)
# Controlled ITS
cits <- bam(out ~ s(time) + post + time_post + group + time_group + post_group + time_post_group + s(id, bs = "re") + offset(log(exposure)),
data = df,
weights = wts,
family = poisson)
?
Or the time variable and all its composites:
# Treatment group
its.trt <- bam(out ~ s(time) + post + s(time_post) + s(id, bs = "re") + offset(log(exposure)),
data = df,
family = poisson)
# Control group
its.tau <- bam(out ~ s(time) + post + s(time_post) + s(id, bs = "re") + offset(log(exposure)),
data = df,
weights = wts,
family = poisson)
# Controlled ITS
cits <- bam(out ~ s(time) + post + s(time_post) + group + s(time_group) + post_group + s(time_post_group) + s(id, bs = "re") + offset(log(exposure)),
data = df,
weights = wts,
family = poisson)
?
Question 2: Assuming autocorrelation is present in the residuals, is it better to smooth the term(s), use an alternative correlation structure (e.g., through gamm
), or both?
Any assistance would be appreciated. Clarification of the R
code (inc., variations as required) would be greatly appreciated.