1. Importer les données

ozone <- read.table("https://r-stat-sc-donnees.github.io/ozone.txt",header=TRUE)
summary(ozone[,c("maxO3","T12")])
     maxO3             T12       
 Min.   : 42.00   Min.   :14.00  
 1st Qu.: 70.75   1st Qu.:18.60  
 Median : 81.50   Median :20.55  
 Mean   : 90.30   Mean   :21.53  
 3rd Qu.:106.00   3rd Qu.:23.55  
 Max.   :166.00   Max.   :33.50  

2. Représenter le nuage de points (xi, yi)

plot(maxO3~T12,data=ozone,pch=15,cex=.5)

3. Estimer les paramètres

reg.s <- lm(maxO3~T12,data=ozone)
summary(reg.s)

Call:
lm(formula = maxO3 ~ T12, data = ozone)

Residuals:
    Min      1Q  Median      3Q     Max 
-38.079 -12.735   0.257  11.003  44.671 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept) -27.4196     9.0335  -3.035    0.003 ** 
T12           5.4687     0.4125  13.258   <2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 17.57 on 110 degrees of freedom
Multiple R-squared:  0.6151,    Adjusted R-squared:  0.6116 
F-statistic: 175.8 on 1 and 110 DF,  p-value: < 2.2e-16
names(reg.s)
 [1] "coefficients"  "residuals"     "effects"       "rank"          "fitted.values" "assign"        "qr"           
 [8] "df.residual"   "xlevels"       "call"          "terms"         "model"        
reg.s$coef
(Intercept)         T12 
 -27.419636    5.468685 
coef(reg.s)
(Intercept)         T12 
 -27.419636    5.468685 
reg.ss.constante <- lm(maxO3~T12-1, data=ozone)

4. Tracer la droite de régression

 plot(maxO3~T12,data=ozone,pch=15,cex=.5)
 grillex <- seq(min(ozone[,"T12"]),max(ozone[,"T12"]),length=100)
 grilley <- reg.s$coef[1]+reg.s$coef[2]*grillex
 lines(grillex,grilley,col=2)

5. Analyser les résidus

res.simple<-rstudent(reg.s)
plot(res.simple,pch=15,cex=.5,ylab="Résidus",ylim=c(-3,3))
abline(h=c(-2,0,2),lty=c(2,1,2))

6. Prévoir une nouvelle valeur

 xnew <- 19
 xnew <- as.data.frame(xnew)
 colnames(xnew) <- "T12"
 predict(reg.s,xnew,interval="pred")
       fit     lwr      upr
1 76.48538 41.4547 111.5161
grillex.df <- data.frame(grillex)
dimnames(grillex.df)[[2]]<-"T12"
 ICdte <- predict(reg.s, new=grillex.df, interval="conf", level=0.95)
 ICprev <- predict(reg.s, new=grillex.df, interval="pred", level=0.95)
 plot(maxO3~T12, data=ozone, pch=15, cex=.5)
 matlines(grillex,cbind(ICdte, ICprev[,-1]), lty=c(1,2,2,3,3),
col=c("black","red","red","blue","blue"))
 legend("topleft", lty=3:2, col=c("blue","red"), c("prev","conf"))

LS0tDQp0aXRsZTogIlLDqWdyZXNzaW9uIFNpbXBsZSINCmF1dGhvcjogIkh1c3NvbiBldCBhbC4iDQpkYXRlOiAiMTIgc2VwdGVtYnJlIDIwMTgiDQpvdXRwdXQ6DQogIGh0bWxfbm90ZWJvb2s6DQogICAgdG9jOiB5ZXMNCiAgICB0b2NfZGVwdGg6IDMNCiAgICB0b2NfZmxvYXQ6IHllcw0KICBodG1sX2RvY3VtZW50Og0KICAgIHRvYzogeWVzDQogICAgdG9jX2RlcHRoOiAnMycNCiAgICB0b2NfZmxvYXQ6IHllcw0KLS0tDQoNCmBgYHtyIHNldHVwLCBpbmNsdWRlPUZBTFNFfQ0Ka25pdHI6Om9wdHNfY2h1bmskc2V0KGVjaG8gPSBUUlVFKQ0KYGBgDQoNCiMgMS4gSW1wb3J0ZXIgbGVzIGRvbm7DqWVzDQoNCmBgYHtyIG96b25lfQ0Kb3pvbmUgPC0gcmVhZC50YWJsZSgiaHR0cHM6Ly9yLXN0YXQtc2MtZG9ubmVlcy5naXRodWIuaW8vb3pvbmUudHh0IixoZWFkZXI9VFJVRSkNCnN1bW1hcnkob3pvbmVbLGMoIm1heE8zIiwiVDEyIildKQ0KYGBgDQojIDIuIFJlcHLDqXNlbnRlciBsZSBudWFnZSBkZSBwb2ludHMgKHhp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