DMLパッケージで試してみる

DMLパッケージで試してみる#

Partially Linear Regression Model#

Y=Dθ0+g0(X)+ζ,E(ζ|D,X)=0,D=m0(X)+V,E(V|X)=0,

doubleml.DoubleMLPLR — DoubleML documentation

class doubleml.DoubleMLPLR(obj_dml_data, ml_l, ml_m, ml_g=None, n_folds=5, n_rep=1, score='partialling out', draw_sample_splitting=True)

nuisance functions

  • ml_l0(X)=E[Y|X]

  • ml_mm0(X)=E[D|X]

  • ml_gg0(X)=E[YDθ0|X]で、scoreが'IV-type'のときのみ使われる

デフォルトのscoreが'partialling out'で、これはRobinson (1988)の

ψ(W;θ,η):={Y(X)θ(Dm(X))}(Dm(X)),η=(,m)

というタイプのスコア関数であり、推定量としては

YE[Y|X]0(X)=θ0(DE[D|X]m0(X))+U

という、残差回帰タイプの推定量をもたらす。

import numpy as np
import doubleml as dml
from doubleml.datasets import make_plr_CCDDHNR2018
from sklearn.ensemble import RandomForestRegressor
from sklearn.base import clone
np.random.seed(0)
learner = RandomForestRegressor(n_estimators=100, max_features=20, max_depth=5, min_samples_leaf=2, random_state=0)
ml_g = learner
ml_m = learner
obj_dml_data = make_plr_CCDDHNR2018(alpha=0.5, n_obs=500, dim_x=20)
dml_plr_obj = dml.DoubleMLPLR(obj_dml_data, ml_g, ml_m)
dml_plr_obj.fit().summary
/usr/local/lib/python3.10/site-packages/sklearn/utils/deprecation.py:151: FutureWarning: 'force_all_finite' was renamed to 'ensure_all_finite' in 1.6 and will be removed in 1.8.
  warnings.warn(
/usr/local/lib/python3.10/site-packages/sklearn/utils/deprecation.py:151: FutureWarning: 'force_all_finite' was renamed to 'ensure_all_finite' in 1.6 and will be removed in 1.8.
  warnings.warn(
coef std err t P>|t| 2.5 % 97.5 %
d 0.438602 0.048179 9.10358 8.740236e-20 0.344173 0.533032

doubleml-for-py/doubleml/plm/plr.py at main · DoubleML/doubleml-for-py