0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

プロビット回帰分析

Last updated at Posted at 2023-11-15

1.プロビット分析とは

プロビット分析とは、重回帰分析において被説明変数をダミー変数(0と1など)に置き換えることにより、被説明変数$Y$が1になる確率が他の説明変数$X$に影響されているかどうかを調べる手法である。

以下、$\Phi$を標準正規分布関数とする。
$$\Phi \left( x\right) =\int ^{x}_{-\infty }\dfrac{1}{\sqrt{2\pi }}e^{-\frac{1}{2}t^{2}}dt$$

プロビット回帰は 連結関数(リンク関数, link function) として$\Phi^{-1}$を用いた場合の一般化線形モデルの例である。

2.連結関数とは

通常、回帰モデルでは、予測変数と応答変数の間の関係を線形にすることが期待される。しかし、応答変数が線形ではなく、例えば0から1の範囲に制約されている場合や、指数的に増加する場合などがある。そのようなときに、リンク関数を使って、応答変数を予測変数の線形結合と関連付ける。

3.説明変数が一つの場合

$$P(Y = 1|X) = \Phi(β_0 + β_1X)$$

観測値$y_1, \cdots, y_n$が与えられた時の尤度関数は

$$L(β_0,β_1) = \prod^n_{i=1} \Phi(β_0 + β_1x_i)^{y_i}(1-\Phi(β_0 + β_1x_i))^{1-y_i}$$となる。ロジスティックスモデルの尤度関数も同様である。

4.説明変数が二つの場合

$$P(Y = 1|X_1,X_2) = \Phi(β_0 + β_1X_1 + β_2X_2)$$

5.コードの例

import numpy as np
import statsmodels.api as sm
import seaborn as sns
import matplotlib.pyplot as plt

# ダミーデータの生成
np.random.seed(42)
X = np.random.randn(100, 2)
# 係数
beta = np.array([0.5, -0.5])
# ノイズ項
epsilon = np.random.randn(100)
# 線形予測子
linear_predictor = X.dot(beta) + epsilon
# 応答変数の生成(0または1に変換)
y = (linear_predictor > 0).astype(int)

# プロビット回帰モデルの推定
X_with_intercept = sm.add_constant(X)  # 定数項を追加
probit_model = sm.Probit(y, X_with_intercept)
result = probit_model.fit()

# 結果の表示
print(result.summary())

# ダミーデータの可視化
plt.figure(figsize=(8, 6))
sns.scatterplot(x=X[:, 0], y=X[:, 1], hue=y, palette='viridis', marker='o', s=100, alpha=0.8)
plt.xlabel('Feature 1')
plt.ylabel('Feature 2')
plt.title('Dummy Data and True Decision Boundary')
plt.legend()
plt.show()

# モデルの予測
y_prob = result.predict(X_with_intercept)

# 予測された確率とデータの散布図
plt.figure(figsize=(8, 6))
sns.scatterplot(x=X[:, 0], y=X[:, 1], hue=y_prob, palette='viridis', marker='o', s=100, alpha=0.8)
plt.xlabel('Feature 1')
plt.ylabel('Feature 2')
plt.title('Predicted Probabilities and True Decision Boundary')
plt.legend()
plt.show()

image.png

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?