我想在R中使用CausalImpact软件包来估计干预措施对传染病病例数的影响。我们通常将案例计数的分布表征为泊松或负二项式。 bsts()
函数允许我们指定泊松族。但是,这在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
这是因为bsts.model
在使用sigma.obs
生成时没有family="poisson"
个广告位。
我是否正确地执行此操作或是否有另一种方法将CausalImpact与Poisson数据一起使用? (我也喜欢能够使用负二项式数据,但我不会太贪心)。
最后,这是CausalImpact编码问题的最佳位置吗?我没有在GitHub页面上看到“问题”选项卡。