Categorical Data Analysis

author: Hiroki Matsui css: R_presentation.css date: 2015/1/21

はじめに

自己紹介

本日お話する内容

Categorical Outcome

Categorical Outcome の解析(単変量)

割合の比較

x col1 col2
row1 a b
row2 c d

95%信頼区間

x col1 col2
row1 a b
row2 c d

\(P_a = \frac{a}{a+b}\), \(P_c = \frac{c}{c+d}\)
- リスク差 (Rusk Difference) \[ RD = \hat{RD} \pm 1.96SE \] \[ SE = \sqrt{\frac{P_a(1-P_a)}{a+b}+\frac{P_c(1-P_c)}{c+d}} \] - リスク比 (Risk Ratio) \[ log(RR) = log(\hat{RR}) \pm 1.96SE \] \[ SE=\sqrt{\frac{1}{a} - \frac{1}{a+b} + \frac{1}{c} - \frac{1}{c+d}} \] - オッズ比 (Odds Ratio) \[ log(OR) = log(\hat{OR}) \pm 1.96SE \] \[ SE=\sqrt{\frac{1}{a} + \frac{1}{b} + \frac{1}{c} + \frac{1}{d}} \]

x <- matrix(c(14, 8, 4, 17), ncol=2, byrow=T)
chisq.test(x)
## 
##  Pearson's Chi-squared test with Yates' continuity correction
## 
## data:  x
## X-squared = 7.0406, df = 1, p-value = 0.007968
 fisher.test(x)
## 
##  Fisher's Exact Test for Count Data
## 
## data:  x
## p-value = 0.005089
## alternative hypothesis: true odds ratio is not equal to 1
## 95 percent confidence interval:
##   1.56789 39.54979
## sample estimates:
## odds ratio 
##   7.051895

オッズ比の解釈
- 基準値1
- 臨床的解釈
- Number Needed to Treat(NNT)

\[NNT = \frac{1}{RD} = \frac{1}{EER - UER}\]
\[= \frac{1}{(OR-1)\times UER} + \frac{OR}{(OR-1)\times(1-UER)}\]
\[EER:Exposed Event Propotion, UER:Unexposed Event Propotion\]

普通の多変量回帰が困難な理由

多変量回帰(一般線形モデル) \[ Y = \beta_0 + \beta_1x_1 + \eta \] \[ Y = \{y|0,1\} \]

summary(lm(y~x_1))
## 
## Call:
## lm(formula = y ~ x_1)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.68033 -0.18708 -0.00144  0.19549  0.61015 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 0.506686   0.008331   60.82   <2e-16 ***
## x_1         0.074887   0.001467   51.04   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.2634 on 998 degrees of freedom
## Multiple R-squared:  0.723,  Adjusted R-squared:  0.7227 
## F-statistic:  2605 on 1 and 998 DF,  p-value: < 2.2e-16

logistic regression

Logistic Function からLogistic regression へ

Logistic regression とOdds Ratio - \(P=f(z)=\frac{1}{1+e^{-z}}\)をzについて解く \(z = log(\frac{p}{1-p})\) - \(\frac{p}{1-p}\) はOddsをあらわす。

logistic regression の使いどころ

Logistic regression には大きく2つの使いどころがある。 - 因果推論モデル - 予測モデル この二つは、似ているようで注意すべき点が異なる。
そのため自分がどちらの使い方をしているのか意識しておく必要がある。

因果推論モデル

予測モデル - 従属変数を所与として、それぞれの症例のアウトカムが生じる確率を知りたい。 - 見たいパラメータ: \(P\)
例えば
- リウマチ症例において、症状が寛解するかどうかを各種予後因子から予測したい。

logistic regression の実施

train_data <- read.csv("http://www.ats.ucla.edu/stat/data/binary.csv")
summary(train_data)
##      admit             gre             gpa             rank      
##  Min.   :0.0000   Min.   :220.0   Min.   :2.260   Min.   :1.000  
##  1st Qu.:0.0000   1st Qu.:520.0   1st Qu.:3.130   1st Qu.:2.000  
##  Median :0.0000   Median :580.0   Median :3.395   Median :2.000  
##  Mean   :0.3175   Mean   :587.7   Mean   :3.390   Mean   :2.485  
##  3rd Qu.:1.0000   3rd Qu.:660.0   3rd Qu.:3.670   3rd Qu.:3.000  
##  Max.   :1.0000   Max.   :800.0   Max.   :4.000   Max.   :4.000
## 
## Call:
## glm(formula = admit ~ gre + gpa + rank, family = "binomial", 
##     data = train_data)
## 
## Deviance Residuals: 
##     Min       1Q   Median       3Q      Max  
## -1.6268  -0.8662  -0.6388   1.1490   2.0790  
## 
## Coefficients:
##              Estimate Std. Error z value Pr(>|z|)    
## (Intercept) -3.989979   1.139951  -3.500 0.000465 ***
## gre          0.002264   0.001094   2.070 0.038465 *  
## gpa          0.804038   0.331819   2.423 0.015388 *  
## rank2       -0.675443   0.316490  -2.134 0.032829 *  
## rank3       -1.340204   0.345306  -3.881 0.000104 ***
## rank4       -1.551464   0.417832  -3.713 0.000205 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 499.98  on 399  degrees of freedom
## Residual deviance: 458.52  on 394  degrees of freedom
## AIC: 470.52
## 
## Number of Fisher Scoring iterations: 4

logistic regression の実施に伴う諸注意

Logistic Regression はコマンド一つで簡単に実施できる。
しかし、注意しておくべき点がいくつかある。

Sufficient events per independent variable

イベント数が極めて少ない場合等で、\(\beta\)の推計値が極めて不安定になる。

Sex=1 Treat=0 Treat=1 Treat=2
death=0 123 246 150
death=1 5 0 10

対応 - まずは、クロス表で確認しそのうえでモデルを組む。 - 変数の統合(Factor=0とFactor=1を統合) - Propensity Score による解析に切り替える。

Conformity with linear gradient for continuous variables(共変量の線型性)

独立変数が連続変数の場合、従属変数との関係は線形であることを仮定している。

例えば、上記の場合推計した\(\beta\)はOutcome に対する因子の効果を正しく推計していない。
確認 - まずは、関係性をグラフを書いてチェック - 共変量をカテゴリー化してモデルに投入 オッズ比は線形になっているか?

対応 - 共変量をカテゴリー化してモデルに投入しOdds比を報告 - スプライン関数や多項式回帰を用いて変数を変換する。

Tests for interactions(交互作用項)

交互作用:変数の組み合わせでOutcome との関連が異なる変数があるかどうか。
例えば

交互作用項は二つの変数の積であらわされる。 \[logit(p) = \beta_0 + \beta_1 x_1 + \beta_2 x_2 +\beta_3 x_1*x_2\]

交互作用の解釈 \[logit(p) = \beta_0 + \beta_1 x_1 + \beta_2 x_2 +\beta_3 x_1*x_2\]

Collinearity(多重共線性)

変数間の相関があまりに強いと\(\beta\) の推計値が安定しなくなる。予測値にはあまり影響しない。

確認

## stat_bin: binwidth defaulted to range/30. Use 'binwidth = x' to adjust this.
## stat_bin: binwidth defaulted to range/30. Use 'binwidth = x' to adjust this.
## stat_bin: binwidth defaulted to range/30. Use 'binwidth = x' to adjust this.
## stat_bin: binwidth defaulted to range/30. Use 'binwidth = x' to adjust this.
## stat_bin: binwidth defaulted to range/30. Use 'binwidth = x' to adjust this.
## stat_bin: binwidth defaulted to range/30. Use 'binwidth = x' to adjust this.
## stat_bin: binwidth defaulted to range/30. Use 'binwidth = x' to adjust this.
## stat_bin: binwidth defaulted to range/30. Use 'binwidth = x' to adjust this.
## stat_bin: binwidth defaulted to range/30. Use 'binwidth = x' to adjust this.
## stat_bin: binwidth defaulted to range/30. Use 'binwidth = x' to adjust this.
## stat_bin: binwidth defaulted to range/30. Use 'binwidth = x' to adjust this.
## stat_bin: binwidth defaulted to range/30. Use 'binwidth = x' to adjust this.

Collinearity(多重共線性)

対応

Goodness-of-fit, Discrimination measures(適合度)

モデルがそのデータをどの程度うまく表しているか?

等。AUC を求めるのが一般的。

Validation(妥当性の検証)

因果推論モデル

過剰適合

予測モデル作成時はさらに以下を確認する。
モデルの内的妥当性および、外的妥当性を検証する。
内的妥当性 今回作成したモデルが過剰にデータにフィットしていないか確認する。

等による予測精度の確認。
外的妥当性 今回作成したモデルが他のデータにフィットしているか確認する。

適合度を確認する。

Statistical significance(統計学的有意性)

logistic regression の報告に伴う諸注意

さらに、報告する際には以下を明記する。

Selection of independent variables(変数選択)

今まで存在する知見などから、全ての共変量を網羅する。

Coding of variables(主としてReferenceの設定)

Odds Ratio はReferenceとの関連で表される。

Fitting procedure(モデル構築)

本日お話する内容

【追加内容】クラスターデータでの解析

個々の測定がクラスター単位で似通ってくる。

対応

【追加内容】オッズ比を報告する場合のOmitted variable

リンク先のDAGにおいて調整すべき因子は何か?

参考資料