一般線形モデル(重回帰や分散分析など)の関数lm()が返す結果に関数summary()を適用したものの中味

2008.6.22(2008.5.9より)

 一般線形モデル(正規線形モデル、つまり、重回帰や分散分析や共分散分析の大部分)を扱う、Rの関数lm()が返してくる、オブジェクトに、関数summary()を適用した結果のオブジェクトの中味に関するメモです。lm()の結果に適用しているので、summary.lm()を適用していることになります。

 使用データや結果オブジェクト名は、関数lm()が返してくる結果オブジェクトのメモと同じです。関数lm()の結果はres1に入っています。

 結果のオブジェクトres1にsummary()を適用して(繰り返しますがsummary.lm()を適用していることになります)得られるオブジェクトの中味は以下の通りです。


List of 11
$ call : language lm(formula = y1 ~ x1)
$ terms :Classes 'terms', 'formula' length 3 y1 ~ x1
.. ..- attr(*, "variables")= language list(y1, x1)
.. ..- attr(*, "factors")= int [1:2, 1] 0 1
.. .. ..- attr(*, "dimnames")=List of 2
.. .. .. ..$ : chr [1:2] "y1" "x1"
.. .. .. ..$ : chr "x1"
.. ..- attr(*, "term.labels")= chr "x1"
.. ..- attr(*, "order")= int 1
.. ..- attr(*, "intercept")= int 1
.. ..- attr(*, "response")= int 1
.. ..- attr(*, ".Environment")=<R_GlobalEnv>
.. ..- attr(*, "predvars")= language list(y1, x1)
.. ..- attr(*, "dataClasses")= Named chr [1:2] "numeric" "numeric"
.. .. ..- attr(*, "names")= chr [1:2] "y1" "x1"
$ residuals : Named num [1:12] -0.965 -0.462 1.279 -1.120 0.518 ...
..- attr(*, "names")= chr [1:12] "1" "2" "3" "4" ...
$ coefficients : num [1:2, 1:4] 0.0412 0.5373 0.2525 0.2549 0.1632 ...
..- attr(*, "dimnames")=List of 2
.. ..$ : chr [1:2] "(Intercept)" "x1"
.. ..$ : chr [1:4] "Estimate" "Std. Error" "t value" "Pr(>|t|)"
$ aliased : Named logi [1:2] FALSE FALSE
..- attr(*, "names")= chr [1:2] "(Intercept)" "x1"
$ sigma : num 0.872
$ df : int [1:3] 2 10 2
$ r.squared : num 0.308
$ adj.r.squared: num 0.238
$ fstatistic : Named num [1:3] 4.44 1.00 10.00
..- attr(*, "names")= chr [1:3] "value" "numdf" "dendf"
$ cov.unscaled : num [1:2, 1:2] 0.08375 -0.00598 -0.00598 0.08536
..- attr(*, "dimnames")=List of 2
.. ..$ : chr [1:2] "(Intercept)" "x1"
.. ..$ : chr [1:2] "(Intercept)" "x1"
- attr(*, "class")= chr "summary.lm"

List of 11とは以下の11個です。

$ call
$ terms
$ residuals
$ coefficients
$ aliased
$ sigma
$ df
$ r.squared
$ adj.r.squared
$ fstatistic
$ cov.unscaled

summary(res1)で返される結果は以下の通りです。

> summary(res1)

Call:
lm(formula = y1 ~ x1)

Residuals:
Min 1Q Median 3Q Max
-1.11978 -0.73665 0.01523 0.61852 1.27939

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.04119 0.25246 0.163 0.8736
x1 0.53730 0.25488 2.108 0.0612 .
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 0.8724 on 10 degrees of freedom
Multiple R-Squared: 0.3077, Adjusted R-squared: 0.2384
F-statistic: 4.444 on 1 and 10 DF, p-value: 0.06124


以下、lm()の結果のオブジェクト(ここの例ではres1)とは異なる部分を見ていきます。

$ call
$ terms
$ residuals
はres1と同じです。


$ r.squaredは相関係数rの二乗つまり決定係数です。

$ adj.r.squaredは自由度調整済み重相関係数の二乗です


$ coefficientsは回帰係数(傾きや切片など)と標準誤差、t統計量の値、t検定したときの有意確率です。

> summary(res1)$coefficients

Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.04119304 0.2524642 0.1631639 0.87363965
x1 0.53730014 0.2548766 2.1080797 0.06123965

> class(summary(res1)$coefficients)

[1] "matrix"

> summary(res1)$coefficients["x1","Estimate"]

[1] 0.5373001


$ fstatisticは、説明変数の効果についてのF検定の、Fの値と自由度です。3つの数値の最初が Fの値で、後の2つが自由度です。