Mathematics/Statistics/Regression Lines

From Dev Wiki
Jump to navigation Jump to search

Template:ToDo

A regression line is effectively an attempt to fit some data to a straight line.

Basically, given some set of data points, you create a line that as closely as possible fits the data. This is accomplished by trying to minimize the total distance between all points and the line itself.

Since this is regression line is a standard straight line, it can be represented by a standard Failed to parse (Conversion error. Server ("https://wikimedia.org/api/rest_") reported: "Cannot get mml. Server problem."): {\displaystyle y=mx+b} equation.


Residuals

Given a single data point, a residual is the distance between that single point and the regression line.

A positive residual value indicates that the data point is somewhere above the regression line. A negative residual value indicates that the data point is somewhere below the regression line. Larger values indicate the point is farther away.

To calculate the residual for some point at Failed to parse (Conversion error. Server ("https://wikimedia.org/api/rest_") reported: "Cannot get mml. Server problem."): {\displaystyle (p_{x},p_{y})} , we have the following equation for some and Failed to parse (Conversion error. Server ("https://wikimedia.org/api/rest_") reported: "Cannot get mml. Server problem."): {\displaystyle b} from our regression line:

Failed to parse (Conversion error. Server ("https://wikimedia.org/api/rest_") reported: "Cannot get mml. Server problem."): {\displaystyle residual_{p}=p_{y}-(m(p_{x})+b)}


We can then take this a step further and combine all residuals in our dataset to get an overall view of "how closely the regression line matches our dataset".

Failed to parse (Conversion error. Server ("https://wikimedia.org/api/rest_") reported: "Cannot get mml. Server problem."): {\displaystyle \sum _{i=1}^{n}(r_{i})^{2}}

Squaring means means that negative residual values don't cancel out positive values. It also means points that are farther away from the line end up with more weight than points closer to the line.


Least Squares Regression

Least Squares Regression is one of the more popular ways to minimize the sum of all residuals in our dataset. We can calculate this regression line with a few steps:

First, we note that the equation we want to calculate is ultimately some form of Failed to parse (Conversion error. Server ("https://wikimedia.org/api/rest_") reported: "Cannot get mml. Server problem."): {\displaystyle y=mx+b} .

Our regression line will always go through the point Failed to parse (Conversion error. Server ("https://wikimedia.org/api/rest_") reported: "Cannot get mml. Server problem."): {\displaystyle ({\bar {x}},{\bar {y}})} , which denotes the means of our x and y. So it's safe to use that as the and in our equation. From there, we can move to calculating our and Failed to parse (Conversion error. Server ("https://wikimedia.org/api/rest_") reported: "Cannot get mml. Server problem."): {\displaystyle b} .

Calculating our M and B

Next, we can calculate line slope with the equation

Failed to parse (Conversion error. Server ("https://wikimedia.org/api/rest_") reported: "Cannot get mml. Server problem."): {\displaystyle m=r{\frac {S_{y}}{S_{x}}}}

Where

  • is the correlation coefficient for our dataset.
  • Failed to parse (Conversion error. Server ("https://wikimedia.org/api/rest_") reported: "Cannot get mml. Server problem."): {\displaystyle S_{y}} is the standard deviation of our x.
  • Failed to parse (Conversion error. Server ("https://wikimedia.org/api/rest_") reported: "Cannot get mml. Server problem."): {\displaystyle S_{x}} is the standard deviation of our y.


We can then proceed to get our Failed to parse (Conversion error. Server ("https://wikimedia.org/api/rest_") reported: "Cannot get mml. Server problem."): {\displaystyle b} with simple algebra:

Failed to parse (Conversion error. Server ("https://wikimedia.org/api/rest_") reported: "Cannot get mml. Server problem."): {\displaystyle b=y-mx}

where

  • is the mean of our x.
  • is the mean of our y.
  • Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle m} is the m we just calculated, above.


Putting all of this together, we can replace the m and b in our Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle y = mx + b} , which will give us a line equation for our regression.

For further explanation, see this Khan Academy video.