重回帰分析とステップワイズ・アルゴリズム

つぎに、同性間の性的関係についての意見を従属変数とし、上記の各説明変数を重回帰式に含め、重回帰分析を行なった。

Residuals:
     Min       1Q   Median       3Q      Max 
-2.06912 -0.72892  0.08554  0.63530  2.75270 

Coefficients:
             Estimate Std. Error t value Pr(>|t|)    
(Intercept)  2.897391   0.224361  12.914  < 2e-16 ***
x1          -0.053754   0.033328  -1.613   0.1069    
x2           0.192808   0.041730   4.620 4.11e-06 ***
x3          -0.254801   0.019074 -13.359  < 2e-16 ***
x4           0.024353   0.074464   0.327   0.7437    
x5           0.010937   0.028128   0.389   0.6974    
x6           0.027165   0.012968   2.095   0.0363 *  
x7          -0.116188   0.075446  -1.540   0.1237    
x8          -0.009874   0.013123  -0.752   0.4519    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 

Residual standard error: 0.8612 on 1753 degrees of freedom
Multiple R-Squared: 0.1889,     Adjusted R-squared: 0.1852 
F-statistic: 51.04 on 8 and 1753 DF,  p-value: < 2.2e-16 

有意なのは性別、年齢、教育年数である(上記Rの出力ではx2、x3、x6)。単回帰のときに有意だった居住地(x1)、婚姻経験(x4)、教育機関の旧制・新制(x7)、世帯収入(x8)の効果は消えている。おそらく婚姻経験、旧制・新制、世帯収入は年齢と関連し、世帯収入はさらに教育年数とも関連している。居住地は教育年数とおそらく関連するだろう。

【ここから下は注に落としたほうがいいかも。社会学でステップワイズってみたことないもんなあ。どうなんでしょ?】
ここでステップワイズ・アルゴリズムを使って、変数を削らない場合と変数を1つ削った場合の解析を全通り行い、各結果のAICを比較してみる。

> result2<-step(result)
Start:  AIC= -517.77 
 y ~ x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 

       Df Sum of Sq     RSS     AIC
- x4    1      0.08 1300.10 -519.67
- x5    1      0.11 1300.13 -519.62
- x8    1      0.42 1300.44 -519.21
<none>              1300.02 -517.77
- x7    1      1.76 1301.78 -517.39
- x1    1      1.93 1301.95 -517.16
- x6    1      3.25 1303.27 -515.37
- x2    1     15.83 1315.85 -498.45
- x3    1    132.34 1432.36 -348.96

Step:  AIC= -519.67 
 y ~ x1 + x2 + x3 + x5 + x6 + x7 + x8 

       Df Sum of Sq     RSS     AIC
- x5    1      0.12 1300.22 -521.51
- x8    1      0.48 1300.58 -521.02
<none>              1300.10 -519.67
- x7    1      1.88 1301.98 -519.11
- x1    1      1.97 1302.07 -519.00
- x6    1      3.28 1303.38 -517.22
- x2    1     15.76 1315.86 -500.44
- x3    1    154.17 1454.26 -324.21

Step:  AIC= -521.51 
 y ~ x1 + x2 + x3 + x6 + x7 + x8 

       Df Sum of Sq     RSS     AIC
- x8    1      0.65 1300.87 -522.62
<none>              1300.22 -521.51
- x7    1      1.83 1302.05 -521.02
- x1    1      1.96 1302.18 -520.85
- x6    1      3.17 1303.38 -519.22
- x2    1     15.65 1315.87 -502.42
- x3    1    155.98 1456.20 -323.87

Step:  AIC= -522.62 
 y ~ x1 + x2 + x3 + x6 + x7 

       Df Sum of Sq     RSS     AIC
<none>              1300.87 -522.62
- x1    1      1.97 1302.84 -521.95
- x7    1      2.31 1303.18 -521.50
- x6    1      2.62 1303.49 -521.08
- x2    1     15.93 1316.80 -503.18
- x3    1    157.02 1457.89 -323.83

> summary(result2)

Call:
lm(formula = y ~ x1 + x2 + x3 + x6 + x7)

Residuals:
    Min      1Q  Median      3Q     Max 
-2.0043 -0.7188  0.0856  0.6305  2.7536 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)  2.93339    0.17085  17.169  < 2e-16 ***
x1          -0.05426    0.03327  -1.631   0.1031    
x2           0.19206    0.04142   4.637  3.8e-06 ***
x3          -0.25827    0.01774 -14.559  < 2e-16 ***
x6           0.02292    0.01219   1.880   0.0602 .  
x7          -0.12975    0.07350  -1.765   0.0777 .  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 

Residual standard error: 0.8607 on 1756 degrees of freedom
Multiple R-Squared: 0.1884,     Adjusted R-squared: 0.1861 
F-statistic: 81.51 on 5 and 1756 DF,  p-value: < 2.2e-16 

説明変数のうち、婚姻経験、主観的階層、世帯収入を削った場合がAIC最小となる。最終的に残った変数は居住地、性別、年齢、教育年数、旧制・新制、の5変数であり、このうち性別と年齢が0.001水準で有意となる。

世帯収入、婚姻経験が削られたのは、年齢との関連性が高いからだと推察される。先の重回帰モデルでは教育年数も有意だったが、最終的なモデルでは有意ではない。これは、教育年数を点数化するにあたって、旧制の教育年数と新制の教育年数を区別せずにそのまま文字通り年数を点数化したため、年齢によって打ち消しあったためではないかと推察される*1(旧制のケースでは、グラフで見たように、教育年数が多いほど「非寛容」の傾向を示している)。したがって、ここでも年齢が強く関連していると考えるのが妥当ではないかと推察される。



関数step()のヘルプは以下:

step                  package:stats                  R Documentation

Choose a model by AIC in a Stepwise Algorithm

Description:

     Select a formula-based model by AIC.

Usage:

     step(object, scope, scale = 0,
          direction = c("both", "backward", "forward"), 
          trace = 1, keep = NULL, steps = 1000, k = 2, ...)

Arguments:

  object: an object representing a model of an appropriate class
          (mainly '"lm"' and '"glm"'). This is used as the initial
          model in the stepwise search. 

   scope: defines the range of models examined in the stepwise search.
          This should be either a single formula, or a list containing
          components 'upper' and 'lower', both formulae.  See the
          details for how to specify the formulae and how they are
          used. 

   scale: used in the definition of the AIC statistic for selecting the
          models, currently only for 'lm', 'aov' and 'glm' models. 

direction: the mode of stepwise search, can be one of '"both"',
          '"backward"', or '"forward"', with a default of '"both"'.  If
          the 'scope' argument is missing the default for 'direction'
          is '"backward"'. 

   trace: if positive, information is printed during the running of
          'step'. Larger values may give more detailed information. 

    keep: a filter function whose input is a fitted model object and
          the  associated 'AIC' statistic, and whose output is
          arbitrary.  Typically 'keep' will select a subset of the
          components of  the object and return them. The default is not
          to keep anything. 

   steps: the maximum number of steps to be considered.  The default is
          1000 (essentially as many as required).  It is typically used
          to stop the process early. 

       k: the multiple of the number of degrees of freedom used for the
          penalty. Only 'k = 2' gives the genuine AIC: 'k = log(n)' is
          sometimes referred to as BIC or SBC. 

     ...: any additional arguments to 'extractAIC'. 

Details:

     'step' uses 'add1' and 'drop1' repeatedly; it will work for any
     method for which they work, and that is determined by having a
     valid method for 'extractAIC'. When the additive constant can be
     chosen so that AIC is equal to Mallows' Cp, this is done and the
     tables are labelled appropriately.

     The set of models searched is determined by the 'scope' argument.
     The right-hand-side of its 'lower' component is always included in
     the model, and right-hand-side of the model is included in the
     'upper' component.  If 'scope' is a single formula, it specifes
     the 'upper' component, and the 'lower' model is empty.  If 'scope'
     is missing, the initial model is used as the 'upper' model.

     Models specified by 'scope' can be templates to update 'object' as
     used by 'update.formula'.  So using '.' in a 'scope' formula means
     'what is already there', with '.^2' indicating all interactions of
     existing terms.

     There is a potential problem in using 'glm' fits with a variable
     'scale', as in that case the deviance is not simply related to the
     maximized log-likelihood. The '"glm"' method for function
     'extractAIC' makes the appropriate adjustment for a 'gaussian'
     family, but may need to be amended for other cases. (The
     'binomial' and 'poisson' families have fixed 'scale' by default
     and do not correspond to a particular maximum-likelihood problem
     for variable 'scale'.)

Value:

     the stepwise-selected model is returned, with up to two additional
     components.  There is an '"anova"' component corresponding to the
     steps taken in the search, as well as a '"keep"' component if the
     'keep=' argument was supplied in the call. The '"Resid. Dev"'
     column of the analysis of deviance table refers to a constant
     minus twice the maximized log likelihood: it will be a deviance
     only in cases where a saturated model is well-defined (thus
     excluding 'lm', 'aov' and 'survreg' fits, for example).

Warning:

     The model fitting must apply the models to the same dataset. This
     may be a problem if there are missing values and R's default of
     'na.action = na.omit' is used.  We suggest you remove the missing
     values first.

Note:

     This function differs considerably from the function in S, which
     uses a number of approximations and does not compute the correct
     AIC.

     This is a minimal implementation. Use 'stepAIC' in package 'MASS'
     for a wider range of object classes.

Author(s):

     B. D. Ripley: 'step' is a slightly simplified version of 'stepAIC'
     in package 'MASS' (Venables & Ripley, 2002 and earlier editions).

     The idea of a 'step' function follows that described in Hastie &
     Pregibon (1992); but the implementation in R is more general.

References:

     Hastie, T. J. and Pregibon, D. (1992) _Generalized linear models._
     Chapter 6 of _Statistical Models in S_ eds J. M. Chambers and T.
     J. Hastie, Wadsworth & Brooks/Cole.

     Venables, W. N. and Ripley, B. D. (2002) _Modern Applied
     Statistics with S._ New York: Springer (4th ed).

See Also:

     'stepAIC' in 'MASS', 'add1', 'drop1'

Examples:

     example(lm)
     step(lm.D9)  

     summary(lm1 <- lm(Fertility ~ ., data = swiss))
     slm1 <- step(lm1)
     summary(slm1)
     slm1$anova

*1:なんか間違ってそう。