Modelisation
Modelisation
des Sciences,
Technologies,
Ingénierie et
Mathématiques
(UNSTIM)
Modélisation Statistique
Saisi par :
Sous la direction de :
Les étudiants de
Dr Nicodème ATCHADE
la 1re Promotion
3
4 SOMMAIRE
RÉGRESSION LINÉAIRE
En régression linéaire, les variables sont quantitatives. Dans le cas simple, le modèle s’écrit
comme suit :
yi = β0 + β1 xi + εi ; i = 1, ..., n.
Y = Xβ + ε
1. Jeu de données :
Y X
y0 x0
y1 x1
.. ..
. .
yn x0
5
6 Chapitre 1 : Régression linéaire
10
8
yp
6
4
2
2 4 6 8 10
xp
3. Estimation du modèle
Il existe deux méthodes principales sont utilisées : la Méthode des Moindres Carrés Ordi-
naires (MCO) et la Méthode du Maximum de Vraisemblance ou Maximum Likelyhood
(MLE). L’objectif principal de la MCO est la minimisation de la somme des carrés des er-
reurs commises.
ε2i = min (yi − ŷi )2
X X
min
β̂0M CO = ȳ − β̂1M CO x̄
¯ − x̄ȳ
xy
β̂1M CO = ¯2
x − x̄2
Sous forme matricielle Y = Xβ + ε
Xβ = Y − ε ⇔ X 0 Xβ = X 0 (Y − ε)
Xβ = Y − ε ⇔ X 0 Xβ = X 0 Y − X 0 ε
or X 0 ε = 0 ; donc X 0 Xβ = X 0 Y
βM CO = (X 0 X)−1 X 0 Y
4. Test de significativité
> modele = lm(y~x)
> summary(modele)
• Significativité des coefficients
Le test mis en évidence test de Student. Les hypothèses du test sont :
Statistique de Student :
β̂j √
tβ̂j = avec σ̂βj = se aii
σ̂βj
s P 2
ε
où aii sont les éléments diagonaux de la matrice carrée (XX ) 0 −1
et se = i
n−m−1
Si tβbj > ttab ou p_value < α, alors on rejet H0 ; on conclut donc que le coefficient β̂j est
significatif au seuil α.
• Significativité globale du modèle
Le test mis en évidence test de Fisher. Les hypothèses du test sont :
contre
REMARQUE 1.1.1
• Si le coefficient est significatif, on peut l’interpréter.
• Intervalle de confiance du coefficient β̂j :
cov(x, y)
• R2 = rxy
2
=
sx × sy
2 n−1
• Radj = 1 − (1 − R2 ) ·
n−m−1
Forme matricielle :
Y = βX + ε
• Procédure de la modélisation
1. Plot
> plot(x_1,y)
> plot(x_2,y)
..
.
> plot(x_m,y)
2. Estimations
> RLM = lm(y ~ x_1 + x_2 + ... + x_m, data = base)
3. Test de significativité
4. Vérifiaction des hypothèses
5. Prédire
6. Sélection de modèles :
La variation d’une unité de X1 entraine la variation de βˆ1 de y, toute chose étant égale
par ailleurs.
Au bout d’une modélisation statisique par RL, il est important de vérifier les hypothèses sto-
chastiques essentiellement celles d’homoscédasticité, de normalité des résidus, d’abscence de
multicolinéarité et d’absence d’auto-corrélation des erreurs.
9
10 Chapitre 2 : Vérification des hypothèses stochastiques du modèle linéaire
où Rj2 désigne le coefficient de détermination du modèle RLM. Xj = f (X1 , X2 , ..., Xj−1 , Xj+1 , ..., Xp )
Ainsi, plus le lien linéaire entre Xj et les autres variables est fort,plus Rj2 est proche de 1 et
plus le VIF est grand et plus l’estimation de
betaj est instable.Autrement,Xj est à la base de la multicolinéarité.
Si VIF ≥ 5, on admet qu’il y a multicolinéarité. Dans la littérature, ce seuil peut varier. (Ref 3
dans Eliseeva,2014 Econométrie)
Sous R :
> library(cor)
> vif(model)
β∈Rp+1 j=1
| {z }
pénalisation
En général,on le calcule pour plusieurs valeurs de λ, λ convenable est estimable avec plusieurs
méthodes dont le maximum de vraisemblance.
Sous R :
> library(MASS)
> reg = lm.ridge(Y ∼ X_1+X_2+X_3, lambda = seq(0,100,1))
> select(reg)
Exemple
Y X
30 4
20 3
10 2
ŷi = β̂xi
MCO
ε2i
X
argminβ
yi2 − 2β xi y i + β 2 x2i
X X X
f (β) =
∂f
x2i = 0
X X
= 0 ⇐⇒ −2 xi yi + 2β
∂β
P
xi y i
⇐⇒ β̂M CO =
x2i
Ridge
yi2 − 2β xi y i + β 2 x2i + λβ 2
X X X
fRidge =
∂fRidge
x2i + 2λβ = 0
X X
= 0 ⇐⇒ −2 xi yi + 2β
∂β
P
xi y i
⇐⇒ β̂Ridge = 2
xi + λ
Application à l’exemple
120 + 60 + 20
β̂M CO = = 7.58
16 + 9 + 4
120 + 60 + 20
β̂Ridge = = 7.09
16 + 9 + 4 + 2
7.09 < 7.58
p
β̂Ridge = argmin kY − Xβk + λ 2
X
|β̂j |
β∈Rp+1 j=1
| {z }
pénalisation
Sous R :
> library(lars)
> X = cbind(1, X_1, X_2)
> regLasso = lars(X, Y, type = "lasso")
> summary(regLasso)
p p
β̂ElN et = argmin kY − Xβk2 + λ β̂j2 + λ
X X
|β̂j |
β∈Rp+1 j=1 j=1
| {z }
pénalisation
εi εi
Homoscédasticité · ·· · Hétéroscédasticité
·
· ·· ··
·
· ·· ··
· · ·
· ·· ··
·
· ·· ··
· · ·
· ·· ··
·
· ·· ··
·
· ·· ··
· · ·
· ·· ··
·
·· ··
·
ŷi ŷi
εi 2
= α0 + αj xji + αj+1 x(j+1)i + · · · + αj+k x(j+k)i + υi
s2
1X 2
avec s2 = εi .
n
Si αj s’avère significatif, alors la variable xj explique la variation des résidus.
On dit que xj est à la base de l’heterosédasticité.
3. Test de White
εi 2 = α0 + α11 x1i + α12 x1i 2 + α21 x2i + α22 x2i 2 + γ12 x1i x2i + υi
4. Test de Park
ln εi 2 = α0 + αj lnxji + υi
5. Test de Gleizer
|εi | = α0 + αj xji k + υi
avec k = −1; −0.5; 0.5; 1
L’estimateur de β en cas d’hétéroscédasticité est :
−1
βbM CG = X 0 Ω−1 X X 0 Ω−1 Y
σε1 2 0 ···
0
0 σε2 2 ··· 0
où Ω = .. .. ..
..
. . . .
0 0 · · · σεn 2
Y = β0 + β1 X1 + β2 X2 + β3 X3 + ε
S’il s’avère par exemple que c’est X3 qui est à la base de l’hétéroscédasticité, on divise toute
l’équation par X3 et on obtient un nouveau modèle qui est le suivant :
Y 1 X1 X2 1
= β0 + β1 + β2 + β3 + ε
X3 X3 X3 X3 X3
On peut réécrire comme suit le modèle :
A ce nouveau modèle, on applique la MCO ; c’est cette procédure qu’on appelle la MCG.
Si la condition d’homoscédaticité (V ar(ε∗i ) = cste) est vérifiée , alors on réécrit le modèle sous
sa forme initiale avec les nouveaux coefficients βj∗ pour l’interprétation.
Exemple 1 :
Soit le modèle suivant :
Comme interprétation, on a :
Une augmentation d’une unité de X1 entraine une augmentation de 8.018 unités de Y ; toute chose
étant identique par ailleurs.
Sous R , pour avoir β̂M CG :
> reg = lm(Y∼X_1 + X_2 + X_3)
> e = residuals(reg)
> reg2 = lm(Y∼X_1+X_2+X_3,weights=1/e^2)
> summary(reg2)
Exemple 2 :
http : //rstudio−pubs−static.s3.amazonaws.com/300060d 2f 81f 64f 48443748969d7c1f 6cc7249.html
https : //rpubs.com/cyobero/187387
2.3.1.2 Résolution
√ 1
Une RLM avec y transformée comme ln(y), y, , . . . peut engendrer de nouvelles erreurs
y
ε1 , ε2 . . . , εn suivant chacune une loi normale. Dès lors, on peut utiliser ce nouveau modèle pour
une étude statistique.
Pour λ = 1, y ∗ = y − 1
1
Pour λ = −1, y ∗ = 1 −
y
Pour λ → 0, y ∗ = ln y (Démonstrations, voir TP)
Pour y < 0, on peut utiliser la transformation de Yéo Johson (Voir TP).
Sous R :
> library(car)
> reg = lm(Y ~ X1+X2+X3)
> reg2 = powerTransform(reg,family = "yjPower)
> summary(reg2)
> reg3 = lm(bcPower(Y,coef(reg2)) ~ X1+X2+X3)
> summary(reg3)
> reg3 = lm(modelYj$fitted ~ X1+X2+X3)
AIC = 2(p + 1) − 2`
BIC = (p + 1) ln(n) − 2`
où ` = max
p+1
`(β) est le maximum de la log-vraissemblance du modèle.
β∈R
Ces critères reposent sur un compromis "biais parcimonie". Plus petits ils sont, meilleur
est le modèle
REMARQUE 2.3.1
Contrairemet au Radj , ces critères peuvent être utilisés pour les modèles linéaires généralisés
(voir cours de Statistique semestre 9)
Sous R :
> AIC(reg)
> BIC(reg)
3.1 INTRODUCTION
In the previous classes, we studied Simple Linear Regression (SLR), Multiple Linear Regres-
sion (MLR) and the variables were quantitative. Generally, that condition is not frequent i.e in
real life, Y is influenced by factors(qualitative) and quantitative variable. For instance, the pro-
ductivity (milk) of a cow can depend on the quality of its diet (premium type I and type II). To
emphasize the dependency of Y related to the predictor, we use dummy variables. There are
binary variable which values are 0 and 1. If the qualitative variable has k modalities, we might
need a dummy variable ; by the way we use k − 1 dummy variables. We affect 1 to the dummy,
if the factor modality is the one of interest. Thus, the remaining got 0. This latter is the reference
Z1 = Z2 = · · · = Zk−1 = 0.
About the choice of the modalities, it is advised to select that modality which is the min or max
proportion of Y. If in the model we have many factors, then, for each of them we make all the
dummy variables. In that case the dummy variables are indexed as zji , with j as index of factor
and i the index about order of the j th category.
We are going to out the different type of modeling with dummy variables.
17
18 Chapitre 3 : DUMMY VARIABLES IN MODELING
Comparing (3.3 and 3.4) we do notice the difference between (α0 + γ11 ) and (α0 ). As illustration
we have :
Y
Ŷ = (α0 + γ11 ) + α1 X1
Ŷ = α0 + α1 X1
X
Let’s notify that α1 is unchanged. It means the variation of X1 has the same effect on Y not depen-
ding on the values of the factor. And, as the factor variation in the model 1 induces the variation
of Y , we can notice that it is the result of Z11 and Z1 2 = 0 of the factor. Eg : Y impôt in millions,
X1 Volume of products, X2 region. After computing OLS we have :
In general Z11 shows of how much in mean the taxes from the central regions are greater than
those in the other regions. We cannot be too sure about our conclusion, because γ11 is not signi-
ficant. If we ignore the non-significant effect of the dummy variable, then both equations (3.3
and 3.4) are equal.
α11 6= α12 and in this case we said that it a structural change of the dependence of X1 and Y . To
take into account this structural change, we introduce the interaction variable and we have :
Consequently we have α12 = α1 + φ111 from (3.9. As an illustration of the model (3.10) can be
shown like this :
Y
Ŷ = α0 + (α1 + φ111 )X1
Ŷ = α0 + α1 + X1
X
1. α1 : can be considered as the influence of X1 with Z11 = 0,
2. φ111 : can be considered as the mean variation of X1 on Y when Z11 = 1
Related to our case our case we have Ŷ = 9436, 96 + 0, 145X1 − 0, 028X1 Z11 and the observed
differences in (3.6 and 3.7) is −0, 028 (non significant). The conclusion is that the difference bet-
ween regression coefficient for region 1 and 0............On the other hand we can interpret −0, 028
as the gain on taxes in central regions compared to the other regions. The obtained models for
the values of Z11 are as follows.
The last two models are not the same as (3.6 and 3.7). Thus, we are to improve them with the
dummy variables.
Ŷ = α0 + α1 X1 ; if Z11 = 0
Ŷ = (α0 + γ11 ) + (α1 + φ111 )X1 ; if Z11 = 0
The parameters of (3.19 and 3.19) are from the general model and we can notice that α01 = α0 ,
α11 = α1 , α02 = α0 + γ11 , α12 = α1 φ111 . As illustration , the general model (3.2) can be presented
as follows :
y
Ŷ = (α0 + γ11 ) + (α1 + φ111 )x1
Ŷ = α0 + α1 X1
x
considering our example
all the parameters are significant. By the way ,the general model , well describe the study ; i.e R2
is quite high (R= 0, 59)and (F = 7, 79 > 2, 82). What are the reason of the non-significance of
the coefficient with the other model (decallage-pente) ?
To get the answer, we need to compare the parameters of the different models. We got that the
central regions helps to have greater taxes (8971.1). At the same time, the "profotability" in taxes
of X1 in the central regions is smaller ie the influence of "region" has two points. This is due to
the values of X1 in our sample and others factors that could taken into account in the model. The
interpretation can be set as follows :
1. 0.186 =⇒ In the region (non-central), Z11 = 0 the taxes are 0,186 millions ( in mean) of 1
million of exported products.
2. 0.112 =⇒ In the central region , the "profotability" of 1 million of exported products is
smaller of 0.112.
3. 9871.9 =⇒ The influence of others factors made us to state that the taxes in central regions
are greater of 8971.9 compare to non central region.
Let’s summarize the computed models and calculations in a table :
Models with dummy variables can be used with time series analysis in order to structure the
seasonal fluctuations.
TRAVAUX PRATIQUES
23
24 Chapitre A : Travaux Pratiques
A.3 ANOVA
Retrouver les formule des tests de Shapiro-Wilk et Shapiro-Francia