Chapitre 6. Programmation en R
307
> summary(reg2)
Call:
lm(formula = ..1)
Residuals:
Min
1Q Median
3Q
Max
-37.846 -5.482
1.677
9.209 38.639
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -8.9753
5.3733 -1.670
0.113
x1
0.4831
1.8083
0.267
0.793
x2
1.7774
0.1676 10.604 6.51e-09 ***
--Signif. codes: 0 ‘ *** ’ 0.001 ‘ ** ’ 0.01 ‘ * ’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 20.63 on 17 degrees of freedom
Multiple R-squared: 0.8784,
Adjusted R-squared: 0.8641
F-statistic: 61.42 on 2 and 17 DF, p-value: 1.663e-08
Rien de tr` es surprenant ne se produit puisque la sortie R du r´ esum´ e est
obtenue grˆ ace `
a la m´ ethode summary.lm(). Les deux utilisateurs sont alors int´ eress´ es par une repr´ esentation tridimensionnelle du nuage de points et du plan
de r´ egression obtenu par la m´ ethode des moindres carr´ es (ordinaires).
1 plot3d . lm2 <- function ( obj , radius =1 , lines = TRUE ,
2
windowRect ,...) {
3
matreg <- model . frame ( obj )
4
colnames ( matreg ) <- c("y" ," x1 " ," x2 ")
5
predlim <- cbind (c( range ( matreg [ ,2]) ,
6
rev ( range ( matreg [ ,2]))) ,
7
rep ( range ( matreg [ ,3]) , c (2 ,2)))
8
predlim <- cbind ( predlim , apply ( predlim ,1 ,
9
function (l) sum (c (1 , l) * coef ( obj ))
10
))
11
if ( missing ( windowRect )) windowRect =c (2 ,2 ,500 ,500)
12
open3d ( windowRect = windowRect ,...)
13
bg3d ( color = " white ")
14
plot3d ( formula ( obj ), type ="n")
15 spheres3d ( formula ( obj ), radius = radius , specular =" green ")
16
quads3d ( predlim , color =" blue " , alpha =0.7 , shininess =128)
17
quads3d ( predlim , color =" cyan " , size =5 , front =" lines " ,
18
back =" lines " , lit =F)
19
if ( lines ) {
20
matpred <- cbind ( matreg [2:3] ,
21
model . matrix ( obj )% * % coef ( obj ))
22
points3d ( matpred )
23
colnames ( matpred ) <- c(" x1 " ," x2 " ,"y")
24
matlines <- rbind ( matreg [,c (2:3 ,1)] , matpred )
Précédent

- 340/701

Suivant