Chapter 9 Parameter Estimation in MLR
9.1 Estimation of in MLR
The equation for the multiple linear regression (MLR) model is:
To estimate the parameters, we follow the same strategy as in SLR: minimizing the sum of squared residuals .
Graphically, this yields the hyperplane (the -dimensional analogue of a plane) that best fits the data, by minimizing the distance between each point and the hyperplane. However, unlike SLR for which we can draw a scatterplot and regression line, visualizing this hyperplane is difficult. Instead, we are primarily limited to algebraic representations of the model.
Minimizing the sum of squared residuals means minimizing the function This is a higher-dimension analogue to (3.1). To find the values that minimize (9.1), we differentiate with respect to all ’s and solve a system of equations. However, solving this system of equations gets tedious, so we will not go into the details of that approach here. A simpler and more scalable approach is to use a matrix representation of the model.
9.2 Matrix form of the MLR model
9.2.1 Random Vectors
Before introducing the matrix form of the MLR model, we first briefly review notation for random vectors.
Definition 9.1 An -dimensional random vector is a vector, each component of which is a random variable.
Definition 9.2 The mean vector is a vector whose elements are the element-wise mean of a random vector, assuming those means exist.
Definition 9.3 The covariance matrix (or variance-covariance matrix) is a matrix containing the variances and covariances of the elements in a random vector (assuming ).
An important property of the covariance matrix is that if is a matrix and is an -vector, (a matrix).
9.2.2 Matrix form of the MLR model
To write the MLR model in matrix form, we translate each component into a vector or matrix. For the predictor variables , we create an covariate matrix:
The th row in corresponds to the th observation, and the th column corresponds to the th predictor variable (where corresponds to the intercept). When needed, we can let denote the th column of . Note that .
We then write the as a vector: .
We write the ’s as an vector: and write the ’s as an vector: .
Together, these pieces give the MLR model in matrix form:
To see the connection to the non-matrix form, we can multiply out the pieces to get:
9.2.3 Assumptions of MLR model
The MLR model assumptions are:
- is “full-rank”
Assumption 1 is the same as the assumption from SLR. Assumption 2 implies constant variance () and no correlation between the ’s (). Assumption 3 is discussed in detail below (Section 9.4).
9.3 Estimation of in MLR (Matrix form)
In the matrix form of the MLR model, we can write the vector of residuals as . Minimizing the sum of square residuals becomes minimizing . This criterion can be re-written:
We minimize this by differentiating with respect to : and then setting the derivative to zero: This gives the “normal equations” for MLR: And by multiplying each side by the inverse of , we obtain the equation for the least-squares estimator of :
9.4 Why must X be full-rank?
In the assumptions above, we said that must be full-rank. Conceptually, this means that each column of is providing different information; no information is duplicated in the chosen predictor variables. For example, including both speed in miles per hour and kilometers per hour in an MLR model is redundant.
Mathematically, this assumption means that the columns of are linearly independent, so the dimension of the column space of is equal to the number of columns in . For example, if , then the matrix is not full rank (it has rank = 3) because the column can be written as a linear combination of columns and .
The underlying reason for this assumption is because we need to be able to find the inverse of to compute . If is less than full rank, then does not exist.
9.5 Fitting MLR in R
To fit a MLR model in R
, we again use the lm()
command. To include multiple predictor variables in the model, separate them by +
: y ~ x1 + x2 + x3
.
As with SLR, the intercept is automatically included.
Detailed output can be obtained from either tidy()
## # A tibble: 4 × 5
## term estimate std.error statistic p.value
## <chr> <dbl> <dbl> <dbl> <dbl>
## 1 (Intercept) -5434. 287. -19.0 1.05e-54
## 2 flipper_length_mm 48.2 1.84 26.2 1.94e-82
## 3 bill_length_mm -5.20 4.86 -1.07 2.85e- 1
## 4 sexmale 359. 41.6 8.63 2.73e-16
or summary()
:
##
## Call:
## lm(formula = body_mass_g ~ flipper_length_mm + bill_length_mm +
## sex, data = penguins)
##
## Residuals:
## Min 1Q Median 3Q Max
## -878.71 -246.26 -0.71 226.67 1061.40
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -5433.534 286.558 -18.961 < 2e-16 ***
## flipper_length_mm 48.209 1.841 26.179 < 2e-16 ***
## bill_length_mm -5.201 4.860 -1.070 0.285
## sexmale 358.631 41.572 8.627 2.73e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 355.8 on 329 degrees of freedom
## (11 observations deleted due to missingness)
## Multiple R-squared: 0.8065, Adjusted R-squared: 0.8047
## F-statistic: 457.1 on 3 and 329 DF, p-value: < 2.2e-16
9.6 Properties of OLS Estimators
As with SLR, it is useful to understand the distributional properties of . It is straightforward to show that is unbiased: This tell us that assuming the model is correct, on average will be equal to . This doesn’t mean it will be true for any particular dataset, but in repeated experiments it would be right on average.
What about the variance of ?
Recall that if is a matrix and is an -vector, (a matrix).
To find the covariance matrix for , we use the property . This allows us to compute the variance matrix as:
Some important facts about the matrix :
- The diagonal elements of are the variances of each .
- The off-diagonal elements provide the covariances of the elements of .
The form of is a multivariate extension of from SLR. Now, instead of just considering the spread of on the variance of , the variability is also impacted by other variables. This means that the correlation between two predictor variables can impact the uncertainty (and thus confidence intervals) of both point estimates. This will be important when we return to multicollinearity in Section 15.
9.7 Fitted values for MLR
Fitted values for the MLR model are .In matrix form, this is:
Similarly, we can write the residuals as:
9.8 Hat Matrix
The matrix is called the `hat’ matrix. The name comes from its use in calculating fitted values (putting the “hat” on the ’s).
is important because it captures the relationships between the predictor variables (’s). The diagonal elements of are especially useful in quantifying leverage and influence (Section 13).
Mathematically, is a symmetric, idempotent matrix that projects onto the column space of . These attributes make foundational to the theory of linear models, although most of the details are outside the scope of this text.
9.9 Estimating
Like in SLR, the parameter represents the variance of the error above and below the “line” (actually a hyperplane) in MLR. Once again, we can estimate using :
There are degrees of freedom associated with , since there are estimated ’s (). For those who are interested in additional theory, the rank of is , which is how this degrees of freedom is derived.
Our estimator for is then:
9.10 Estimating Var
To estimate , we just plug in in for in the formula for . The square-root of the diagonal elements of are the standard errors of .
In R, the vcov
function will compute :
## (Intercept) flipper_length_mm bill_length_mm sexmale
## (Intercept) 82115.6880 -434.680727 105.511986 1940.88100
## flipper_length_mm -434.6807 3.391103 -5.572842 -3.27875
## bill_length_mm 105.5120 -5.572842 23.620806 -48.95908
## sexmale 1940.8810 -3.278750 -48.959084 1728.20296
You can compute standard errors from :
## (Intercept) flipper_length_mm bill_length_mm sexmale
## 286.558350 1.841495 4.860124 41.571661
## # A tibble: 4 × 5
## term estimate std.error statistic p.value
## <chr> <dbl> <dbl> <dbl> <dbl>
## 1 (Intercept) -5434. 287. -19.0 1.05e-54
## 2 flipper_length_mm 48.2 1.84 26.2 1.94e-82
## 3 bill_length_mm -5.20 4.86 -1.07 2.85e- 1
## 4 sexmale 359. 41.6 8.63 2.73e-16