I'm trying to model the impact of storms on sales patterns using the CausalImpact package. When I create a zoo object and pass it to the model I receive an error. I've read through the documentation and can't figure out what I'm doing differently from the examples in the documentation.
I'm working with the following 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
Then I'm converting it to a zoo object:
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" ...
Then I set the pre and post periods and run the model:
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)
But I'm receiving this error:
> 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
I've used this package successfully with univariate time series data, but cant identify why this isn't working.
Thank you for your help!