I have a monthly time series of count data that I have fitted a negative binomial AR1 segmented regression model with dummy variables for months to control for seasonal effects and an indicator variable for an intervention. I am attempting to quantify the magnitude of the effect of the intervention by calculating the difference of the predicted values during the last 12 months of the series, with and without the intervention effect. I want to report the confidence intervals of the difference. I have a rough understanding of how to do this and understand the need for using the multivariate delta method, but I have a hard time implementing this in R. Dummy data for clarity:
## An explanation of the structure of the df
df <- data.frame(
count = c(10,12,9,9,12,15,17,13,10,6),
month = facotr(month.name, levels = month.name),
time = 1:length(timeseries),
intervention = ifelse(time >= time_of_intervention, 1, 0),
intervention_trend = c(rep(0, time_of_intervention), 1:(length(timeseries) - (time_of_intervention - 1))),
lag1 = c(NA, count[-nrow(df)])
)
## models with and without the intervention
nullmodel <- glm.nb(count ~ month + time + log(lag1), data=df)
fullmodel <- glm.nb(count ~ intervention_level + intervention_trend + month + time + log(lag1), data = df)
## the difference I would like confidence intervals for
sum_without <- sum(exp(predict(nullmodel)[length(predict(nullmodel))- 11:0]))
sum_with <- sum(exp(predict(fullmodel)[length(predict(fullmodel))- 11:0]))
diff <- sum_with - sum_without
I thought I would use multivariate normal sampling of the coefficients of the model with and without and do repeated sums of the fitted values of last 12 timepoints to produce a distribution and estimate the confidence intervals from there. I don't know how to do this in R. This is as far as I have gotten:
without_coeff_sample <- mvrnorm(n = 10000, mu = nullmodel$coefficients, Sigma = vcov(nullmodel))
with_coeff_sample <- mvrnorm(n = 10000, mu = fullmodel$coefficients, Sigma = vcov(fullmodel))
I'm not sure how to proceed from here. Any thoughts appriciated.