google / google/CausalImpact

CausalImpact() causes R to crash if not all dates exist in the defined period

Open
#32 22 comments 0 reactions 0 assignees View on GitHub
Dominant language
R
Stars
1.9k
Forks
264
PR merge metrics
No merged PRs in 30d

Description

I am trying to exclude a single date in my post period, and model the impact with the rest of the dates. If I don't filter out the single date (see `grey_date` below) the code runs fine and returns results. If I do filter out the `grey_date` then it causes R to crash.

```
pre_start = '2019-02-17'
pre_end = '2019-04-13'
post_start = '2019-04-28'
post_end = '2019-05-25'

pre.period <- as.Date(c(pre_start, pre_end))
post.period <- as.Date(c(post_start, post_end))

grey_date = '2019-05-17'
metric = 'xyz'

data_comp <- dat %>%
filter(ds >= as.Date(pre_start) & ds <= as.Date(post_end)) %>%
filter(ds != as.Date(grey_date)) %>% # this line causes crash, works fine without it
select(ds, country, metric) %>%
spread(country, metric)

timeseries <- zoo(data_comp %>% select(NO, NL), data_comp$ds)

# CausalImpact
impact <- CausalImpact(
timeseries,
pre.period,
post.period,
model.args = list(prior.level.sd = 0.01, niter = 5000, nseasons = 7, season.duration = 1)
)
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.