Git Product home page Git Product logo

causalimpact's Introduction

CausalImpact

R-CMD-check Codecov test coverage

An R package for causal inference using Bayesian structural time-series models

This R package implements an approach to estimating the causal effect of a designed intervention on a time series. For example, how many additional daily clicks were generated by an advertising campaign? Answering a question like this can be difficult when a randomized experiment is not available. The package aims to address this difficulty using a structural Bayesian time-series model to estimate how the response metric might have evolved after the intervention if the intervention had not occurred.

As with all approaches to causal inference on non-experimental data, valid conclusions require strong assumptions. The CausalImpact package, in particular, assumes that the outcome time series can be explained in terms of a set of control time series that were themselves not affected by the intervention. Furthermore, the relation between treated series and control series is assumed to be stable during the post-intervention period. Understanding and checking these assumptions for any given application is critical for obtaining valid conclusions.

Installation

install.packages("CausalImpact")
library(CausalImpact)

Getting started

Video tutorial

Documentation and examples

Further resources

causalimpact's People

Contributors

alhauser avatar deanmarchiori-irx avatar evjan avatar fmarquezg avatar jeffreyoldham avatar kaybrodersen avatar kjewell avatar picarus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

causalimpact's Issues

Is it possible for support on multivariate analysis (MBSTS)?

Hi Team, thank you for the great package!
I'm trying to use this package to analysis impact on multiple time series, but I noticed that current package only supports doing these independently. Is it possible to provide support for analysis with multiple variables, using methods like mbsts? Or could you shed some light on how can I do this with the mbsts() function in the bsts package? Thank you!

Error in bsts when using dynamic.regression

I tried to fit a dynamic.regression, but it seems to be broken:

Error in bsts(y, state.specification = ss, niter = model.args$niter, expected.model.size = 3, : Caught an exception with the following error message in MCMC iteration 63. Aborting. illegal parameter values passed to rgamma: a = 448 scale = 0

4. bsts(y, state.specification = ss, niter = model.args$niter, expected.model.size = 3, ping = 0, seed = 1, prior = sd.prior)
3. ConstructModel(data.modeling, model.args)
2. RunWithData(data, pre.period, post.period, model.args, alpha)
1. CausalImpact(serie, pre.period, post.period, model.args = list(niter = 1000, dynamic.regression = T))

Different families of distributions - custom bsts

I have tried to use a custom model, but I have noticed that this package seems to work with "gaussian" and "student" families (from the bsts package), but not with the "logit" and "poisson" families (which are supported by bsts).

I think adding support for these families would be useful.

Another alternative, probably easier to implement (but probably suboptimal), would be to add support for variable transformations and backtrasformations.

https://robjhyndman.com/hyndsight/forecasting-within-limits/
https://robjhyndman.com/hyndsight/backtransforming/

I think the poisson family is particularly important since it is very common to deal with count data.

Dynamic pre and post periods

First, thanks so much for the incredible package! This is an amazing contribution. Second, I'm wondering how to accommodate datasets where the pre- and post- date vary depending on some other variable. For example, let's say I'm trying to evaluate the impact of some policy, but different states implement the policy at different periods of time, and therefore have different "pre" and "post" windows.

I'm guessing this requires a custom model, but the documentation isn't clear on how to accomplish this.

Any thoughts?

Multiple regressors not shown in plot

When I use CausalImpact on data like this

             y    x1  x2
2017-09-04   150 150 275
2017-09-05   200 249 125
2017-09-06   225 150 249
2017-09-07   150 125 275
2017-09-08   175 325 250
2017-09-09   200 175 250

then it seems like I get only one counterfactual prediction, even though the two time series x1 and x2 are meant to be used as indipendent. How's this single prediction computed (cfr. attachment) ?
screenshot from 2018-05-15 13-22-26

Controlling randomness of results

Using the same dataset, multiple runs of CausalImpact produce different p-values and confidence intervals using bsts. They are within a small range of each other when using large niter values, but I want to produce the same values each time. How can these be controlled so that the results are consistent with every run?

Thanks

Python version

Are you planning and/or interested to have a python version?

Issue with plot()

Is df one of the inputs to plot function? I keep having issue with plot function:

plot(impact)
Error in plot(impact) : argument "df" is missing, with no default

Unable to load the "CausalImpact" library

The package worked fine for me a few months earlier, but I was unable to load the "CausalImpact" library today. See the error message below:

Error: package or namespace load failed for ‘BoomInterface’ in dyn.load(file, DLLpath = DLLpath, ...):
unable to load shared object....
Error: package ‘BoomInterface’ could not be loaded

Statistically Testing the post-period two series or testing the Difference equals zero

Hello,

Thanks to the authors for making, sharing, and publishing this great package. My question is: after the intervention occurs and in the post-period window, we have two-time series:

  1. The time series after the intervention (The real data)
  2. The prediction time series data (Created by the library) predicting what would have happened if we didn't introduce the intervention.

My question is: Is there a statistical test to check and test whether the difference between these two-time series is statistically significant or not. In other words, the plot(impact) command would produce 3 plots (original, pointwise, and cumulative) is there a statistical test to test the hypothesis of whether the difference between the aforementioned two time series in the "pointwise" figure equals zero or not.

http://google.github.io/CausalImpact/CausalImpact.html

Thank you very much.

Error in parse(text = x, keep.source = FALSE) : <text>:1:9: unexpected symbol

I apply casual impact with the following code
impact <- CausalImpact(SynthTS, pre.period, post.period, model.args = list(niter = 5000, nseasons = 7, season.duration = 1, dynamic.regression=FALSE))

but I hit the following error:

Error in parse(text = x, keep.source = FALSE) : 
  <text>:1:9: unexpected symbol
1: My Column
                    ^

For debugging my SynthTS is a zoo object:

> str(SynthTS)
‘zoo’ series from 2016-07-01 to 2019-10-30
  Data: num [1:1217, 1:7] 0 66.4 49.7 10 76.9 ...
 - attr(*, "dimnames")=List of 2
  ..$ : NULL
  ..$ : chr [1:7] "My Column" "My Column2" "My Column3" "My Column4" ...
  Index:  Date[1:1217], format: "2016-07-01" "2016-07-02" "2016-07-03" "2016-07-04" "2016-07-05" "2016-07-06" "2016-07-07" "2016-07-08" "2016-07-09" "2016-07-10" "2016-07-11" ...

Can it be an issue that my column names have a space inside?

Whitened innovation and other diagnostics

I am using CausalImpact/bsts for a project and would like to use the in-sample whitened innovation (one step prediction error) to test for independence, homocedasticity, and Gaussianity, and general diagnostics.

I can find the in-sample innovation in bsts.object$one.step.prediction.errors, but after digging through the source code I cannot find the variance of the in sample innovations (This would be F_t using the notation in Durbin and Koopman 2nd ed). I assume those had to be computed somewhere to get the filtered estimates. Any pointers would be greatly appreciated.

In addition, I am also interested in testing for shocks in the state and/or observation model using the "smoothations" approach described in de Jong and Penzer (JASA 1998), which is also described at the end of Section 7.5 of Durbin and Koopman 2nd ed. These are a by-product of the disturbance smoother, which I believe bsts uses. Using the notation in Durbin and Koopman, this would be:
r_{i,t}^s = r_{i,t} / sqrt(N_{i,i,t}) and
u_{i,t}^s = u_{i,t} / sqrt(D_{i,i,t}) (in the book, there is a typo in the eq, but what I wrote here is correct).

Again, any pointers would be greatly appreciated.

Cheers!
Camilo

Case Studies of CausalImpact

thanks for releasing this amazing library! Are there any documented use cases of how Google uses this CausalImpact library on real world data?

It'd also be helpful if someone could point me to any documentation of this library being used for practical real use cases, and not just sample data. I'm trying to understand the limitations in the interpretation of the output before I use this library to reach any conclusions for an actual use case. Thanks,

Several questions about the codes

Hi CausalImpact team,

I'm trying to use the CausalImpact package to implement one of our company's project. Here are some questions after I reviewing the raw code from this repository:

  1. I noticed that in the file impact_model.R The expected.model.size of the function bsts is fixed to be 3 (by the variable kStaticRegressionExpectedModelSize). Is there any reason for this parameter to be fixed as 3 ? Also, Is that possible to make it adjustable in the future is by model.args ?

  2. I also noticed that both pre.period and post.period control groups' data are included in one bsts function, which may cause while estimating the posterior distribution of the coefficients by using the pre.period data, the post.period information is also used.

For example: If my dataset test is like:

date_period, target, control_1, control_2
1, 100 , 3, 0,
2, 90, 2, 0,
3, 80, 2, 0,
4, 70, 3, 1,
5, 60, 3, 1

code of generating this test data:

target = c(100, 90, 80, 70, 60)
control1 = c(3,2,2,3,3)
control2 = c(0,0,0,1,1)

test = data.frame(target, control1, control2)

and
pre.period = c(1,2), post.period = c(3,4)

In this case, if you run the command:

impact <- CausalImpact(test, pre.period, post.period, model.args = list(standardize.data=F, niter = 100),alpha = 0.9)
coef = as.data.table(impact$model$bsts.model$coefficients)

you can find control_2 also shows non-zero coefficients in each iteration.

This is of course an extreme case. My question is, have you tried how different will be the results: between using current method, and the traditional predict(bsts) after building the model by only using pre.period data?

Thank you in advance!

`Plot` function cause R to crash for no particular error message

I was commenting under another crash related issue but found out mine eventually was a different story.

I am running R 4.1 in MX linux 19.04, with the package version being 1.2.7.

I have attached the test data as well, which is 900 rows of stock daily OHLCV data.
spce.csv

fin.ci <- function(data, interv.date, period="other", extend=F, range=c(5,9)){

  from <- range[1]
  to <- range[2]
  
  if (identical(period, "daily")){
    start <- ymd(interv.date) - days(from)
    end <- ymd(interv.date) + days(to) 
    pre.interv <- ymd(interv.date) - days(1)
    pre.period <- c(start, ymd(pre.interv))
    post.period <- c(ymd(interv.date), end)
    dat.xts <- xts(data$close, order.by = ymd(data$date))
  }else{
    start <- ymd_hms(interv.date) - days(from)
    end <- ymd_hms(interv.date) + days(to) + hours(5) + minutes(59)
    pre.interv <- ymd_hms(interv.date) - days(1) + ifelse(extend, hours(6), hours(5))
    pre.period <- c(start, ymd_hms(pre.interv))
    post.period <- c(ymd_hms(interv.date), end)
    dat.xts <- xts(data$close, order.by = ymd_hms(data$date))
  }
  res <- CausalImpact(dat.xts, pre.period, post.period)
  summary(res)
  plot(res)
}

I can run through to summary(res). The output from summary(res):

Posterior inference {CausalImpact}

                         Average      Cumulative 
Actual                   25           200        
Prediction (s.d.)        17 (0.28)    133 (2.23) 
95% CI                   [16, 17]     [128, 137] 
                                                 
Absolute effect (s.d.)   8.4 (0.28)   67.2 (2.23)
95% CI                   [7.9, 9]     [63.1, 72] 
                                                 
Relative effect (s.d.)   51% (1.7%)   51% (1.7%) 
95% CI                   [48%, 54%]   [48%, 54%] 

Posterior tail-area probability p:   0.00102
Posterior prob. of a causal effect:  99.89837%

For more details, type: summary(impact, "report")

It seems the new pull request could fix it, but I thought it's probably better to still flag it up.

Thanks Team.

missing values

I have two models fit using this code: https://github.com/markhwhiteii/blog/blob/master/causalimpact/causalimpact.R

I'm wondering why I always get the ggplot2 errors for missing data/data outside of the range of the plot when I run the plot function on an impact object:

Removed 82 rows containing missing values (geom_path).
Removed 164 rows containing missing values (geom_path).

Figures for both of the impact objects have straight lines for the counterfactual predictions... Does that have something to do with it? I'm not sure if I am missing something simple, but I have noticed other people run into similar problems (https://rpubs.com/heruwiryanto/Causal_impact).

predict.bsts does not capture holiday information

Hi!

I've been working with bsts to model time-series and make forecasts, but have run into some problems with the predict function and holidays.

When I train the model with regressor holidays these regressors do not appear to be used in the predict function. For instance in a simple local level model the holiday regressor causes the response variable to go down, but the predictor of the response over the same period does not capture this behaviour.

I attach below a minimum working example based on the regression.holiday code from the documentation:

library(bsts)
library(ggplot2)
set.seed(12345)

trend <- cumsum(rnorm(1095, 0, .1))
  dates <- seq.Date(from = as.Date("2014-01-01"), length = length(trend), by = "day")
  y <- zoo(trend + rnorm(length(trend), 0, .2), dates)

AddHolidayEffect <- function(y, dates, effect) {
  ## Adds a holiday effect to simulated data.
  ## Args:
  ##   y: A zoo time series, with Dates for indices.
  ##   dates: The dates of the holidays.
  ##   effect: A vector of holiday effects of odd length.  The central effect is
  ##     the main holiday, with a symmetric influence window on either side.
  ## Returns:
  ##   y, with the holiday effects added.
  time <- dates - (length(effect) - 1) / 2
  for (i in 1:length(effect)) {
    y[time] <- y[time] + effect[i]
    time <- time + 1
  }
  return(y)
}

## Define some holidays.
memorial.day <- NamedHoliday("MemorialDay")
memorial.day.effect <- c(-.75, -2, -2)
memorial.day.dates <- as.Date(c("2014-05-26", "2015-05-25", "2016-05-25"))
y <- AddHolidayEffect(y, memorial.day.dates, memorial.day.effect)

## The holidays can be in any order.
holiday.list <- list(memorial.day)

## Let's train the model to just before MemorialDay
cut_date = as.Date("2016-05-20")
train_data <- y[time(y) < cut_date]
test_data <- y[time(y) >= cut_date]
ss <- AddLocalLevel(list(), train_data)
ss <- AddRegressionHoliday(ss, train_data, holiday.list = holiday.list)
model <- bsts(train_data, state.specification = ss, niter = 500, ping = 0)
## Now let's make a prediction covering MemorialDay
my_horizon = 15
## Note adding the time stamps here doesn't help either
pred <- predict(object = model, horizon = my_horizon)
## Make a data frame for plotting
plot_info <- data.frame(Date = time(y), 
                        value = y, 
                        predict_mean = NA,
                        predict_upper = NA,
                        predict_lower = NA
                       )
plot_info[plot_info$Date %in% time(test_data)[1:my_horizon],]$predict_mean = pred$mean
plot_info[plot_info$Date %in% time(test_data)[1:my_horizon],]$predict_lower = pred$interval[1,]
plot_info[plot_info$Date %in% time(test_data)[1:my_horizon],]$predict_upper = pred$interval[2,]
## Let's make a pretty plot to demonstrate the problem
filter(plot_info, Date > time(test_data)[1] - 25 & Date < time(test_data)[my_horizon] + 10)  %>% 
    ggplot(aes(x = Date, y = value)) +
    geom_line() +
    geom_line(aes(y = predict_mean), col = "Forest Green") + # The prediction
    geom_line(aes(y = predict_lower), col = "Forest Green", lty = 2) + # lower bound
    geom_line(aes(y = predict_upper), col = "Forest Green", lty = 2)  # upper bound

Choose the predictor time series as the shifted series

I am interested in the CausalImpact to analyse the impact of an event on a time series.

Now, it the serious challenge to find a proper Control Series, I think. But unfortunately in my case this might be a problem. So I came to the following idea.

What about using the shifted time series for your response? If I have click rates for the last 3 years and what to analyse the impact of my event, I think I could use the same Series shifted by let's say 1 year. This underlies the assumption that over a year for eg a specific month my Response behaves similar to last years'month. So I can use the shifted series to see if the event has an impact for this year's month?

This seems a very easy idea, but is not mentioned especially in this nice video.

Maybe I oversee some statistical consequences?

Any one who has an idea?

CausalImpact Simulation data

Hello,

Big fan of the package. I'm working on my own developments to the approach and would like to compare them to the simulation data in Brodersen et al section 3. However, this dataset isn't provided in the package. Could you make available the code to create the data or the data itself? I'd like to ensure differences in simulation results aren't caused by my coding skills or weird seed issues.

Thanks!

Error installing BoomSpikeSlab

Hi Everyone,

I am trying to install bsts package for that I need to install its dependencies Boom and BoomSpikeSlab. I was successfully able to install Boom after trying Mac Binaries from its CRAN page but I am not able to install BoomSpikeSlab. I am having Linus-gnu operating system and working on Rstudio.

Below is the error that I am getting......

Installing package into ‘/libs/workspace’
(as ‘lib’ is unspecified)
trying URL 'https://cloud.r-project.org/src/contrib/BoomSpikeSlab_1.2.5.tar.gz'
Content type 'application/x-gzip' length 129209 bytes (126 KB)

downloaded 126 KB

  • installing source package ‘BoomSpikeSlab’ ...
    ** package ‘BoomSpikeSlab’ successfully unpacked and MD5 sums checked
    ** using staged installation
    ** libs
    g++ -std=gnu++11 -I"/opt/R/3.6.1/lib/R/include" -DNDEBUG -I/opt/R/3.6.1/lib/R/bin/Rscript -e "cat(system.file(package='Boom'))"/include -DADD_ -DR_NO_REMAP -DRLANGUAGE -I"/libs/workspace/Boom/include" -I/usr/local/include -fpic -g -O2 -c boom_spike_slab_init.cc -o boom_spike_slab_init.o
    g++ -std=gnu++11 -I"/opt/R/3.6.1/lib/R/include" -DNDEBUG -I/opt/R/3.6.1/lib/R/bin/Rscript -e "cat(system.file(package='Boom'))"/include -DADD_ -DR_NO_REMAP -DRLANGUAGE -I"/libs/workspace/Boom/include" -I/usr/local/include -fpic -g -O2 -c logit_spike_slab_wrapper.cc -o logit_spike_slab_wrapper.o
    In file included from /libs/workspace/Boom/include/LinAlg/VectorView.hpp:28:0,
    from /libs/workspace/Boom/include/LinAlg/Matrix.hpp:24,
    from /libs/workspace/Boom/include/r_interface/boom_r_tools.hpp:25,
    from /libs/workspace/Boom/include/r_interface/seed_rng_from_R.hpp:22,
    from logit_spike_slab_wrapper.cc:10:
    /libs/workspace/Boom/include/LinAlg/VectorViewIterator.hpp:183:24: error: specialization of ‘template struct std::iterator_traits’ in different namespace [-fpermissive]
    template<> struct std::iterator_traitsBOOM::VectorViewIterator {
    ^
    In file included from /usr/include/c++/4.8.2/bits/stl_algobase.h:65:0,
    from /usr/include/c++/4.8.2/bits/char_traits.h:39,
    from /usr/include/c++/4.8.2/string:40,
    from logit_spike_slab_wrapper.cc:5:
    /usr/include/c++/4.8.2/bits/stl_iterator_base_types.h:159:12: error: from definition of ‘template struct std::iterator_traits’ [-fpermissive]
    struct iterator_traits
    ^
    In file included from /libs/workspace/Boom/include/LinAlg/VectorView.hpp:28:0,
    from /libs/workspace/Boom/include/LinAlg/Matrix.hpp:24,
    from /libs/workspace/Boom/include/r_interface/boom_r_tools.hpp:25,
    from /libs/workspace/Boom/include/r_interface/seed_rng_from_R.hpp:22,
    from logit_spike_slab_wrapper.cc:10:
    /libs/workspace/Boom/include/LinAlg/VectorViewIterator.hpp:191:25: error: specialization of ‘template struct std::iterator_traits’ in different namespace [-fpermissive]
    template <> struct std::iterator_traitsBOOM::VectorViewConstIterator {
    ^
    In file included from /usr/include/c++/4.8.2/bits/stl_algobase.h:65:0,
    from /usr/include/c++/4.8.2/bits/char_traits.h:39,
    from /usr/include/c++/4.8.2/string:40,
    from logit_spike_slab_wrapper.cc:5:
    /usr/include/c++/4.8.2/bits/stl_iterator_base_types.h:159:12: error: from definition of ‘template struct std::iterator_traits’ [-fpermissive]
    struct iterator_traits
    ^
    In file included from /libs/workspace/Boom/include/LinAlg/Array.hpp:23:0,
    from /libs/workspace/Boom/include/r_interface/boom_r_tools.hpp:28,
    from /libs/workspace/Boom/include/r_interface/seed_rng_from_R.hpp:22,
    from logit_spike_slab_wrapper.cc:10:
    /libs/workspace/Boom/include/LinAlg/ArrayIterator.hpp:135:25: error: specialization of ‘template struct std::iterator_traits’ in different namespace [-fpermissive]
    template <> struct std::iterator_traitsBOOM::ArrayIterator {
    ^
    In file included from /usr/include/c++/4.8.2/bits/stl_algobase.h:65:0,
    from /usr/include/c++/4.8.2/bits/char_traits.h:39,
    from /usr/include/c++/4.8.2/string:40,
    from logit_spike_slab_wrapper.cc:5:
    /usr/include/c++/4.8.2/bits/stl_iterator_base_types.h:159:12: error: from definition of ‘template struct std::iterator_traits’ [-fpermissive]
    struct iterator_traits
    ^
    In file included from /libs/workspace/Boom/include/LinAlg/Array.hpp:23:0,
    from /libs/workspace/Boom/include/r_interface/boom_r_tools.hpp:28,
    from /libs/workspace/Boom/include/r_interface/seed_rng_from_R.hpp:22,
    from logit_spike_slab_wrapper.cc:10:
    /libs/workspace/Boom/include/LinAlg/ArrayIterator.hpp:144:24: error: specialization of ‘template struct std::iterator_traits’ in different namespace [-fpermissive]
    template<> struct std::iterator_traitsBOOM::ConstArrayIterator {
    ^
    In file included from /usr/include/c++/4.8.2/bits/stl_algobase.h:65:0,
    from /usr/include/c++/4.8.2/bits/char_traits.h:39,
    from /usr/include/c++/4.8.2/string:40,
    from logit_spike_slab_wrapper.cc:5:
    /usr/include/c++/4.8.2/bits/stl_iterator_base_types.h:159:12: error: from definition of ‘template struct std::iterator_traits’ [-fpermissive]
    struct iterator_traits
    ^
    make: *** [logit_spike_slab_wrapper.o] Error 1
    ERROR: compilation failed for package ‘BoomSpikeSlab’
  • removing ‘/libs/workspace/BoomSpikeSlab’
    Warning in install.packages :
    installation of package ‘BoomSpikeSlab’ had non-zero exit status

The downloaded source packages are in
‘/tmp/RtmprDP2RP/downloaded_packages’

Could any one please help me out how to install BoomSpikeSlab on R-Studio?

I can't get summury from date indexing data: 'NoneType' object has no attribute 'loc'

The source code is following. I ran example code in google colab.
import pandas as pd
from causalimpact import CausalImpact

data = pd.read_csv('https://raw.githubusercontent.com/WillianFuks/tfcausalimpact/master/tests/fixtures/comparison_data.csv', index_col=['DATE'])
pre_period = ['2019-04-16', '2019-07-14']
post_period = ['2019-7-15', '2019-08-01']
ci = CausalImpact(data, pre_period, post_period)

pd.version
1.5.2
print(ci.summary())

AttributeError Traceback (most recent call last)
in
----> 1 print(ci.summary())

/usr/local/lib/python3.8/dist-packages/causalimpact/analysis.py in summary(self, output, width, path)
727 confidence = "{}%".format(int((1 - alpha) * 100))
728 post_period = self.params["post_period"]
--> 729 post_inf = self.inferences.loc[post_period[0] : post_period[1], :]
730 post_point_resp = post_inf.loc[:, "response"]
731 post_point_pred = post_inf.loc[:, "point_pred"]

AttributeError: 'NoneType' object has no attribute 'loc'

Relative Effects incorrect (wrong sign) when post-period mean is negative

See impact_inference.R, line 248:

  summary <- dplyr::mutate(summary,
                           RelEffect = AbsEffect / Pred,
                           RelEffect.lower = AbsEffect.lower / Pred,
                           RelEffect.upper = AbsEffect.upper / Pred,
                           RelEffect.sd = AbsEffect.sd / Pred)

I noticed negative RelEffect.sd in my CausalImpactObject$summary which is clearly the product of not using abs(Pred) as the denominator, as I believe it should be in each of these cases. In particular the upper and lower bounds are out of order, too, when Pred < 0 .

At least as long error

Hi,

While using my dataset for this model I've run into this error:

"bsts.model$original.series must end on a stretch of NA at least as long as y.cf"

I've tried to read the github code to better understand this error but I'm still stuck.

Is there any advice that I can use in diagnosing this?

Thanks!

Posterior predictive confidence intervals differ to calculation by `predict.bsts`

Hi, from looking at the code I can see that CausalImpact generates the posterior predictive samples by getting the state value draws and sampling noise with variance equal to the sigma.obs draws from the bsts model object.

When I try to replicate the inference step using predict.bsts, I get different results. In particular, the credible intervals produced by generating the posterior predictive with bsts.predict are larger than CausalImpact suggests. The bounds of the relative difference credible interval can differ by 2-3%. Is there inherently a difference between how CausalImpact prediction and predict.bsts works? I've attached example code below.

library(magrittr)
library(CausalImpact)

# Dummy data
set.seed(1)
x1 <- 8000 + arima.sim(model = list(ar = 0.99), n = 100)
y <- 1.2 * x1 + rnorm(100, 0, 1)
y[71:100] <- y[71:100] + 10
data <- cbind(y, x1)

pre.period <- c(1, 70)
post.period <- c(71, 100)

# Run CausalImpact
impact <- CausalImpact(data, pre.period, post.period, model.args = list(niter = 10000, standardize.data = F))

# Predictions from bsts
bsts_model <- impact$model$bsts.model
bsts_predict <-
  predict.bsts(bsts_model,
               newdata = data[post.period[1]:post.period[2], "x1"])

# Actuals as a matrix
observed_post <-
  data[post.period[1]:post.period[2], "y"] %>% 
  rep(nrow(bsts_predict$distribution)) %>% 
  matrix(nrow = nrow(bsts_predict$distribution), byrow = T)

# Calculate differences
ppd_diff <- observed_post - bsts_predict$distribution
# Cumulative to last day of post period
diff_cum <- rowSums(ppd_diff)
reldiff_cum <- rowSums(ppd_diff)/rowSums(observed_post)

# Calculated stats
cat("Absolute difference:\n")
c(quantile(diff_cum, 0.025), mn = mean(diff_cum), quantile(diff_cum, 0.975)) %>% 
  print()
# Returns 75.6, 204.3, 342.3

cat("Relative difference:\n")
c(quantile(reldiff_cum, 0.025), mn = mean(reldiff_cum), quantile(reldiff_cum, 0.975)) %>% 
  print()
# Returns 0.026%, 0.071%, 0.12%

# Compare to CausalImpact CIs
summary(impact)
# Returns 123.2, 203.7, 288.0
#         0.043%, 0.071%, 0.1%

Error during installation - fails to install bsts

Hi there,

I'm installing Causal Impact in R for the first time.

Installation fails because installation of bsts fails:

* installing *source* package 'bsts' ...
** package 'bsts' successfully unpacked and MD5 sums checked
** using staged installation
** libs

*** arch - i386
C:/Rtools/mingw_32/bin/g++  -std=gnu++11 -I"C:/PROGRA~1/R/R-36~1.1/include" -DNDEBUG -I`C:/PROGRA~1/R/R-36~1.1/bin/Rscript -e "cat(system.file(package='Boom'))"`/include -DADD_ -DR_NO_REMAP -DRLANGUAGE -I"C:/Program Files/R/R-3.6.1/library/Boom/include"        -O2 -Wall  -mtune=generic -c aggregate_time_series.cc -o aggregate_time_series.o
g++.exe: error: Files/R/R-3.6.1/library/Boom/include: No such file or directory
make: *** [C:/PROGRA~1/R/R-36~1.1/etc/i386/Makeconf:213: aggregate_time_series.o] Error 1
ERROR: compilation failed for package 'bsts'
* removing 'C:/Program Files/R/R-3.6.1/library/bsts'

It says "No such file or directory" for C:/Program Files/R/R-3.6.1/library/Boom/include (or does it?) but this folder exists and has plenty of stuff in it.

Here is my sessionInfo():

R version 3.6.1 (2019-07-05)
Platform: i386-w64-mingw32/i386 (32-bit)
Running under: Windows 10 x64 (build 19042)

Matrix products: default

locale:
[1] LC_COLLATE=English_Canada.1252  LC_CTYPE=English_Canada.1252    LC_MONETARY=English_Canada.1252 LC_NUMERIC=C                    LC_TIME=English_Canada.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] hash_2.2.6.1  ROracle_1.3-1 DBI_1.1.1    

loaded via a namespace (and not attached):
[1] compiler_3.6.1 tools_3.6.1 

Any suggestions would be greatly appreciated.

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

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)
)

Error when data is 0 in the post period

I noticed that when the data is all zeros in the post period the code execution breaks. I am using the latest version of the package available on CRAN v1.2.1

Below is a reproducible example

    library(CausalImpact)
    set.seed(1)
    df<- data.frame(y=rep(c(1,0,0),each = 10), x1 = runif(30), x2 = runif(30))
    df_zoo <- zoo(df)
    pre.period = c(1,20)
    post.period = c(21,30)
    impact<-CausalImpact(df_zoo, as.numeric(pre.period), as.numeric(post.period))

On running the script, the execution breaks throwing the following error

Error in sprintf("%0.*f", round.digits + first.nonzero - 1, x) : 
  argument for '*' conversion specification must be a number
In addition: Warning message:
In sprintf("%0.*f", round.digits + first.nonzero - 1, x) :
  NAs introduced by coercion to integer range

Below is the trace of the error

10: sprintf("%0.*f", round.digits + first.nonzero - 1, x)
9: PrettifySingleNumber(x[index], letter[index], round.digits)
8: FUN(X[[i]], ...)
7: lapply(X = X, FUN = FUN, ...)
6: sapply(seq_along(x), function(index) {
       PrettifySingleNumber(x[index], letter[index], round.digits)
   })
5: PrettifyNumber(summary$Actual, round.digits = digits)
4: InterpretSummaryTable(summary)
3: CompilePosteriorInferences(bsts.model, y.cf, post.period - pre.period[1] + 
       1, alpha, UnStandardize)
2: RunWithData(data, pre.period, post.period, model.args, alpha)
1: CausalImpact(df_zoo, as.numeric(pre.period), as.numeric(post.period))

On digging deeper into PrettifySingleNumber function I notice that it doesn't cover the scenario where the number is zero

PrettifySingleNumber <- function(x, letter, round.digits) {
    if (is.na(x) && !is.nan(x)) {
      return("NA")
    }
    else if (!is.finite(x)) {
      return(as.character(x))
    }
    else if ((letter == "" && abs(x) >= 1e+09) || letter == 
             "B") {
      return(sprintf("%0.*fB", round.digits, x/1e+09))
    }
    else if ((letter == "" && abs(x) >= 1e+06) || letter == 
             "M") {
      return(sprintf("%0.*fM", round.digits, x/1e+06))
    }
    else if ((letter == "" && abs(x) >= 1000) || letter == 
             "K") {
      return(sprintf("%0.*fK", round.digits, x/1000))
    }
    else if (abs(x) >= 1) {
      return(sprintf("%0.*f", round.digits, x))
    }
    else {
      first.nonzero <- -floor(log10(abs(x)))
      return(sprintf("%0.*f", round.digits + first.nonzero - 
                       1, x))
    }
  }

Kindly update the code to resolve this error. Thanks.

Error with plot(impact): confidence bands won't plot

I'm having an issue where plot() is just returning bare line plots with no error bands. After running into this problem with my own data I tried to copy the code from the CI tutorial exactly and I get the same problem:


library(CausalImpact)

set.seed(1)
x1 <- 100 + arima.sim(model = list(ar = 0.999), n = 100)
y <- 1.2 * x1 + rnorm(100)
y[71:100] <- y[71:100] + 10
data <- cbind(y, x1)

matplot(data, type = "l")

pre.period <- c(1, 70)
post.period <- c(71, 100)

impact <- CausalImpact(data, pre.period, post.period)

plot(impact)

image

What is it about my session that could be causing this? SessionInfo() posted below:

R version 3.5.2 (2018-12-20)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18362)

Matrix products: default

locale:
[1] LC_COLLATE=English_United Kingdom.1252  LC_CTYPE=English_United Kingdom.1252   
[3] LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C                           
[5] LC_TIME=English_United Kingdom.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] ggplot2_3.2.1       CausalImpact_1.2.3  bsts_0.9.2          xts_0.11-2         
[5] zoo_1.8-6           BoomSpikeSlab_1.2.1 Boom_0.9.3          MASS_7.3-51.1      

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.3       igraph_1.2.4.2   magrittr_1.5     tidyselect_0.2.5 munsell_0.5.0   
 [6] colorspace_1.4-1 lattice_0.20-38  R6_2.4.1         rlang_0.4.2      stringr_1.4.0   
[11] plyr_1.8.5       dplyr_0.8.3      tools_3.5.2      grid_3.5.2       gtable_0.3.0    
[16] withr_2.1.2      lazyeval_0.2.2   assertthat_0.2.1 tibble_2.1.3     lifecycle_0.1.0 
[21] crayon_1.3.4     farver_2.0.1     reshape2_1.4.3   purrr_0.3.3      glue_1.3.1      
[26] labeling_0.3     stringi_1.4.3    compiler_3.5.2   pillar_1.4.3     scales_1.1.0    
[31] pkgconfig_2.0.3 

CausalImpact plot function bug for ggplot2::geom_ribbon()

R 3.6.1
CausalImpact version 1.2.3
ggplot2 version 3.2.1
MacOS 10.14.6

Recent updates to ggplot2 (mainly geom_ribbon()) breaks the plot function in CasualImpact. All works except no ribbon plotted (see attached PDF 1).

Fig 2 attached shows that geom_ribbon() works fine if I use my own ggplot2 code here from a Stan model output. So it is the internal plot function in CausalImpact that is no longer functioning with ggplot2.

I, and I am sure others, would be grateful for a fix for this plot bug.

Fig1.pdf
Fig2.pdf

example code

I've got a warning messages while trying the example code that you offered.
plot(impact)
warning

Understand warning messages

I get the following warnings when using plot(impact) (only there, nothing is shown when I call CausalImpact(data, pre.period, post.period)

Warning messages:
1: Removed 252 rows containing missing values (geom_path). 
2: Removed 504 rows containing missing values (geom_path).

Just to make sure everything is alright, here's a reproducible example that gives the same warnings

> data
             y  x1  x2
2017-09-04 150 150 275
2017-09-05 200 249 125
2017-09-06 225 150 249
2017-09-07 150 125 275
2017-09-08 175 325 250
2017-09-09 200 175 250
2017-09-10 175 125 150
2017-09-11 225 175 274
2017-09-12 175 250 249
2017-09-13 150 250 374
2017-09-14 275 375 300
2017-09-15 300 275 400
2017-09-16 325 175 200
2017-09-17 175 175 125
2017-09-18 275 375 250
2017-09-19 225 125 324
2017-09-20 275 250 324
2017-09-21 125 200 275
2017-09-22 150 275 150
2017-09-23 100 125 250
> pre.period <- as.Date(c('2017-09-04', '2017-09-16'))
> post.period = as.Date(c('2017-09-17', '2017-09-23'))
> impact <- CausalImpact(data, pre.period, post.period)
> plot(impact)
Warning messages:
1: Removed 20 rows containing missing values (geom_path). 
2: Removed 40 rows containing missing values (geom_path). 

Power Analysis for Geo experiments

Hi team - Thanks for the amazing package.

I am looking for ideas/suggestions for doing power analysis for geo experiment. To give more context, I have a marketing intervention to test and have pre selected comparable Geos (control and treatment) to run the test on. I will be using causal impact to measure the lift of the intervention. How can I check the minimum detectable effect under this setting. I have control/test Geos, duration of the intervention and default significance levels. I would like to know the MDE - smallest treatment effect that can be measure using causalimpact technique. This key since if from business intuition this MDE is not within the range of possibility I might want to suggest a different treatment.

I am guessing this would involve simulation with adding known effects, wanted to understand if there are known functions/packages for this usecase.

Thanks!

BoomSpikeSlab installation failed | -DNDEBUG does not search in the correct /Boom/include directory

Hello there,

I've successfully installed Boom_0.9.6.tar.gz from source in a given .libPaths() by running from CLI R CMD INSTALL --library=/<XXX>/app/R40_Library /<XXX>/ds_tests/Boom_0.9.6.tar.gz . However I get below error when trying to do the same for BoomSpikeSlab_1.2.3.tar.gz.

I think I know where the error occurs, but a unable to modify the g++ -std=gnu++11 args.

SessionInfo (Microsoft R Open 4.0.2)

> sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Red Hat Enterprise Linux 8.3 (Ootpa)

Matrix products: default
BLAS:   /opt/microsoft/ropen/4.0.2/lib64/R/lib/libRblas.so
LAPACK: /opt/microsoft/ropen/4.0.2/lib64/R/lib/libRlapack.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8       
 [4] LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C              
[10] LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] RevoUtils_11.0.2     RevoUtilsMath_11.0.0

loaded via a namespace (and not attached):
[1] compiler_4.0.2 parallel_4.0.2 tools_4.0.2

R /Boom/include dir

$ ls -al /<XXX>/app/R40_Library/Boom/include/
total 42
drwxr-xr-x. 14 ishams dce    15 Nov 25 16:04 .
drwxr-xr-x.  9 ishams dce    11 Nov 25 16:05 ..
drwxr-xr-x.  2 ishams dce     4 Nov 25 16:04 Bmath
drwxr-xr-x.  2 ishams dce    43 Nov 25 16:04 cpputil
drwxr-xr-x.  2 ishams dce     9 Nov 25 16:04 distributions
-rw-r--r--.  1 ishams dce 18791 Nov 25 16:04 distributions.hpp
drwxr-xr-x.  3 ishams dce    30 Nov 25 16:04 Eigen
drwxr-xr-x.  2 ishams dce    21 Nov 25 16:04 LinAlg
drwxr-xr-x.  3 ishams dce     2 Nov 25 16:04 math
drwxr-xr-x. 14 ishams dce    72 Nov 25 16:04 Models
drwxr-xr-x.  2 ishams dce     8 Nov 25 16:04 numopt
-rw-r--r--.  1 ishams dce 14809 Nov 25 16:04 numopt.hpp
drwxr-xr-x.  2 ishams dce    13 Nov 25 16:04 r_interface
drwxr-xr-x.  4 ishams dce    17 Nov 25 16:04 Samplers
drwxr-xr-x.  2 ishams dce    23 Nov 25 16:04 stats
drwxr-xr-x.  2 ishams dce     6 Nov 25 16:04 TargetFun
-rw-r--r--.  1 ishams dce  1041 Nov 25 16:04 uint.hpp

Reproducing error

$ R CMD INSTALL --library=/<XXX>/app/R40_Library /<XXX>/ds_tests/BoomSpikeSlab_1.2.3.tar.gz


Microsoft R Open 4.0.2
The enhanced R distribution from Microsoft
Microsoft packages Copyright (C) 2020 Microsoft Corporation

Using the Intel MKL for parallel mathematical computing (using 8 cores).

Default CRAN mirror snapshot taken on 2020-07-16.
See: https://mran.microsoft.com/.

* installing *source* package ‘BoomSpikeSlab’ ...
** package ‘BoomSpikeSlab’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
g++ -std=gnu++11 -I/opt/microsoft/ropen/4.0.2/lib64/R/include -DNDEBUG -I`/opt/microsoft/ropen/4.0.2/lib64/R/bin/Rscript -e "cat(system.file(package='Boom'))"`/include -DADD_ -DR_NO_REMAP -DRLANGUAGE -I'/<XXX>/app/R40_Library/Boom/include' -DU_STATIC_IMPLEMENTATION   -fpic  -DU_STATIC_IMPLEMENTATION -g -O2 -c boom_spike_slab_init.cc -o boom_spike_slab_init.o
g++: error: R: No such file or directory
g++: error: Open: No such file or directory
g++: error: 4.0.2: No such file or directory
g++: error: The: No such file or directory
g++: error: enhanced: No such file or directory
g++: error: R: No such file or directory
g++: error: distribution: No such file or directory
g++: error: from: No such file or directory
g++: error: Microsoft: No such file or directory
g++: error: Microsoft: No such file or directory
g++: error: packages: No such file or directory
g++: error: Copyright: No such file or directory
g++: error: (C): No such file or directory
g++: error: 2020: No such file or directory
g++: error: Microsoft: No such file or directory
g++: error: Corporation: No such file or directory
g++: error: Using: No such file or directory
g++: error: the: No such file or directory
g++: error: Intel: No such file or directory
g++: error: MKL: No such file or directory
g++: error: for: No such file or directory
g++: error: parallel: No such file or directory
g++: error: mathematical: No such file or directory
g++: error: computing: No such file or directory
g++: error: (using: No such file or directory
g++: error: 8: No such file or directory
g++: error: cores).: No such file or directory
g++: error: Default: No such file or directory
g++: error: CRAN: No such file or directory
g++: error: mirror: No such file or directory
g++: error: snapshot: No such file or directory
g++: error: taken: No such file or directory
g++: error: on: No such file or directory
g++: error: 2020-07-16.: No such file or directory
g++: error: See:: No such file or directory
g++: error: https://mran.microsoft.com/.: No such file or directory
make: *** [/opt/microsoft/ropen/4.0.2/lib64/R/etc/Makeconf:166: boom_spike_slab_init.o] Error 1
ERROR: compilation failed for package ‘BoomSpikeSlab’
* removing ‘/<XXX>/app/R40_Library/BoomSpikeSlab’
Warning in install.packages :
  installation of package ‘/<XXX>/ds_tests/BoomSpikeSlab_1.2.3.tar.gz’ had non-zero exit status

Hint

When looking at g++ -std=gnu++11 call, I saw below two args.

-DNDEBUG -I`/opt/microsoft/ropen/4.0.2/lib64/R/bin/Rscript -e "cat(system.file(package='Boom'))"`/include
-DRLANGUAGE -I'/<XXX>/app/R40_Library/Boom/include

While the second one correctly finds the /Boom/include dir (that was created after Boom installation), the first arg fails to do so, I guess because it calls the system.file().

Odd thing is, if I run system.file() inside RStudio, it gives me the correct dir for Boom

> cat(system.file(package='Boom'))
/<XXX>/app/R40_Library/Boom

But if I run Rscript command (what -DNDEBUG is doing), it gives this output

$ /opt/microsoft/ropen/4.0.2/lib64/R/bin/Rscript -e "cat(system.file(package='Boom'))"
Microsoft R Open 4.0.2
The enhanced R distribution from Microsoft
Microsoft packages Copyright (C) 2020 Microsoft Corporation

Using the Intel MKL for parallel mathematical computing (using 8 cores).

Default CRAN mirror snapshot taken on 2020-07-16.
See: https://mran.microsoft.com/.

So I guess the issue is clear 😃

What I tried so far

I tried passing configure.vars explicitly to R CMD INSTALL as well as install.packages(), but both seem to not picking them up correctly and they both yelled at me with the above error.

I think I may be not doing it right, so reaching out for help!

myargs = c('/<XXX>/app/R40_Library/Boom/include', '/<XXX>/app/R40_Library/Boom/include')
names(myargs) = c('DNDEBUG','DRLANGUAGE')

install.packages(pkgs = "/<XXX>/ds_tests/BoomSpikeSlab_1.2.3.tar.gz",
                 lib = "/<XXX>/app/R40_Library",
                 repos = NULL,
                 type="source",
                 configure.vars = myargs,
                 configure.args = myargs
                 )

This is myargs

> typeof(myargs)
[1] "character"
> length(myargs)
[1] 2
> myargs
                                                                    DNDEBUG 
"/<XXX>/app/R40_Library/Boom/include" 
                                                                 DRLANGUAGE 
"/<XXX>/app/R40_Library/Boom/include"

Causal impact inconsistent performance

Running Causal Impact for the same timeserie on the same version of R (installed with the same conda environment) on two similar machines (i7-6700HQ with ubuntu 16.10 and gcc6 , i7-7700HQ with ubuntu 16.04 and gcc5) the elapsed time is ~3.5 seconds vs ~21 seconds. I tried to create several VM with ubuntu 17.04 and 17.10 using gcc6 and gcc7 but i couldn't get the same performance as the first machine. Do I need to install some special library on my machine to get the best from CI?

'GammaPrior not exported by namespace: Boom' Error

Hello,

I am attempting to load "CausalImpact" into my R environment and continue to get the error:
Error : object ‘GammaPrior’ is not exported by 'namespace:Boom'

Is there perhaps a package that I need to load prior to CausalImpact?

Thanks.

Annual seasonality takes too long to compute

I have a time series with daily observations from 2016-07-01 until today.
The data have both annual and day-of-the-week seasonality, but the annual component is way more important. When I try to model it by specifying nseasons = 365 parameter as shown below in the code, it takes over an hour to compute. Is this normal?

impact <- CausalImpact(SynthTS, pre.period, post.period, model.args = list(niter = 1000, nseasons = 365, season.duration = 1, dynamic.regression=FALSE))

Daily time series with zeros

I have an issue that I'm having trouble debugging, I'm not convinced its a bug, but thought that I should post it here anyway. I have a fair number (10+) of daily time series that I'm using as control series. Some of the time-series contain 0 entries when daily. When I run the model using daily time series I get the following error message:

> impact <- CausalImpact(
+   final_series, 
+   pre.period = first_last(pre_index),
+   post.period = first_last(post_index),
+   model.args = list(nseasons = 7),
+   alpha = .2
+ )
Error in data.frame(y.model, cum.y.model, point.pred, cum.pred) : 
  arguments imply differing number of rows: 979, 1459

I've tried dropping out control time series one by one without luck.

When I convert the same time series to weekly, most (but not all) of the zero entries are removed and the model runs without any problems.

I'm at a bit of a loss as to why this error is occurring. I'm using the latest version of the package.

> packageVersion("CausalImpact")
[1] ‘1.2.1’

multiple caampaign effects

Hi guys,

Would it be possible to estimate in one shot the overall and individual impact of multiple interventions directly in CausalImpact?
To give an example, I could be interested in estimating the effects of a set of multiple campaigns that took place for 2 months every 3 months in the last 2 years. I could estimate each intervention one by one, assuming independence between each other or controlling for the past interventions (like in issue #25?) and then aggregate the results.

Any suggestion?

Best wishes

Period marker only works with Date object

The plot function only plots the period marker if the time index is a Date object, and fails to plot for 'DateTime/POSIX index (e.g. 2017-02-02 03:00).

It seems concatenating a POSIX timestamp with NULL (e.g. https://github.com/google/CausalImpact/blob/master/R/impact_plot.R#L82) does not really work

> c(NULL,strptime('2017-02-02 03:00','%Y-%m-%d %H:00'))
$sec
[1] 0

$min
[1] 0

$hour
[1] 3

$mday
[1] 2

$mon
[1] 1

$year
[1] 117

$wday
[1] 4

$yday
[1] 32

$isdst
[1] 0

$zone
[1] "CET"

$gmtoff
[1] NA

whereas c(NULL,as.Date('2014-02-01')) returns the expected value.

error installing package

Hello hello,
I upgraded my base R to the latest version yesterday. I also re-installed the causal impact package with a bunch of other packages.

Now, when I run
library(CausalImpact)

I get the following error:

Warning: S3 methods ‘ToString.default’, ‘ToString.table’ were declared in NAMESPACE but not found
Error : object ‘GammaPrior’ is not exported by 'namespace:Boom'

Does anyone have a suggested solution for this? Thanks much in advance...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.