r - Errors using CausalImpact package with Zoo objects -
i'm trying model impact of storms on sales patterns using causalimpact package. when create zoo object , pass model receive error. i've read through documentation , can't figure out i'm doing differently examples in documentation.
i'm working 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 zoo object:
my.data<- zoo( my.data[ ,c('sales','units')], my.data[,'date'] ) > str(my.data) ‘zoo’ series 2014-10-17 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 set pre , post periods , run 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 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 following error message: bregvssampler did not start legal configuration. selector vector: 11 beta: 0 0
i've used package univariate time series data, cant identify why isn't working.
thank help!
i ran same exact issue, after applying recent package updates (including causalimpact). working fine previously.
while don't have exact cause/solution, have discovered may you.
in data, tried replacing dates in zoo object test sequence. in case like:
time.pts <- seq.date(as.date("2014-10-17"), = 1, length.out = 907) my.data<- zoo( my.data[ ,c('sales','units')], time.pts )
after doing this, "bregvssampler" exception did not occur. figured issue must related dates, , put original date series zoo object. noticed had gap between pre.period , post.period, i.e. see gap between 3/9 , 3/20 below:
pre.period <- as.date(c('2015-10-17','2017-03-09')) post.period <- as.date(c('2017-03-20','2017-04-13'))
when adjusted pre/post periods remove gap in dates, problem again went away.
while don't seem have such gap in code show above, may want @ date series inconsistencies and/or try different date range. there bug somewhere needs fixed, perhaps above info work around issue in interim.
Comments
Post a Comment