1

I came across pycausalimpact recently.

https://pypi.org/project/pycausalimpact/

import numpy as np
import pandas as pd
from statsmodels.tsa.arima_process import ArmaProcess
from causalimpact import CausalImpact


np.random.seed(12345)
ar = np.r_[1, 0.9]
ma = np.array([1])
arma_process = ArmaProcess(ar, ma)
X = 100 + arma_process.generate_sample(nsample=100)
y = 1.2 * X + np.random.normal(size=100)
y[70:] += 5

data = pd.DataFrame({'y': y, 'X': X}, columns=['y', 'X'])
pre_period = [0, 69]
post_period = [70, 99]

ci = CausalImpact(data, pre_period, post_period)
print(ci.summary())
print(ci.summary(output='report'))
ci.plot()

That generic code works fine in the given example. Now, I am trying to run my own data in that pycausalimpact example, as shown below.

import sys
import os
import numpy as np
import pandas as pd
from IPython.core.pylabtools import figsize
import statsmodels as sm
from statsmodels.tsa.statespace.structural import UnobservedComponents
from statsmodels.tsa.arima_process import ArmaProcess
from matplotlib import pyplot as plt
from causalimpact import CausalImpact
import warnings

y = fus['days']
X = fus[['market_cat',
               'mmepool_cat',
               'submarket_cat',
               'local_market_cat',
               'project_type_cat',
               'site_status_cat',
               'city_cat',
               'state_cat']]

The part that I am struggling with is here:

ci = CausalImpact(data, pre_period, post_period)
print(ci.summary())
print(ci.summary(output='report'))
ci.plot()

How do I need to prepare the 'data', the 'pre_period', and the 'post_period', to work in my specific data set? Here is some of my actual data.

y =

enter image description here

X =

enter image description here

Basically, I want to see if there is any kind of causation effect between the independent variables and the dependent variable (days). Or...is there a better/alternative way to determine and measure causation?

halfer
  • 19,824
  • 17
  • 99
  • 186
ASH
  • 20,759
  • 19
  • 87
  • 200

0 Answers0