# Introduction to Effectiveness Verification Chapters 4 and 5 are written in Python

# Introduction

Introduction to Effectiveness Verification-Causal Reasoning for Correct Comparison / Basics of Econometrics Reproduce the source code in Python To do.

I already have a Great ancestor implementation example, but I will leave it as a memo for my study.

This article describes Chapters 4 and 5.
The code is also posted on github.
In addition, variable names and processing contents are basically implemented in the book.

CausalImpact

Here, it is implemented using pycausal impact.
The result does not match the R version, but this seems to be because the method handled is different as described in the README.
It seems that you can specify the state space model with the argument `model`

, but I gave up because it seems to be difficult to match the implementation with the R version.

`CausalImpact`

```
from causalimpact import CausalImpact
impact = CausalImpact(CI_data, pre_period, post_period, prior_level_sd=None)
impact.plot()
print(impact.summary())
```

RDD
Non-linear regression analysis can be performed by learning the following model and referring to the effect size of the intervention variable.

Y = \beta_0 + \beta_1 f_1(X-c) + \beta_2 f_2(X-c) + \rho Z + \epsilon
`RDD`

```
from sklearn.preprocessing import PolynomialFeatures
degree = 4
X = nonlinear_rdd_data[['history_log']]
X = X - cutpoint
X_poly = PolynomialFeatures(degree=degree, include_bias=False).fit_transform(X)
X_poly = pd.DataFrame(X_poly, columns=[f'X{i+1}' for i in range(X_poly.shape[1])])
nonlinear_rdd_data = pd.concat([nonlinear_rdd_data, X_poly], axis=1)
nonlinear_rdd_ord4 = ols('visit ~ treatment + X1 + X2 + X3 + X4 + treatment:X1 + treatment:X2 + treatment:X3 + treatment:X4', data=nonlinear_rdd_data).fit()
```

# Relation

-I wrote "Introduction to Effect Verification" in Python