プライマリ・コンテンツに移動
Oracle® R Enterpriseユーザーズ・ガイド
リリース1.5
E67082-02
目次へ移動
目次
索引へ移動
索引

前
前へ
次
次へ

4.2.5 一般化線形モデルの構築

ore.odmGLM関数は一般化線形モデル(GLM)を構築しますが、これは線形モデル(線形回帰)のクラスを含み、このクラスを拡張したものです。一般化線形モデルは、実際には違反されることが多い線形モデルの制限を緩和したものです。たとえば、2値(yes/noまたは0/1)応答は、クラス間で同じ分散を持ちません。

Oracle Data MiningのGLMはパラメトリック・モデリング手法です。パラメトリック・モデルでは、データの分散を仮定します。仮定が満たされる場合、パラメトリック・モデルはノンパラメトリック・モデルよりも効率的になります。

このタイプのモデルの作成では、どの程度仮定が満たされるかを見極めることが課題となります。このため、良質なパラメトリック・モデルを作成するには質の診断が重要です。

古典的な、線形回帰における重み付き最小二乗推定およびロジスティック回帰における反復再重み付き最小二乗推定(いずれもコレスキー分解およびマトリクス反転を使用する解決)に加えて、Oracle Data MiningのGLMでは、マトリクス反転が不要で高次元データに最適な共役勾配法に基づく最適化アルゴリズムを提供します。アルゴリズムの選択は内部的に処理され、ユーザーに対して透過的です。

GLMを使用して、次のような分類モデルまたは回帰モデルを構築できます。

  • 分類: 2項ロジスティック回帰は、GLM分類アルゴリズムです。このアルゴリズムでは、ロジット・リンク関数および2項分散関数を使用します。

  • 回帰: 線形回帰は、GLM回帰アルゴリズムです。このアルゴリズムでは、ターゲット値の範囲に対する一定分散およびターゲット変換を想定していません。

ore.odmGLM関数では、2つの異なるタイプのモデルを構築できます。一部、分類モデルにのみ適用される引数、回帰モデルにのみ適用される引数があります。

ore.odmGLM関数の引数の詳細は、help(ore.odmGLM)を呼び出してください。

次の例では、GLMを使用していくつかのモデルを構築します。入力ore.frameオブジェクトは、データベースにプッシュされるRデータセットです。

例4-11 線形回帰モデルの構築

この例では、longleyデータセットを使用して線形回帰モデルを構築します。

longley_of <- ore.push(longley)
longfit1 <- ore.odmGLM(Employed ~ ., data = longley_of)
summary(longfit1)
例4-11のリスト
R> longley_of <- ore.push(longley)
R> longfit1 <- ore.odmGLM(Employed ~ ., data = longley_of)
R> summary(longfit1)
 
Call:
ore.odmGLM(formula = Employed ~ ., data = longely_of)
 
Residuals:
     Min       1Q   Median       3Q      Max 
-0.41011 -0.15767 -0.02816  0.10155  0.45539 
 
Coefficients:
               Estimate Std. Error t value Pr(>|t|)    
(Intercept)  -3.482e+03  8.904e+02  -3.911 0.003560 ** 
GNP.deflator  1.506e-02  8.492e-02   0.177 0.863141    
GNP          -3.582e-02  3.349e-02  -1.070 0.312681    
Unemployed   -2.020e-02  4.884e-03  -4.136 0.002535 ** 
Armed.Forces -1.033e-02  2.143e-03  -4.822 0.000944 ***
Population   -5.110e-02  2.261e-01  -0.226 0.826212    
Year          1.829e+00  4.555e-01   4.016 0.003037 ** 
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
 
Residual standard error: 0.3049 on 9 degrees of freedom
Multiple R-squared:  0.9955,    Adjusted R-squared:  0.9925 
F-statistic: 330.3 on 6 and 9 DF,  p-value: 4.984e-10

例4-12 ore.odmGLMモデルの係数に対するリッジ推定の使用方法

この例では、例4-11longley_ofore.frameを使用します。例4-12では、ore.odmGLM関数を呼び出し、係数のリッジ推定を使用して指定します。

longfit2 <- ore.odmGLM(Employed ~ ., data = longley_of, ridge = TRUE,
                       ridge.vif = TRUE)
summary(longfit2)
例4-12のリスト
R> longfit2 <- ore.odmGLM(Employed ~ ., data = longley_of, ridge = TRUE,
+                         ridge.vif = TRUE)
R> summary(longfit2)
 
Call:
ore.odmGLM(formula = Employed ~ ., data = longley_of, ridge = TRUE, 
    ridge.vif = TRUE)
 
Residuals:
    Min      1Q  Median      3Q     Max 
-0.4100 -0.1579 -0.0271  0.1017  0.4575 
 
Coefficients:
               Estimate   VIF
(Intercept)  -3.466e+03 0.000
GNP.deflator  1.479e-02 0.077
GNP          -3.535e-02 0.012
Unemployed   -2.013e-02 0.000
Armed.Forces -1.031e-02 0.000
Population   -5.262e-02 0.548
Year          1.821e+00 2.212
 
Residual standard error: 0.3049 on 9 degrees of freedom
Multiple R-squared:  0.9955,    Adjusted R-squared:  0.9925 
F-statistic: 330.2 on 6 and 9 DF,  p-value: 4.986e-10

例4-13 ロジスティック回帰GLMの構築

この例では、ロジスティック回帰(分類)モデルを構築します。ここでは、infertデータセットを使用します。この例では、ore.odmGLM関数を呼び出し、logistictype引数(二項分布GLMを構築します)として指定します。

infert_of <- ore.push(infert)
infit1 <- ore.odmGLM(case ~ age+parity+education+spontaneous+induced,
                     data = infert_of, type = "logistic")
infit1
例4-13のリスト
R> infert_of <- ore.push(infert)
R> infit1 <- ore.odmGLM(case ~ age+parity+education+spontaneous+induced,
+                       data = infert_of, type = "logistic")
R> infit1
 
Response:
case == "1"
 
Call:  ore.odmGLM(formula = case ~ age + parity + education + spontaneous + 
    induced, data = infert_of, type = "logistic")
 
Coefficients:
     (Intercept)               age            parity   education0-5yrs  education12+ yrs       spontaneous           induced  
        -2.19348           0.03958          -0.82828           1.04424          -0.35896           2.04590           1.28876  
 
Degrees of Freedom: 247 Total (i.e. Null);  241 Residual
Null Deviance:      316.2 
Residual Deviance: 257.8        AIC: 271.8

例4-14 ロジスティック回帰GLMの構築での参照値の指定

この例では、ロジスティック回帰(分類)モデルを構築し、参照値を指定します。この例では、例4-13infert_ofore.frameを使用します。

infit2 <- ore.odmGLM(case ~ age+parity+education+spontaneous+induced,
                     data = infert_of, type = "logistic", reference = 1)
infit2
例4-14のリスト
infit2 <- ore.odmGLM(case ~ age+parity+education+spontaneous+induced,
                     data = infert_of, type = "logistic", reference = 1)
infit2

Response:
case == "0"
 
Call:  ore.odmGLM(formula = case ~ age + parity + education + spontaneous + 
    induced, data = infert_of, type = "logistic", reference = 1)
 
Coefficients:
     (Intercept)               age            parity   education0-5yrs  education12+ yrs       spontaneous           induced  
         2.19348          -0.03958           0.82828          -1.04424           0.35896          -2.04590          -1.28876  
 
Degrees of Freedom: 247 Total (i.e. Null);  241 Residual
Null Deviance:      316.2 
Residual Deviance: 257.8        AIC: 271.8