我正在尝试使用 CausalImpact 包模拟风暴对销售模式的影响。当我创建一个动物园对象并将其传递给模型时,我收到一个错误。我已经通读了文档,但无法弄清楚我在做什么与文档中的示例不同。
我正在使用以下data.frame:
> head(my.data)
date sales units
1 2014-10-17 71319.85 21436.64
2 2014-10-18 88598.26 26755.79
3 2014-10-19 95768.29 29823.86
4 2014-10-20 62303.04 19417.71
5 2014-10-21 56477.57 17562.21
6 2014-10-22 54890.39 16946.43
然后我将其转换为动物园对象:
my.data<- zoo( my.data[ ,c('sales','units')], my.data[,'date'] )
> str(my.data)
‘zoo’ series from 2014-10-17 to 2017-04-13
Data: num [1:907, 1:2] 71320 88598 95768 62303 56478 ...
- attr(*, "dimnames")=List of 2
..$ : NULL
..$ : chr [1:2] "sales" "units"
Index: Date[1:907], format: "2014-10-17" "2014-10-18" "2014-10-19" ...
然后我设置前期和后期并运行模型:
pre.period <- as.Date(c('2015-10-17','2017-03-09'))
post.period <- as.Date(c('2017-03-10','2017-04-13'))
library(CausalImpact)
impact<- CausalImpact(data = my.data, pre.period = pre.period, post.period = post.period, alpha = .01)
但我收到此错误:
> impact<- CausalImpact(data = my.data, pre.period = pre.period, post.period = post.period, alpha = .05)
Error in bsts(formula, data = data, state.specification = ss, expected.model.size = kStaticRegressionExpectedModelSize, :
Caught exception with the following error message:
BregVsSampler did not start with a legal configuration.
Selector vector: 11
beta: 0 0
我已经成功地将这个包与单变量时间序列数据一起使用,但无法确定为什么这不起作用。
谢谢您的帮助!