CausalImpact package in R does not work for bsts Poisson model

I would like to use the CausalImpact R package to evaluate the effect of the intervention on the number of cases of infectious diseases. We usually characterize the distribution of case counters, both Poisson and negative binomes. The function bsts()allows you to specify the Poisson family. However, this encountered an error inCausalImpact()

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 it bsts.modeldoes not have a slot sigma.obswhen creating using family="poisson".

Am I doing it right or is there another way to use CausalImpact with Poisson data? (I would also like to be able to use negative binomial data, but I will not be too greedy).

, CausalImpact? "" GitHub.

+4

Source: https://habr.com/ru/post/1660214/


All Articles