
In statistics, linear regression is a model that estimates the relationship between a scalar response (dependent variable) and one or more explanatory variables (regressor or independent variable). A model with exactly one explanatory variable is a simple linear regression; a model with two or more explanatory variables is a multiple linear regression.[1] This term is distinct from multivariate linear regression, which predicts multiple correlated dependent variables rather than a single dependent variable.[2]
In linear regression, the relationships are modeled using linear predictor functions whose unknown model parameters are estimated from the data. Most commonly, the conditional mean of the response given the values of the explanatory variables (or predictors) is assumed to be an affine function of those values; less commonly, the conditional median or some other quantile is used. Like all forms of regression analysis, linear regression focuses on the conditional probability distribution of the response given the values of the predictors, rather than on the joint probability distribution of all of these variables, which is the domain of multivariate analysis.
Linear regression is also a type of machine learning algorithm, more specifically a supervised algorithm, that learns from the labelled datasets and maps the data points to the most optimized linear functions that can be used for prediction on new datasets.[3]
Linear regression was the first type of regression analysis to be studied rigorously, and to be used extensively in practical applications. This is because models which depend linearly on their unknown parameters are easier to fit than models which are non-linearly related to their parameters and because the statistical properties of the resulting estimators are easier to determine.
Linear regression has many practical uses. Most applications fall into one of the following two broad categories:
Linear regression models are often fitted using the least squares approach, but they may also be fitted in other ways, such as by minimizing the "lack of fit" in some other norm (as with least absolute deviations regression), or by minimizing a penalized version of the least squares cost function as in ridge regression (L2-norm penalty) and lasso (L1-norm penalty). Use of the Mean Squared Error (MSE) as the cost on a dataset that has many large outliers, can result in a model that fits the outliers more than the true data due to the higher importance assigned by MSE to large errors. So, cost functions that are robust to outliers should be used if the dataset has many large outliers. Conversely, the least squares approach can be used to fit models that are not linear models. Thus, although the terms "least squares" and "linear model" are closely linked, they are not synonymous.
\{yi,xi1,\ldots,xip
| n | |
| \} | |
| i=1 |
Often these n equations are stacked together and written in matrix notation as
y=X\boldsymbol\beta+\boldsymbol\varepsilon,
y=\begin{bmatrix}y1\ y2\ \vdots\ yn\end{bmatrix},
X=\begin{bmatrix}
| T | |
| x | |
| 1 |
| T | |
| \ x | |
| 2 |
\ \vdots
| T | |
| \ x | |
| n |
\end{bmatrix} =\begin{bmatrix}1&x11& … &x1p\\ 1&x21& … &x2p\\ \vdots&\vdots&\ddots&\vdots\\ 1&xn1& … &xnp\end{bmatrix},
\boldsymbol\beta=\begin{bmatrix}\beta0\ \beta1\ \beta2\ \vdots\ \betap\end{bmatrix}, \boldsymbol\varepsilon=\begin{bmatrix}\varepsilon1\ \varepsilon2\ \vdots\ \varepsilonn\end{bmatrix}.
y
yi (i=1,\ldots,n)
\hat{y}
X
xi ⋅
x ⋅
X
xi0=1
i=1,\ldots,n
\boldsymbol\beta
(p+1)
\beta0
\boldsymbol\beta
\boldsymbol\varepsilon
\varepsiloni
Fitting a linear model to a given data set usually requires estimating the regression coefficients
\boldsymbol\beta
\boldsymbol\varepsilon=y-X\boldsymbol\beta
| 2 | |
| \|\boldsymbol\varepsilon\| | |
| 2 |
\boldsymbol\varepsilon
Consider a situation where a small ball is being tossed up in the air and then we measure its heights of ascent hi at various moments in time ti. Physics tells us that, ignoring the drag, the relationship can be modeled as
hi=\beta1ti+\beta2
| 2 | |
| t | |
| i |
+\varepsiloni,
hi=
| T | |
| x | |
| i\boldsymbol\beta |
+\varepsiloni.
See main article: Generalized least squares. When estimating the parameters of linear regression models with standard estimation techniques such as ordinary least squares, it is necessary to make a number of assumptions about the predictor variables, the response variable and their relationship, to get estimators that are unbiased in finite sample. Numerous extensions have been developed that allow each of these assumptions to be relaxed (reduced to a weaker form), and in some cases eliminated entirely. Generally these extensions require more data or modelling assumptions to produce an equally precise model[4] .
A fitted linear regression model can be used to identify the relationship between a single predictor variable xj and the response variable y when all the other predictor variables in the model are "held fixed". Specifically, the interpretation of βj is the expected change in y for a one-unit change in xj when the other covariates are held fixed—that is, the expected value of the partial derivative of y with respect to xj. This is sometimes called the unique effect of xj on y. In contrast, the marginal effect of xj on y can be assessed using a correlation coefficient or simple linear regression model relating only xj to y; this effect is the total derivative of y with respect to xj.
Care must be taken when interpreting regression results, as some of the regressors may not allow for marginal changes (such as dummy variables, or the intercept term), while others cannot be held fixed (recall the example from the introduction: it would be impossible to "hold ti fixed" and at the same time change the value of ti2).
It is possible that the unique effect be nearly zero even when the marginal effect is large. This may imply that some other covariate captures all the information in xj, so that once that variable is in the model, there is no contribution of xj to the variation in y. Conversely, the unique effect of xj can be large while its marginal effect is nearly zero. This would happen if the other covariates explained a great deal of the variation of y, but they mainly explain variation in a way that is complementary to what is captured by xj. In this case, including the other variables in the model reduces the part of the variability of y that is unrelated to xj, thereby strengthening the apparent relationship with xj.
The meaning of the expression "held fixed" may depend on how the values of the predictor variables arise. If the experimenter directly sets the values of the predictor variables according to a study design, the comparisons of interest may literally correspond to comparisons among units whose predictor variables have been "held fixed" by the experimenter. Alternatively, the expression "held fixed" can refer to a selection that takes place in the context of data analysis. In this case, we "hold a variable fixed" by restricting our attention to the subsets of the data that happen to have a common value for the given predictor variable. This is the only interpretation of "held fixed" that can be used in an observational study.
The notion of a "unique effect" is appealing when studying a complex system where multiple interrelated components influence the response variable. In some cases, it can literally be interpreted as the causal effect of an intervention that is linked to the value of a predictor variable. However, it has been argued that in many cases multiple regression analysis fails to clarify the relationships between the predictor variables and the response variable when the predictors are correlated with each other and are not assigned following a study design.[5]
Numerous extensions of linear regression have been developed, which allow some or all of the assumptions underlying the basic model to be relaxed.
The simplest case of a single scalar predictor variable x and a single scalar response variable y is known as simple linear regression. The extension to multiple and/or vector-valued predictor variables (denoted with a capital X) is known as multiple linear regression, also known as multivariable linear regression (not to be confused with multivariate linear regression).[6]
Multiple linear regression is a generalization of simple linear regression to the case of more than one independent variable, and a special case of general linear models, restricted to one dependent variable. The basic model for multiple linear regression is
Yi=\beta0+\beta1Xi1+\beta2Xi2+\ldots+\betapXip+\epsiloni
for each observation .
In the formula above we consider n observations of one dependent variable and p independent variables. Thus, Yi is the ith observation of the dependent variable, Xij is ith observation of the jth independent variable, j = 1, 2, ..., p. The values βj represent parameters to be estimated, and εi is the ith independent identically distributed normal error.
In the more general multivariate linear regression, there is one equation of the above form for each of m > 1 dependent variables that share the same set of explanatory variables and hence are estimated simultaneously with each other:
Yij=\beta0j+\beta1jXi1+\beta2jXi2+\ldots+\betapjXip+\epsilonij
for all observations indexed as i = 1, ..., n and for all dependent variables indexed as j = 1, ..., m.
Nearly all real-world regression models involve multiple predictors, and basic descriptions of linear regression are often phrased in terms of the multiple regression model. Note, however, that in these cases the response variable y is still a scalar. Another term, multivariate linear regression, refers to cases where y is a vector, i.e., the same as general linear regression.
The general linear model considers the situation when the response variable is not a scalar (for each observation) but a vector, yi. Conditional linearity of
E(y\midxi)=x
| TB | |
| i |
Various models have been created that allow for heteroscedasticity, i.e. the errors for different response variables may have different variances. For example, weighted least squares is a method for estimating linear regression models when the response variables may have different error variances, possibly with correlated errors. (See also Weighted linear least squares, and Generalized least squares.) Heteroscedasticity-consistent standard errors is an improved method for use with uncorrelated but potentially heteroscedastic errors.
The Generalized linear model (GLM) is a framework for modeling response variables that are bounded or discrete. This is used, for example:
Generalized linear models allow for an arbitrary link function, g, that relates the mean of the response variable(s) to the predictors:
E(Y)=g-1(XB)
(-infty,infty)
Some common examples of GLMs are:
Single index models allow some degree of nonlinearity in the relationship between x and y, while preserving the central role of the linear predictor β′x as in the classical linear regression model. Under certain conditions, simply applying OLS to data from a single-index model will consistently estimate β up to a proportionality constant.[7]
Hierarchical linear models (or multilevel regression) organizes the data into a hierarchy of regressions, for example where A is regressed on B, and B is regressed on C. It is often used where the variables of interest have a natural hierarchical structure such as in educational statistics, where students are nested in classrooms, classrooms are nested in schools, and schools are nested in some administrative grouping, such as a school district. The response variable might be a measure of student achievement such as a test score, and different covariates would be collected at the classroom, school, and school district levels.
Errors-in-variables models (or "measurement error models") extend the traditional linear regression model to allow the predictor variables X to be observed with error. This error causes standard estimators of β to become biased. Generally, the form of bias is an attenuation, meaning that the effects are biased toward zero.
In a multiple linear regression model
y=\beta0+\beta1x1+ … +\betapxp+\varepsilon,
\betaj
xj
xj
y
xj
xj
xj
\betaj
xj
For a group of predictor variables, say,
\{x1,x2,...,xq\}
\xi(w)
\xi(w)=w1\beta1+w2\beta2+...+wq\betaq,
w=(w1,w2,...,w
| \intercal | |
| q) |
{wj}
\xi(w)
\xi(w)
y
x1,x2,...,xq
w1,w2,...,wq
i
q=1
ii
wi=1
wj=0
j ≠ i
\xi(w)
q
(x1,x2,...,
| \intercal | |
| x | |
| q) |
Group effects provide a means to study the collective impact of strongly correlated predictor variables in linear regression models. Individual effects of such variables are not well-defined as their parameters do not have good interpretations. Furthermore, when the sample size is not large, none of their parameters can be accurately estimated by the least squares regression due to the multicollinearity problem. Nevertheless, there are meaningful group effects that have good interpretations and can be accurately estimated by the least squares regression. A simple way to identify these meaningful group effects is to use an all positive correlations (APC) arrangement of the strongly correlated variables under which pairwise correlations among these variables are all positive, and standardize all
p
\{x1,x2,...,xq\}
y'
y
xj'
xj
y'=\beta1'x1'+ … +\betap'xp'+\varepsilon.
\betaj
\beta0
\betaj'
\{x1',x2',...,xq'\}
\{x1',x2',...,xq'\}
\xi'(w)=w1\beta1'+w2\beta2'+...+wq\betaq',
\hat{\xi}'(w)=w1\hat{\beta}1'+w2\hat{\beta}2'+...+wq\hat{\beta}q',
\hat{\beta}j'
\betaj'
q
| \xi | ||||
|
(\beta1'+\beta2'+...+\betaq'),
y'
xj'
(1/q)
\xiA
\betaj'
\hat{\beta}j'
Not all group effects are meaningful or can be accurately estimated. For example,
\beta1'
w1=1
wj=0
j ≠ 1
\hat{\beta}'1
q
w
wj\geq0
Applications of the group effects include (1) estimation and inference for meaningful group effects on the response variable, (2) testing for "group significance" of the
q
H0:\xiA=0
H1:\xiA ≠ 0
A group effect of the original variables
\{x1,x2,...,xq\}
\{x1',x2',...,xq'\}
In Dempster–Shafer theory, or a linear belief function in particular, a linear regression model may be represented as a partially swept matrix, which can be combined with similar matrices representing observations and other assumed normal distributions and state equations. The combination of swept or unswept matrices provides an alternative method for estimating linear regression models.
A large number of procedures have been developed for parameter estimation and inference in linear regression. These methods differ in computational simplicity of algorithms, presence of a closed-form solution, robustness with respect to heavy-tailed distributions, and theoretical assumptions needed to validate desirable statistical properties such as consistency and asymptotic efficiency.
Some of the more common estimation techniques for linear regression are summarized below.
See main article: Linear least squares. Assuming that the independent variables are
\vec{xi}=
| i, | |
| \left[x | |
| 1 |
| i, | |
| x | |
| 2 |
\ldots,
| i\right] | |
| x | |
| m |
\vec{\beta}=\left[\beta0,\beta1,\ldots,\betam\right]
yi ≈ \beta0+
| m | |
| \sum | |
| j=1 |
\betaj x
| i | |
| x | |
| j |
\vec{xi}
\vec{xi}=\left[1,
| i, | |
| x | |
| 1 |
| i, | |
| x | |
| 2 |
\ldots,
| i\right] | |
| x | |
| m |
yi
yi ≈
| m | |
| \sum | |
| j=0 |
\betaj x
| i | |
| x | |
| j |
=\vec{\beta} ⋅ \vec{xi}
In the least-squares setting, the optimum parameter vector is defined as such that minimizes the sum of mean squared loss:
\vec{\hat{\beta}}=\underset{\vec{\beta}}argminL\left(D,\vec{\beta}\right)=\underset{\vec{\beta}}argmin
| n | |
| \sum | |
| i=1 |
\left(\vec{\beta} ⋅ \vec{xi}-
| 2 | |
| y | |
| i\right) |
Now putting the independent and dependent variables in matrices
X
Y
\begin{align} L\left(D,\vec{\beta}\right) &=\|X\vec{\beta}-Y\|2\\ &=\left(X\vec{\beta}-Y\right)sf{T}\left(X\vec{\beta}-Y\right)\\ &=Ysf{T}Y-Ysf{T}X\vec{\beta}-\vec{\beta}sf{T}Xsf{T}Y+\vec{\beta}sf{T}Xsf{T}X\vec{\beta} \end{align}
As the loss function is convex, the optimum solution lies at gradient zero. The gradient of the loss function is (using Denominator layout convention):
\begin{align}
| \partialL\left(D,\vec{\beta | |
| \right)}{\partial\vec{\beta}} |
&=
| \partial\left(Ysf{T | |
| Y |
-Ysf{T}X\vec{\beta}-\vec{\beta}sf{T}Xsf{T}Y+\vec{\beta}sf{T}Xsf{T}X\vec{\beta}\right)}{\partial\vec{\beta}}\\ &=-2Xsf{T}Y+2Xsf{T}X\vec{\beta} \end{align}
Setting the gradient to zero produces the optimum parameter:
\begin{align} -2Xsf{T}Y+2Xsf{T}X\vec{\beta}&=0\\ ⇒ Xsf{T}X\vec{\beta}&=Xsf{T}Y\\ ⇒ \vec{\hat{\beta}}&=\left(Xsf{T}X\right)-1Xsf{T}Y \end{align}
Note: The
\hat{\beta}
Linear least squares methods include mainly:
Maximum likelihood estimation can be performed when the distribution of the error terms is known to belong to a certain parametric family ƒθ of probability distributions.[10] When fθ is a normal distribution with zero mean and variance θ, the resulting estimate is identical to the OLS estimate. GLS estimates are maximum likelihood estimates when ε follows a multivariate normal distribution with a known covariance matrix.Let's denote each data point by
(\vec{xi},yi)
\vec{\beta}
D
L(D,\vec{\beta})=\sumi(yi-\vec{\beta} ⋅
| 2 | |
| \vec{x | |
| i}) |
As shown below the same optimal parameter that minimizes
L(D,\vec{\beta})
y
\vec{x}
\begin{align} H(D,\vec{\beta})&=
| n | |
| \prod | |
| i=1 |
Pr(yi|\vec{xi};\vec{\beta},\sigma)\ &=
| n | |
| \prod | |
| i=1 |
| 1 | \sigma}\exp\left(- | |
| \sqrt{2\pi |
| \left(yi-\vec{\beta | |
⋅ \vec{xi}\right)2}{2\sigma2}\right) \end{align}
Now, we need to look for a parameter that maximizes this likelihood function. Since the logarithmic function is strictly increasing, instead of maximizing this function, we can also maximize its logarithm and find the optimal parameter that way.
\begin{align} I(D,\vec{\beta})&=
| n | |
| log\prod | |
| i=1 |
Pr(yi|\vec{xi};\vec{\beta},\sigma)\ &=
| n | |
| log\prod | |
| i=1 |
| 1 | \sigma}\exp\left(- | |
| \sqrt{2\pi |
| \left(yi-\vec{\beta | |
⋅ \vec{xi}\right)2}{2\sigma2}\right)\ &=nlog
| 1 | |
| \sqrt{2\pi |
\sigma}-
| 1 | |
| 2\sigma2 |
| n | |
| \sum | |
| i=1 |
\left(yi-\vec{\beta} ⋅ \vec{xi}\right)2 \end{align}
The optimal parameter is thus equal to:
\begin{align} \underset{\vec{\beta}}argmaxI(D,\vec{\beta})&=\underset{\vec{\beta}}argmax\left(nlog
| 1 | |
| \sqrt{2\pi |
\sigma}-
| 1 | |
| 2\sigma2 |
| n | |
| \sum | |
| i=1 |
\left(yi-\vec{\beta} ⋅ \vec{xi}\right)2\right)\ &=\underset{\vec{\beta}}argmin
| n | |
| \sum | |
| i=1 |
\left(yi-\vec{\beta} ⋅ \vec{xi}\right)2\ &=\underset{\vec{\beta}}argminL(D,\vec{\beta})\ &=\vec{\hat{\beta}} \end{align}
In this way, the parameter that maximizes
H(D,\vec{\beta})
L(D,\vec{\beta})
Ridge regression[12] [13] [14] and other forms of penalized estimation, such as Lasso regression,[15] deliberately introduce bias into the estimation of β in order to reduce the variability of the estimate. The resulting estimates generally have lower mean squared error than the OLS estimates, particularly when multicollinearity is present or when overfitting is a problem. They are generally used when the goal is to predict the value of the response variable y for values of the predictors x that have not yet been observed. These methods are not as commonly used when the goal is inference, since it is difficult to account for the bias.
Least absolute deviation (LAD) regression is a robust estimation technique in that it is less sensitive to the presence of outliers than OLS (but is less efficient than OLS when no outliers are present). It is equivalent to maximum likelihood estimation under a Laplace distribution model for ε.[16]
If we assume that error terms are independent of the regressors,
\varepsiloni\perpxi
Linear regression is widely used in biological, behavioral and social sciences to describe possible relationships between variables. It ranks as one of the most important tools used in these disciplines.
See main article: Trend estimation. A trend line represents a trend, the long-term movement in time series data after other components have been accounted for. It tells whether a particular data set (say GDP, oil prices or stock prices) have increased or decreased over the period of time. A trend line could simply be drawn by eye through a set of data points, but more properly their position and slope is calculated using statistical techniques like linear regression. Trend lines typically are straight lines, although some variations use higher degree polynomials depending on the degree of curvature desired in the line.
Trend lines are sometimes used in business analytics to show changes in data over time. This has the advantage of being simple. Trend lines are often used to argue that a particular action or event (such as training, or an advertising campaign) caused observed changes at a point in time. This is a simple technique, and does not require a control group, experimental design, or a sophisticated analysis technique. However, it suffers from a lack of scientific validity in cases where other potential changes can affect the data.
Early evidence relating tobacco smoking to mortality and morbidity came from observational studies employing regression analysis. In order to reduce spurious correlations when analyzing observational data, researchers usually include several variables in their regression models in addition to the variable of primary interest. For example, in a regression model in which cigarette smoking is the independent variable of primary interest and the dependent variable is lifespan measured in years, researchers might include education and income as additional independent variables, to ensure that any observed effect of smoking on lifespan is not due to those other socio-economic factors. However, it is never possible to include all possible confounding variables in an empirical analysis. For example, a hypothetical gene might increase mortality and also cause people to smoke more. For this reason, randomized controlled trials are often able to generate more compelling evidence of causal relationships than can be obtained using regression analyses of observational data. When controlled experiments are not feasible, variants of regression analysis such as instrumental variables regression may be used to attempt to estimate causal relationships from observational data.
The capital asset pricing model uses linear regression as well as the concept of beta for analyzing and quantifying the systematic risk of an investment. This comes directly from the beta coefficient of the linear regression model that relates the return on the investment to the return on all risky assets.
See main article: Econometrics. Linear regression is the predominant empirical tool in economics. For example, it is used to predict consumption spending,[23] fixed investment spending, inventory investment, purchases of a country's exports, spending on imports,[24] the demand to hold liquid assets,[25] labor demand, and labor supply.[26]
Linear regression finds application in a wide range of environmental science applications such as land use,[27] infectious diseases,[28] and air pollution.[29] For example, linear regression can be used to predict the changing effects of car pollution.[30] One notable example of this application in infectious diseases is the flattening the curve strategy emphasized early in the COVID-19 pandemic, where public health officials dealt with sparse data on infected individuals and sophisticated models of disease transmission to characterize the spread of COVID-19.[31]
Linear regression is commonly used in building science field studies to derive characteristics of building occupants. In a thermal comfort field study, building scientists usually ask occupants' thermal sensation votes, which range from -3 (feeling cold) to 0 (neutral) to +3 (feeling hot), and measure occupants' surrounding temperature data. A neutral or comfort temperature can be calculated based on a linear regression between the thermal sensation vote and indoor temperature, and setting the thermal sensation vote as zero. However, there has been a debate on the regression direction: regressing thermal sensation votes (y-axis) against indoor temperature (x-axis) or the opposite: regressing indoor temperature (y-axis) against thermal sensation votes (x-axis).[32]
Linear regression plays an important role in the subfield of artificial intelligence known as machine learning. The linear regression algorithm is one of the fundamental supervised machine-learning algorithms due to its relative simplicity and well-known properties.[33]
Isaac Newton is credited with inventing "a certain technique known today as linear regression analysis" in his work on equinoxes in 1700, and wrote down the first of the two normal equations of the ordinary least squares method.[34] [35] The Least squares linear regression, as a means of finding a good rough linear fit to a set of points was performed by Legendre (1805) and Gauss (1809) for the prediction of planetary movement. Quetelet was responsible for making the procedure well-known and for using it extensively in the social sciences.[36]