Help us understand the problem. What is going on with this article?

# はじめに

この記事では、4・5章について記載します。
コードは、githubにも掲載しています。
なお、変数名や処理内容は、基本的に書籍内に寄せて実装します。

# CausalImpact

ここでは、pycausalimpactを使って実装する。

CausalImpact
from causalimpact import CausalImpact

impact = CausalImpact(CI_data, pre_period, post_period, prior_level_sd=None)

impact.plot()
print(impact.summary())

# RDD

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

# 関連

データ分析コンサルタント
Why not register and get more from Qiita?
1. We will deliver articles that match you
By following users and tags, you can catch up information on technical fields that you are interested in as a whole
2. you can read useful information later efficiently
By "stocking" the articles you like, you can search right away