Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

条件付き期待値関数(CEF)

CEFの性質

CEF分解の性質

従属変数yiy_iK×1K \times 1の説明変数ベクトルXi=(xi1,,xik)X_i = (x_{i1}, \dots, x_{ik})を扱うこととする。

証明
  1. E[eX]=E[yE(yX)X]=E[yX]E[yX]=0E[e|X]=E[y-E(y|X)|X]=E[y|X] - E[y|X] = 0

  2. h(X)h(X)XXの任意の関数とする。繰り返し期待値の法則Ex[E[YX]]=E[Y]E_x[E[Y|X]]=E[Y]よりE[h(X)e]=E[h(X)E[eX]]E[h(X)e]=E[h(X) E[e|X]]で、平均独立E[eX]=0E[e|X]=0よりE[h(X)e]=0E[h(X)e]=0

二乗誤差における最良の回帰関数

証明
(yim(Xi))2= ((yiE[yiXi])+(E[yiXi]m(Xi)))2= (yiE[yiXi])2+2(E[yiXi]m(Xi))×(yiE[yiXi])+(E([yiXi])m(Xi))2\begin{aligned} (y_i-m(X_i))^2 = ~& ((y_i-E[y_i \mid X_i])+(E[y_i \mid X_i]-m(X_i)))^2 \\ = ~& (y_i-E[y_i \mid X_i])^2\\ & + 2(E[y_i \mid X_i]-m(X_i)) \times (y_i-E[y_i \mid X_i]) \\ & + (E([y_i \mid X_i])-m(X_i))^2 \end{aligned}

第1項はm(X)m(X)が含まれないため最小化とは関係ない。

第2項は(yiE[yiXi])=ei(y_i-E[y_i \mid X_i]) = e_iなので二乗誤差(yim(Xi))2(y_i-m(X_i))^2の期待値をとると0になる

なので第3項だけが残り、そのうちのE([yiXi])m(Xi)E([y_i \mid X_i])-m(X_i)をゼロにするのはm(Xi)=E([yiXi])m(X_i) = E([y_i \mid X_i])のとき。

FWL定理

import numpy as np
import matplotlib.pyplot as plt

np.random.seed(0)
true_beta = np.array([3, 5, 7])
d = len(true_beta)
n = 100
X = np.random.uniform(size=n * d).reshape(-1, d)
y = X @ true_beta + np.random.normal(size=n)
class OLS:
    def fit(self, X, y):
        self.beta_ = np.linalg.inv(X.T @ X) @ X.T @ y
        return self

    def predict(self, X):
        return X @ self.beta_

model = OLS()
model.fit(X, y)
model.beta_
array([2.56721661, 4.94832955, 7.22025893])

xjx_jをそれ以外の説明変数に回帰し

xj=γ0+γ1x1++γj1xj1+γj+1xj+1++γdxd+x~jx_j = \gamma_0 + \gamma_1 x_1 + \cdots + \gamma_{j-1} x_{j-1} + \gamma_{j+1} x_{j+1} + \cdots + \gamma_d x_d + \tilde{x}_j

その残差x~j\tilde{x}_jを使って

βj=Cov(Y,x~j)Var(x~j)\beta_j = \frac {Cov(Y, \tilde{x}_j)} {Var(\tilde{x}_j)}

のようにβj\beta_jを推定することができる

model.fit(X[:, 1:3], X[:, 0])
model.beta_
array([0.35005087, 0.53528288])
residual = X[:, 0] - model.predict(X[:, 1:3])
residual
array([-0.02418807, 0.05084639, -0.39041088, -0.17681092, 0.20601426, -0.36563531, -0.0502294 , 0.21981341, -0.18246505, 0.54003402, -0.25063503, 0.23124686, -0.10903475, 0.32203852, 0.31964041, 0.52798123, -0.11710549, 0.03799755, -0.19718749, -0.04077773, -0.23098932, -0.12800315, 0.33846528, -0.49657305, 0.36931925, -0.12414819, 0.0843685 , 0.02113964, 0.19361591, -0.60510641, 0.01439223, 0.51696115, 0.13575687, -0.37710544, 0.26522578, 0.06259589, -0.34976755, 0.44234243, 0.20336118, -0.09807966, 0.03799004, 0.17102746, -0.43975292, -0.15577178, -0.27403238, 0.04018249, 0.02117883, -0.26244433, 0.50614744, 0.13479612, -0.24141967, 0.11829199, 0.3901465 , -0.41774219, -0.10340225, 0.65901272, 0.39100947, -0.02558537, 0.53045183, 0.66445758, -0.36183548, -0.41777507, -0.06168752, 0.0602216 , -0.54025425, 0.27469945, -0.26093776, 0.46797235, -0.36252938, -0.21410597, 0.55947956, -0.14985363, -0.1291308 , 0.14375786, -0.1051827 , 0.59677821, 0.55560326, 0.01817855, -0.14147823, 0.05229564, 0.5457693 , -0.33087323, 0.42372952, -0.13982339, 0.0195092 , -0.42273305, 0.73075836, -0.40301839, 0.24426778, 0.30407443, 0.48966302, 0.37230869, 0.32414815, 0.31729101, 0.42737496, -0.45161281, 0.07624642, -0.2525051 , 0.38042213, 0.00730186])
np.cov(y, residual)[1, 0] / np.var(residual)
-1.0835887765493208