LoginSignup
0
0

More than 1 year has passed since last update.

単回帰,相関分析,分散分析は結果的には同じだよ

Posted at

重回帰分析

なぜ,重回帰分析についての記事が何回も何回も掲載されるのか。それも,重回帰分析すらでなくて単回帰(直線回帰)分析。しかも,不十分な記事が。

重回帰分析の導出なんて,誰が何回やっても同じなんだから,それを個別に何回も何回も記述しても,意味ないじゃん。数式を一杯書いたらすごそうに見える?

その割には,注意すべき点についてちゃんと記述できている記事も少ないし。

単回帰分析は重回帰分析のもっとも単純な場合なので,以下のように。

プラットフォームはいろいろあるが,R なら,

options(digits=16)
x = c(2,1,3,4,5,5,4)
y = c(2,3,4,2,2,3,1)
lm.1 = lm(y ~ x)
lm.2 = summary(lm.1)
# 直線回帰の結果の表示
# Coefficients の x の行の最終欄 Pr(>|t|) が,偏回帰係数(slope) H0: slope ≡ 0 の有意性検定
# 最終行の F-statistic の行の p-value が,回帰の分散分析の F 値に対する p 値
# 2つの p 値は同じである
print(lm.2)
Call:
lm(formula = y ~ x)

Residuals:
               1                2                3                4 
-0.6666666666667  0.1666666666667  1.5000000000000 -0.3333333333333 
               5                6                7 
-0.1666666666667  0.8333333333333 -1.3333333333333 

Coefficients:
                    Estimate       Std. Error  t value Pr(>|t|)  
(Intercept)  3.0000000000000  1.0327955589886  2.90474 0.033605 *
x           -0.1666666666667  0.2788866755114 -0.59761 0.576132  
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 1.032795558989 on 5 degrees of freedom
Multiple R-squared:  0.06666666666667,  Adjusted R-squared:           -0.12 
F-statistic: 0.3571428571429 on 1 and 5 DF,  p-value: 0.5761317257177
# Multiple R-squared 重相関係数は,従属変数と独立変数の間の相関係数の 2 乗だ(直線回帰の場合,Adjusted R-squared はほとんど意味がない)
cor(x, y)^2
0.0666666666666667
# 直線回帰の場合の slope の有意性検定の p 値は以下の通り
cat("AGAIN: partial regression coefficient for x\n")
print(lm.2$coefficients[2,4])
AGAIN: partial regression coefficient for x
[1] 0.5761317257177403
# 従属変数と独立変数の相関分析 は cor.test で行う
# 両者が無相関であるかの検定は p-value の横に示されているもの
# 偏回帰係数の検定 と 分散分析 の p 値と同じである
cor.test(x, y)
    Pearson's product-moment correlation

data:  x and y
t = -0.5976143046672, df = 5, p-value = 0.5761317257177
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
 -0.8466377904121403  0.6143036678155451
sample estimates:
                cor 
-0.2581988897471611 
# 回帰分析の結果の所にもあるが,個別に検定することもできる
# 回帰の分散分析である
# Pr(>F) の下に書かれている p 値は,既に書いてきた 3 個の p 値と全く同じである
anova(lm.1)
A anova: 2 × 5
Df Sum Sq Mean Sq F value Pr(>F)
<int> <dbl> <dbl> <dbl> <dbl>
x 1 0.3809524 0.3809524 0.3571429 0.5761317
Residuals 5 5.3333333 1.0666667 NA NA
0
0
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
0