8

I'd like to use the CausalImpact package in R to estimate the impact of an intervention on infectious disease case counts. We typically characterize the distributions of case counts as either Poisson or negative binomial. The bsts() function allows us to specify the Poisson family. However this encountered an error in CausalImpact()

set.seed(1)
x1 <- 100 + arima.sim(model = list(ar = 0.999), n = 100)
y <- rpois(100, 1.2 * x1)
y[71:100] <- y[71:100] + 10
data <- cbind(y, x1)
pre.period <- c(1, 70)
post.period <- c(71, 100)
post.period.response <- y[post.period[1] : post.period[2]]
y[post.period[1] : post.period[2]] <- NA
ss <- AddLocalLevel(list(), y)
bsts.model <- bsts(y ~ x1, ss, family="poisson", niter = 1000)
impact <- CausalImpact(bsts.model = bsts.model,
                   post.period.response = post.period.response)

Error in rnorm(prod(dim(state.samples)), 0, sigma.obs) : invalid arguments

This is due to the fact that bsts.model has no sigma.obs slot when generated using family="poisson".

Am I doing this correctly or is there another way to use CausalImpact with Poisson data? (I'd also love to be able to use negative binomial data, but I won't get too greedy).

Last, is this the best place for coding issues for CausalImpact? I didn't see an Issues tab on the GitHub page.

salauer
  • 81
  • 2
  • There was a causalimpact Google Group but they closed last year and requested people post here. So I think you're in the right place. – Jeremy Miles Nov 08 '16 at 23:00
  • Thanks @JeremyMiles though I am concerned that there is a causalimpact tag in stats.stackexchange, but not here. – salauer Nov 11 '16 at 16:01
  • You could create a tag. Also, if you mention @kay-brodersen does it ping them? (I'm not sure.) – Jeremy Miles Nov 12 '16 at 03:27
  • 1
    @salauer Did you ever find a solution for this? – tom Dec 20 '17 at 17:37
  • 1
    @tom No, I didn't. I've moved on to using different methods of causal inference, such as targeted maximum likelihood estimation (TMLE). – salauer Dec 21 '17 at 18:48

0 Answers0