Spesso si raccolgono dati sperimentali e si vuole trovare la retta che li “approssima meglio”. Il metodo dei minimi quadrati dà la risposta ottimale: la retta che minimizza la somma dei quadrati degli errori. Questa sezione ne presenta la definizione, le formule e un esempio numerico completo.

Often experimental data are collected and one wishes to find the line that “best approximates” them. The method of least squares gives the optimal answer: the line that minimises the sum of the squares of the errors. This section presents its definition, the formulae and a complete numerical example.

Spesso si raccolgono dati sperimentali e si vuole trovare la retta che li “approssima meglio”. Il metodo dei minimi quadrati dà la risposta ottimale.

Definizione — Retta di regressione

Data una serie di punti (x1,y1),,(xn,yn)(x_1,y_1),\dots,(x_n,y_n), la retta di regressione (o retta dei minimi quadrati) è la retta y=mx+qy = mx+q che minimizza la somma dei quadrati degli scarti verticali.

Collegamenti

Argomenti: Radicali
Concetti: Minimi quadrati · Regressione lineare
Competenze: Modellizzare

Often experimental data are collected and one wishes to find the line that “best approximates” them. The method of least squares gives the optimal answer.

Definition — Regression line

Given a set of points (x1,y1),,(xn,yn)(x_1,y_1),\dots,(x_n,y_n), the regression line (or least-squares line) is the line y=mx+qy = mx+q that minimises the sum of the squares of the vertical deviations.

Topics: Radicals
Concepts: Least squares · Linear regression
Skills: Modelling

Il coefficiente angolare mm e l’intercetta qq della retta di regressione si calcolano direttamente dai dati con le formule seguenti.

Proprietà — Formule dei minimi quadrati

m=nxiyi(xi) ⁣(yi)nxi2(xi) ⁣2,q=yˉmxˉm = \frac{n\,\displaystyle\sum x_i y_i - \biggl(\sum x_i\biggr)\!\biggl(\sum y_i\biggr)}{n\,\displaystyle\sum x_i^2 - \biggl(\sum x_i\biggr)^{\!2}}, \qquad q = \bar{y} - m\,\bar{x} dove xˉ=1nxi\bar{x}=\dfrac{1}{n}\sum x_i e yˉ=1nyi\bar{y}=\dfrac{1}{n}\sum y_i sono le medie.

La retta passa sempre per il punto (xˉ,yˉ)(\bar{x},\,\bar{y}) (baricentro dei dati).

Collegamenti

Argomenti: Radicali
Concetti: Minimi quadrati · Regressione lineare
Competenze: Geometria analitica · Usare formule

The slope mm and the intercept qq of the regression line are computed directly from the data with the following formulae.

Property — Least-squares formulae

m=nxiyi(xi) ⁣(yi)nxi2(xi) ⁣2,q=yˉmxˉm = \frac{n\,\displaystyle\sum x_i y_i - \biggl(\sum x_i\biggr)\!\biggl(\sum y_i\biggr)}{n\,\displaystyle\sum x_i^2 - \biggl(\sum x_i\biggr)^{\!2}}, \qquad q = \bar{y} - m\,\bar{x} where xˉ=1nxi\bar{x}=\dfrac{1}{n}\sum x_i and yˉ=1nyi\bar{y}=\dfrac{1}{n}\sum y_i are the means.

The line always passes through the point (xˉ,yˉ)(\bar{x},\,\bar{y}) (centroid of the data).

Topics: Radicals
Concepts: Least squares · Linear regression
Skills: Analytic geometry · Using formulae

Applichiamo le formule dei minimi quadrati a un piccolo insieme di dati.

Esempio

Dati i punti (1;2)(1;\,2), (2;3,5)(2;\,3{,}5), (3;4)(3;\,4), (4;5,5)(4;\,5{,}5), (5;6)(5;\,6): xˉ=3,  yˉ=4,2,  xiyi=66,5,  xi2=55.\bar{x}=3,\;\bar{y}=4{,}2,\; \sum x_iy_i = 66{,}5,\; \sum x_i^2 = 55. m=566,51521555225=332,5315275225=17,550=0,95,q=4,20,953=1,35.m = \frac{5\cdot 66{,}5 - 15\cdot 21}{5\cdot 55 - 225} = \frac{332{,}5-315}{275-225} = \frac{17{,}5}{50} = \boxed{0{,}95},\qquad q = 4{,}2-0{,}95\cdot 3 = \boxed{1{,}35}. Retta: y=0,95x+1,35y = 0{,}95\,x+1{,}35.

Il grafico mostra i dati (in rosso), la retta di regressione (in blu) e il baricentro (xˉ,yˉ)=(3;4,2)(\bar{x},\bar{y})=(3;\,4{,}2) per cui la retta passa (in verde).

I cinque punti sperimentali, la retta dei minimi quadrati e il baricentro dei dati.

Collegamenti

Argomenti: Radicali
Concetti: Minimi quadrati · Regressione lineare
Competenze: Calcolare · Interpretare grafico · Tracciare grafico

Let us apply the least-squares formulae to a small set of data.

Example

Given the points (1;2)(1;\,2), (2;3,5)(2;\,3{,}5), (3;4)(3;\,4), (4;5,5)(4;\,5{,}5), (5;6)(5;\,6): xˉ=3,  yˉ=4,2,  xiyi=66,5,  xi2=55.\bar{x}=3,\;\bar{y}=4{,}2,\; \sum x_iy_i = 66{,}5,\; \sum x_i^2 = 55. m=566,51521555225=332,5315275225=17,550=0,95,q=4,20,953=1,35.m = \frac{5\cdot 66{,}5 - 15\cdot 21}{5\cdot 55 - 225} = \frac{332{,}5-315}{275-225} = \frac{17{,}5}{50} = \boxed{0{,}95},\qquad q = 4{,}2-0{,}95\cdot 3 = \boxed{1{,}35}. Line: y=0,95x+1,35y = 0{,}95\,x+1{,}35.

The graph shows the data (in red), the regression line (in blue) and the centroid (xˉ,yˉ)=(3;4,2)(\bar{x},\bar{y})=(3;\,4{,}2) through which the line passes (in green).

The five experimental points, the least-squares line and the centroid of the data.

Topics: Radicals
Concepts: Least squares · Linear regression
Skills: Calculating · Interpreting a graph · Plotting a graph