Regression linéaire multiple
> x1<-c(2,1,3,6,7,8,8,5,5,8,4,9,12,7)
> length(x1)
[1] 14
> x2<-c(45,43,43,47,42,41,32,33,41,38,32,31,35,29)
> length(x2)
[1] 14
> x3<-c(121,132,154,145,129,156,132,147,128,163,161,172,174,180)
> length(x3)
[1] 14
> summary(y)
Min. 1st Qu. Median Mean 3rd Qu. Max.
10.00 14.50 19.00 17.71 21.00 25.00
> summary(x1)
Min. 1st Qu. Median Mean 3rd Qu. Max.
1.000 4.250 6.500 6.071 8.000 12.000
> summary(x2)
Min. 1st Qu. Median Mean 3rd Qu. Max.
29.00 32.25 39.50 38.00 42.75 47.00
> summary(x3)
Min. 1st Qu. Median Mean 3rd Qu. Max.
121.0 132.0 150.5 149.6 162.5 180.0
> [Link](y,x1)
Pearson's product-moment correlation
data: y and x1
t = 3.5958, df = 12, p-value = 0.003674
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
0.3068375 0.9049589
sample estimates:
cor
0.7201718
> [Link](y,x2)
Pearson's product-moment correlation
data: y and x2
t = -3.3467, df = 12, p-value = 0.005815
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
-0.8953286 -0.2601395
sample estimates:
cor
-0.6948171
> [Link](y,x3)
Pearson's product-moment correlation
data: y and x3
t = 1.8961, df = 12, p-value = 0.08227
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
-0.06767425 0.80551565
sample estimates:
cor
0.4801456
> [Link](x1,x2)
Pearson's product-moment correlation
data: x1 and x2
t = -1.7814, df = 12, p-value = 0.1002
1
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
-0.79499412 0.09674007
sample estimates:
cor
-0.4573125
> [Link](x1,x3)
Pearson's product-moment correlation
data: x1 and x3
t = 2.3812, df = 12, p-value = 0.03469
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
0.05131528 0.84352324
sample estimates:
cor
0.5664716
> [Link](x2,x3)
Pearson's product-moment correlation
data: x2 and x3
t = -2.6544, df = 12, p-value = 0.02101
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
-0.8609631 -0.1146462
sample estimates:
cor
-0.6082278
> par(mfrow=c(1,3))
> plot(x1,y)
> plot(x2,y)
> plot(x3,y)
> model<-lm(y~x1+x2+x3)
> model
Call:
2
lm(formula = y ~ x1 + x2 + x3)
Coefficients:
(Intercept) x1 x2 x3
32.89132 0.80190 -0.38136 -0.03713
> summary(model)
Call:
lm(formula = y ~ x1 + x2 + x3)
Residuals:
Min 1Q Median 3Q Max
-3.6973 -1.1259 0.1907 1.4846 4.4880
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 32.89132 11.66331 2.820 0.0182 *
x1 0.80190 0.29844 2.687 0.0228 *
x2 -0.38136 0.15658 -2.436 0.0351 *
x3 -0.03713 0.05202 -0.714 0.4917
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 2.597 on 10 degrees of freedom
Multiple R-squared: 0.7027, Adjusted R-squared: 0.6135
F-statistic: 7.878 on 3 and 10 DF, p-value: 0.005452
> names(model)
[1] "coefficients" "residuals" "effects" "rank"
"[Link]"
[6] "assign" "qr" "[Link]" "xlevels" "call"
[11] "terms" "model"
> model$coefficients
(Intercept) x1 x2 x3
32.89132428 0.80190069 -0.38136236 -0.03713244
> coef(model)
(Intercept) x1 x2 x3
32.89132428 0.80190069 -0.38136236 -0.03713244
> model$[Link]
[1] 10
*********Intervalle de confiance pour les prévisions
> predict(model,interval="confidence")
fit lwr upr
1 12.84079 9.784226 15.89736
2 12.39316 9.241868 15.54446
3 13.18005 9.962768 16.39733
4 14.39449 11.096515 17.69247
5 17.69733 14.741749 20.65290
6 17.87801 15.405667 20.35036
7 22.20145 17.977976 26.42493
8 18.85740 16.253227 21.46158
9 16.51202 14.054197 18.96984
10 18.76217 16.564757 20.95959
11 17.91701 14.712613 21.12141
12 21.89942 19.238295 24.56054
13 22.70541 19.006635 26.40418
14 20.76128 17.286810 24.23575
> resid<-resid(model)
> resid
1 2 3 4 5 6
7
-0.8407945 1.6068382 -3.1800496 1.6055059 -3.6973256 1.1219871 -
1.2014526
8 9 10 11 12 13
14
0.1425984 4.4879810 -2.7621729 1.0829908 -0.8994182 2.2945940
0.2387179
> summary(resid)
Min. 1st Qu. Median Mean 3rd Qu. Max.
3
-3.6970 -1.1260 0.1907 0.0000 1.4850 4.4880
> model$[Link]
[1] 10
> model$[Link]
1 2 3 4 5 6 7 8
9
12.84079 12.39316 13.18005 14.39449 17.69733 17.87801 22.20145 18.85740
16.51202
10 11 12 13 14
18.76217 17.91701 21.89942 22.70541 20.76128
> plot(model)
> anova<-anova(model)
> anova
Analysis of Variance Table
Response: y
Df Sum Sq Mean Sq F value Pr(>F)
x1 1 117.659 117.659 17.4445 0.001898 **
x2 1 38.314 38.314 5.6806 0.038389 *
x3 1 3.436 3.436 0.5095 0.491694
Residuals 10 67.448 6.745
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
*********** Intervalle de confiance pour les coefficients
> confint(model)
2.5 % 97.5 %
(Intercept) 6.9038498 58.87879876
x1 0.1369442 1.46685718
x2 -0.7302459 -0.03247885
x3 -0.1530472 0.07878231
> confint(model,level=0.90)
5 % 95 %
(Intercept) 11.7520281 54.03062049
x1 0.2609973 1.34280405
x2 -0.6651588 -0.09756595
x3 -0.1314223 0.05715746
> confint(model,level=0.98)
1 % 99 %
(Intercept) 0.65662392 65.12602465
x1 -0.02290717 1.62670855
x2 -0.81411529 0.05139056
x3 -0.18091236 0.10664749
4
*******************les composant de la matrice X’X
> sum(x1)
[1] 85
> sum(x2)
[1] 532
> sum(x3)
[1] 2094
> sum(x1^2)
[1] 631
> sum(x2^2)
[1] 20666
> sum(x3^2)
[1] 317950
> sum(x1*x2)
[1] 3126
> sum(x1*x3)
[1] 13132
> sum(x2*x3)
[1] 78683
******************Les composants de la matrice X’Y
> sum(y)
[1] 248
> sum(y*x1)
[1] 1622
> sum(y*x2)
[1] 9202
> sum(y*x3)
[1] 37592
*****************************SCT
> sum((y-mean(y))^2)
[1] 226.8571