\( %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Mes commandes %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \newcommand{\multirows}[3]{\multirow{#1}{#2}{$#3$}}%pour rester en mode math \renewcommand{\arraystretch}{1.3}%pour augmenter la taille des case \newcommand{\point}[1]{\marginnote{\small\vspace*{-1em} #1}}%pour indiquer les points ou le temps \newcommand{\dpl}[1]{\displaystyle{#1}}%megamode \newcommand{\A}{\mathscr{A}} \newcommand{\LN}{\mathscr{N}} \newcommand{\LL}{\mathscr{L}} \newcommand{\K}{\mathbb{K}} \newcommand{\N}{\mathbb{N}} \newcommand{\Z}{\mathbb{Z}} \newcommand{\Q}{\mathbb{Q}} \newcommand{\R}{\mathbb{R}} \newcommand{\C}{\mathbb{C}} \newcommand{\M}{\mathcal{M}} \newcommand{\D}{\mathbb{D}} \newcommand{\E}{\mathcal{E}} \renewcommand{\P}{\mathcal{P}} \newcommand{\G}{\mathcal{G}} \newcommand{\Kk}{\mathcal{K}} \newcommand{\Cc}{\mathcal{C}} \newcommand{\Zz}{\mathcal{Z}} \newcommand{\Ss}{\mathcal{S}} \newcommand{\B}{\mathbb{B}} \newcommand{\inde}{\bot\!\!\!\bot} \newcommand{\Proba}{\mathbb{P}} \newcommand{\Esp}[1]{\dpl{\mathbb{E}\left(#1\right)}} \newcommand{\Var}[1]{\dpl{\mathbb{V}\left(#1\right)}} \newcommand{\Cov}[1]{\dpl{Cov\left(#1\right)}} \newcommand{\base}{\mathcal{B}} \newcommand{\Som}{\textbf{Som}} \newcommand{\Chain}{\textbf{Chain}} \newcommand{\Ar}{\textbf{Ar}} \newcommand{\Arc}{\textbf{Arc}} \newcommand{\Min}{\text{Min}} \newcommand{\Max}{\text{Max}} \newcommand{\Ker}{\text{Ker}} \renewcommand{\Im}{\text{Im}} \newcommand{\Sup}{\text{Sup}} \newcommand{\Inf}{\text{Inf}} \renewcommand{\det}{\texttt{det}} \newcommand{\GL}{\text{GL}} \newcommand{\crossmark}{\text{\ding{55}}} \renewcommand{\checkmark}{\text{\ding{51}}} \newcommand{\Card}{\sharp} \newcommand{\Surligne}[2]{\text{\colorbox{#1}{ #2 }}} \newcommand{\SurligneMM}[2]{\text{\colorbox{#1}{ #2 }}} \newcommand{\norm}[1]{\left\lVert#1\right\rVert} \renewcommand{\lim}[1]{\underset{#1}{lim}\,} \newcommand{\nonor}[1]{\left|#1\right|} \newcommand{\Un}{1\!\!1} \newcommand{\sepon}{\setlength{\columnseprule}{0.5pt}} \newcommand{\sepoff}{\setlength{\columnseprule}{0pt}} \newcommand{\flux}{Flux} \newcommand{\Cpp}{\texttt{C++\ }} \newcommand{\Python}{\texttt{Python\ }} %\newcommand{\comb}[2]{\begin{pmatrix} #1\\ #2\end{pmatrix}} \newcommand{\comb}[2]{C_{#1}^{#2}} \newcommand{\arrang}[2]{A_{#1}^{#2}} \newcommand{\supp}[1]{Supp\left(#1\right)} \newcommand{\BB}{\mathcal{B}} \newcommand{\arc}[1]{\overset{\rotatebox{90}{)}}{#1}} \newcommand{\modpi}{\equiv_{2\pi}} \renewcommand{\Re}{Re} \renewcommand{\Im}{Im} \renewcommand{\bar}[1]{\overline{#1}} \newcommand{\mat}{\mathcal{M}} \newcommand{\und}[1]{{\mathbf{\color{red}\underline{#1}}}} \newcommand{\rdots}{\text{\reflectbox{$\ddots$}}} \newcommand{\Compa}{Compa} \newcommand{\dint}{\dpl{\int}} \newcommand{\intEFF}[2]{\left[\!\left[#1 ; #2\right]\!\right]} \newcommand{\intEFO}[2]{\left[\!\left[#1 ; #2\right[\!\right[} \newcommand{\intEOF}[2]{\left]\!\left]#1 ; #2\right]\!\right]} \newcommand{\intEOO}[2]{\left]\!\left]#1 ; #2\right[\!\right[} \newcommand{\ou}{\vee} \newcommand{\et}{\wedge} \newcommand{\non}{\neg} \newcommand{\implique}{\Rightarrow} \newcommand{\equivalent}{\Leftrightarrow} \newcommand{\Ab}{\overline{A}} \newcommand{\Bb}{\overline{B}} \newcommand{\Cb}{\overline{C}} \newcommand{\Cl}{\texttt{Cl}} \newcommand{\ab}{\overline{a}} \newcommand{\bb}{\overline{b}} \newcommand{\cb}{\overline{c}} \newcommand{\Rel}{\mathcal{R}} \newcommand{\superepsilon}{\varepsilon\!\!\varepsilon} \newcommand{\supere}{e\!\!e} \makeatletter \newenvironment{console}{\noindent\color{white}\begin{lrbox}{\@tempboxa}\begin{minipage}{\columnwidth} \ttfamily \bfseries\vspace*{0.5cm}} {\vspace*{0.5cm}\end{minipage}\end{lrbox}\colorbox{black}{\usebox{\@tempboxa}} } \makeatother \def\ie{\textit{i.e. }} \def\cf{\textit{c.f. }} \def\vide{ { $ {\text{ }} $ } } %Commande pour les vecteurs \newcommand{\grad}{\overrightarrow{Grad}} \newcommand{\Vv}{\overrightarrow{v}} \newcommand{\Vu}{\overrightarrow{u}} \newcommand{\Vw}{\overrightarrow{w}} \newcommand{\Vup}{\overrightarrow{u'}} \newcommand{\Zero}{\overrightarrow{0}} \newcommand{\Vx}{\overrightarrow{x}} \newcommand{\Vy}{\overrightarrow{y}} \newcommand{\Vz}{\overrightarrow{z}} \newcommand{\Vt}{\overrightarrow{t}} \newcommand{\Va}{\overrightarrow{a}} \newcommand{\Vb}{\overrightarrow{b}} \newcommand{\Vc}{\overrightarrow{c}} \newcommand{\Vd}{\overrightarrow{d}} \newcommand{\Ve}[1]{\overrightarrow{e_{#1}}} \newcommand{\Vf}[1]{\overrightarrow{f_{#1}}} \newcommand{\Vn}{\overrightarrow{0}} \newcommand{\Mat}{Mat} \newcommand{\Pass}{Pass} \newcommand{\mkF}{\mathfrak{F}} \renewcommand{\sp}{Sp} \newcommand{\Co}{Co} \newcommand{\vect}[1]{\texttt{Vect}\dpl{\left( #1\right)}} \newcommand{\prodscal}[2]{\dpl{\left\langle #1\left|\vphantom{#1 #2}\right. #2\right\rangle}} \newcommand{\trans}[1]{{\vphantom{#1}}^{t}{#1}} \newcommand{\ortho}[1]{{#1}^{\bot}} \newcommand{\oplusbot}{\overset{\bot}{\oplus}} \SelectTips{cm}{12}%Change le bout des flèches dans un xymatrix \newcommand{\pourDES}[8]{ \begin{itemize} \item Pour la ligne : le premier et dernier caractère forment $#1#2$ soit $#4$ en base 10. \item Pour la colonne : les autres caractères du bloc forment $#3$ soit $#5$ en base 10. \item A l'intersection de la ligne $#4+1$ et de la colonne $#5+1$ de $S_{#8}$ se trouve l'entier $#6$ qui, codé sur $4$ bits, est \textbf{\texttt{$#7$}}. \end{itemize} } \)

La statistique bivarié

Dans une promotion de \( 52\) étudiants, on dispose, pour chaque étudiant, de sa moyenne en mathématique et de sa moyenne en informatique. On représente ces données dans un graphique, où les notes de maths sont placées en abscisse et les notes d'informatique en ordonnée. Chaque point représente donc un étudiant. Une observation rapide, permet d'observer qu'il y a un alignement. L'observation de cet alignement nous motive à penser que la note d'informatique d'un étudiant, notée \( y\) , est une fonction affine de la note de mathématique, notée \( x\) . La formulation mathématique est donc \[y=ax+b\] On observe aussi que, bien que les données soient alignées elles ne le sont pas parfaitement, en vérité \( y=ax+b+erreur\) . L'objectif de la régression linéaire est d'essayer de trouver \( a\) et \( b\) tel que l'erreur soit la plus petite possible. Il y a enfin un dernier paramètre à prendre en compte : il n'y a pas qu'une information, mais \( 52\) , c'est à dire qu'en fait \( y_i=ax_i+b+erreur_i\) où l'ajout de l'indice \( i\) permet d'identifier l'étudiant \( i\) . Finalement, nous cherchons \( a\) et \( b\) tel que les \( erreur_i\) soient les plus petit possible. L'idée1 est de faire en sorte que \( \dpl{\sum_i} erreur_i^2\) soient les plus petit possible. De la formule \( y_i=ax_i+b+erreur_i\) on obtient \( erreur_i=y_i-(ax_i+b)\) et on cherche donc le minimum de \[f(a, b)=\sum_i\left(y_i-(ax_i+b)\right)^2\] Déterminons les points critiques éventuels de cette fonction. \[ \dfrac{\partial f}{\partial a} (a, b) = \sum_i-2x_i\left(y_i-(ax_i+b)\right) \] \[ \dfrac{\partial f}{\partial b} (a, b) = \sum_i-2\left(y_i-(ax_i+b)\right) \] Trouver un point critique reviens donc à résoudre le système \[ \left\{ \begin{array}{rcl} \dfrac{\partial f}{\partial a} (a, b)&=&0\\ \dfrac{\partial f}{\partial b} (a, b)&=&0 \end{array} \right. \quad\Longrightarrow\quad \left\{ \begin{array}{rcl} \dpl{\sum_i}-2x_i\left(y_i-(ax_i+b)\right)&=&0\\ \dpl{\sum_i}-2\left(y_i-(ax_i+b)\right)&=&0 \end{array} \right. \] Faisons un peut de math, rappelons quelques notation de la statistique : \( \overline{x}=\dfrac{1}{52}\dpl{\sum_i}x_i\) (la moyenne), \( \overline{xy}=\dfrac{1}{52}\dpl{\sum_i}x_iy_i\) , \( \overline{x^2}=\overline{xx} = \dfrac{1}{52}\dpl{\sum_i}x_i^2\) , \( cov(x, y) = \overline{xy}-\overline{x}\cdot\overline{y}=\dfrac{1}{52}\dpl{\sum_i}(x_iy_i-\overline{x}\cdot\overline{y})\) (la covariance), \( \sigma_x^2=cov(x, x)\) (la variance, la racine carré, \( \sigma_x\) est appelé l'écrat-type). \begin{eqnarray*} \left\{ \begin{array}{rcl} \dpl{\sum_i}-2x_i\left(y_i-(ax_i+b)\right)&=&0\\ \dpl{\sum_i}-2\left(y_i-(ax_i+b)\right)&=&0 \end{array} \right. &\Rightarrow & \left\{ \begin{array}{rcl} \dpl{\sum_i}x_i\left(y_i-(ax_i+b)\right)&=&0\\ \dpl{\sum_i}\left(y_i-(ax_i+b)\right)&=&0 \end{array} \right. \\ &\Rightarrow & \left\{ \begin{array}{rcl} \dpl{\sum_i}x_iy_i-ax_i^2-bx_i&=&0\\ \dpl{\sum_i}y_i-ax_i-b&=&0 \end{array} \right. \\ &\Rightarrow & \left\{ \begin{array}{rcl} \dfrac{1}{52}\dpl{\sum_i}x_iy_i-ax_i^2-bx_i&=&0\\ \dfrac{1}{52}\dpl{\sum_i}y_i-ax_i-b&=&0 \end{array} \right. \\ &\Rightarrow & \left\{ \begin{array}{rcl} \dfrac{1}{52}\dpl{\sum_i}x_iy_i-a\dfrac{1}{52}\dpl{\sum_i}x_i^2-b\dfrac{1}{52}\dpl{\sum_i}x_i&=&0\\ \dfrac{1}{52}\dpl{\sum_i}y_i-a\dfrac{1}{52}\dpl{\sum_i}x_i-b\dfrac{1}{52}\dpl{\sum_i} 1&=&0 \end{array} \right. \\ &\Rightarrow & \left\{ \begin{array}{rcl} \overline{xy}-a\overline{x^2}-b\overline{x}&=&0\\ \overline{y}-a\overline{x}-b&=&0 \end{array} \right. \\ &\Rightarrow & \left\{ \begin{array}{rcl} a\overline{x^2}+b\overline{x}&=&\overline{xy}\\ a\overline{x}+b&=&\overline{y} \end{array} \right. \\ &\Rightarrow & \left\{ \begin{array}{rcl} a\overline{x^2}+b\overline{x}&=&\overline{xy}\\ a\overline{x}^2+b\overline{x}&=&\overline{y}\cdot \overline{x} \end{array} \right. \end{eqnarray*} En faisant la soustraction des deux lignes, on trouve \( a(\overline{x^2}-\overline{x}^2)=\overline{xy}-\overline{y}\cdot \overline{x}\) , soit avec les outils et notation de la statistique \( a\sigma_x^2=cov(x, y)\) et donc \( a=\dfrac{cov(x, y)}{\sigma_x^2}\) , la seconde équation donne \( b=\overline{y}-a\overline{x}\) . Bref, nous avons trouver un unique point critique. Puisqu'il s'agit d'une somme de carré, c'est nécessairement un minimum. Ce \( a\) et ce \( b\) donne donc la meilleure droite. On peut se convaincre qu'il s'agit d'un minimum en calculant la hessienne. \begin{eqnarray*} \dfrac{\partial^2 f}{\partial a^2}(a, b) &=& \dfrac{\partial }{\partial a}\left(\dpl{\sum_i}-2x_i\left(y_i-(ax_i+b)\right)\right)\\ &=& \dfrac{\partial }{\partial a}\left(\dpl{\sum_i}-2x_iy_i+2ax_i^2+2bx_i\right)\\ &=& \dpl{\sum_i}2x_i^2\\ &=& 2\times 52\overline{x^2} \end{eqnarray*} \begin{eqnarray*} \dfrac{\partial^2 f}{\partial b^2}(a, b) &=& \dfrac{\partial f}{\partial b}\left(\dpl{\sum_i}-2\left(y_i-(ax_i+b)\right)\right)\\ &=& \dfrac{\partial f}{\partial b}\left(\dpl{\sum_i}-2y_i+2ax_i+2b\right)\\ &=& \dpl{\sum_i} 2\\ &=& 2\times 52 \end{eqnarray*} \begin{eqnarray*} \dfrac{\partial^2 f}{\partial a\partial b}(a, b) &=& \dfrac{\partial f}{\partial a}\left(\dpl{\sum_i}-2\left(y_i-(ax_i+b)\right)\right)\\ &=& \dfrac{\partial f}{\partial a}\left(\dpl{\sum_i}-2y_i+2ax_i+2b\right)\\ &=& \dpl{\sum_i}2x_i\\ &=&2\times 52\overline{x} \end{eqnarray*} Ainsi la hessienne est \( H= \begin{pmatrix} 104\overline{x^2} & 104\overline{x}\\ 104\overline{x} & 104 \end{pmatrix} \) . En particulier \( \det(H)=(104\overline{x^2})(104)-(104\overline{x})^2 = 104^2\left(\overline{x^2}-\overline{x}\right)=104^2\sigma_x^2\) . Ce déterminant est donc positif. On a de plus \( tr(H)=104\overline{x^2} + 104{>}0\) et nous avons bien un minimum.

Cas général

On dispose de \( n\) observations de deux caractères quantitatifs \( x=(x_1, \ldots, x_n)\) et \( y=(y_1, \ldots, y_n)\) , les observations permettent d'émettre l'hypothèse que pour tout \( i\) , les données \( y_i\) suivent une certaine fonction \( F(x_i, \vartheta)\) où \( \vartheta\) est un ensemble de paramètre inconnue. La méthode des moindres carrés, consiste à trouver les paramètres \( \vartheta\) tel que \( \left(y_i-F(x_i, \vartheta)\right)^2\) soit le plus petit possible. Dans la pratique, on cherche à minimiser \( f(\vartheta)=\dpl{\sum_i\left(y_i-F(x_i, \vartheta)\right)^2}\) . Dans l'exemple bien connu de statistique bivarié, les paramètres \( \vartheta=(a, b)\) et \( F(x, \vartheta)=ax_i+b\)

Exemple : un modèle non linéaire

Vous disposez de \( 100\) valeurs \( x_i\) et \( y_i\) représentées dans le dessin ci dessous. Un statisticien vous souffle que ce nuage de point semble suivre une courbe \( \dfrac{a}{x_i}+\dfrac{b}{x_i^2}\) .
Déterminer les meilleures estimations de \( a\) et \( b\) .
Appliquons la méthodes des moindre carrés, et déterminons les minimum de \[f(a, b)=\sum_i\left(y_i-\dfrac{a}{x_i}-\dfrac{b}{x_i^2}\right)^2\] Pour simplifier les notations, posons \( z_i=\dfrac{1}{x_i}\) , on a donc, \( f(a, b)=\sum_i\left(y_i-{a}{z_i}-{b}{z_i^2}\right)^2\) . Déterminons ses points critiques : \[\dfrac{\partial f}{\partial a}=\sum_i-2z_i\left(y_i-{a}{z_i}-{b}{z_i^2}\right)\] \[\dfrac{\partial f}{\partial b}=\sum_i-2z_i^2\left(y_i-{a}{z_i}-{b}{z_i^2}\right)\] \begin{eqnarray*} \left\{ \begin{array}{rcl} \dfrac{\partial f}{\partial a}&=&0\\ \dfrac{\partial f}{\partial b}&=&0 \end{array} \right. &\Rightarrow & \left\{ \begin{array}{rcl} \sum_i-2z_i\left(y_i-{a}{z_i}-{b}{z_i^2}\right)&=&0\\ \sum_i-2z_i^2\left(y_i-{a}{z_i}-{b}{z_i^2}\right)&=&0 \end{array} \right. \\ &\Rightarrow & \left\{ \begin{array}{rcl} \sum_i z_i\left(y_i-{a}{z_i}-{b}{z_i^2}\right)&=&0\\ \sum_i z_i^2\left(y_i-{a}{z_i}-{b}{z_i^2}\right)&=&0 \end{array} \right. \\ &\Rightarrow & \left\{ \begin{array}{rcl} \sum_i z_iy_i-{a}{z_i^2}-{b}{z_i^3}&=&0\\ \sum_i z_i^2y_i-{a}{z_i^3}-{b}{z_i^4}&=&0 \end{array} \right. \\ &\Rightarrow & \left\{ \begin{array}{rcl} \overline{zy}-a\overline{z^2}-b\overline{z^3}&=&0\\ \overline{z^2y}-a\overline{z^3}-b\overline{z^4}&=&0 \end{array} \right. \\ &\Rightarrow & \left\{ \begin{array}{rcl} a\overline{z^2}+b\overline{z^3}&=&\overline{zy}\\ a\overline{z^3}+b\overline{z^4}&=&\overline{z^2y} \end{array} \right. \\ &\Rightarrow & \left\{ \begin{array}{rcl} a\overline{z^2}\cdot\overline{z^3}+b\overline{z^3}\cdot\overline{z^3}&=&\overline{zy}\cdot\overline{z^3}\\ a\overline{z^3}\cdot\overline{z^2}+b\overline{z^4}\cdot\overline{z^2}&=&\overline{z^2y}\cdot\overline{z^2} \end{array} \right. \end{eqnarray*} La différence des deux lignes donne : \( b(\overline{z^3}^2-\overline{z^4}\cdot\overline{z^2})=\overline{zy}\cdot\overline{z^3}-\overline{z^2y}\cdot\overline{z^2}\) et donc \( b=\dfrac{\overline{zy}\cdot\overline{z^3}-\overline{z^2y}\cdot\overline{z^2}}{\overline{z^3}^2-\overline{z^4}\cdot\overline{z^2}}\) et \( a=\dfrac{\overline{zy}-b\overline{z^3}}{\overline{z^2}}\) (il faudrait prendre toutes les précaution mathématiques et s'assurer que les opérations effectuées dans le système ou les dénominateurs des fractions qui apparaissent soient bien définies ; dans la pratique de la statistique les cas d'erreurs sont très rare).




1de Legendre et Gauss