Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 17

Solving OLS Coefficients for Multiple Linear Regression

Recommended resources

Welcome to the next stage of our course. In our previous sessions, we focused on preparing our data for analysis—identifying outliers, handling missing values, and understanding the consequences of these cleaning steps. Now, with clean datasets, we can move from assessing single relationships with correlation to building more comprehensive explanatory models.

This lesson marks our entry into regression modeling. Your goal is to understand the relationships between variables, and multiple linear regression is a cornerstone for this. Our focus today is purely on the mechanics of finding the model's parameters. We will tackle the learning outcome of setting up a multiple linear regression model and solving the normal equations by hand for a small dataset. You'll work through the matrix algebra required to compute the Ordinary Least Squares (OLS) coefficients, building the foundational calculation skills we'll need for interpretation in the next lesson.

From Single Equation to Matrix Form

In your theoretical studies, you've seen the equation for a multiple linear regression model, which describes an outcome variable, , as a linear combination of several predictor variables, :

Here, the values are the coefficients we need to find, and is the error term for the -th observation. While this form is intuitive, it becomes cumbersome to solve for the coefficients when you have multiple predictors. A much more efficient approach, and the one required for a formal solution, is to use matrix algebra.

The entire system of equations for all observations in our dataset can be written compactly as:

Where:

  • is an vector of our observed outcomes.
  • is the design matrix, containing our predictor variables. A crucial detail is that its first column is filled with ones to account for the intercept term, .
  • is a vector of the unknown coefficients we want to estimate.
  • is an vector of the errors.

To solidify these concepts, the following video provides an excellent overview of setting up the model in matrix form and presents the ultimate formula we will be using.

Matrix Approach to Multiple Linear Regression

Please watch the following segments from the video "Matrix Approach to Multiple Linear Regression".

First, watch the section that explains how the familiar regression equation is translated into the matrix form. Pay close attention to how the design matrix X is constructed, particularly the purpose of the column of ones. Next, watch the segment that derives the solution. The principle of Ordinary Least Squares (OLS) is to minimize the sum of squared errors. The video shows how this minimization problem leads to what are known as the normal equations, and then to the final formula for calculating the coefficient vector, \hat{\beta}. This formula is the centerpiece of our lesson.

As the video explained, the OLS estimate for the coefficients, which we denote as , is found by solving the normal equations. This gives us the celebrated formula:

Here, denotes the transpose of matrix , and is the inverse of the matrix product . Our task is to compute this expression by hand for our two scenarios.


Numerical Example 1: Bra-Fitting Business

Scenario: You want to understand what factors contribute to a customer needing a significant change in their bra size during a fitting. You hypothesize that Age and the Years Since Last Fitting are key predictors for the Cup Size Change needed (measured as the number of cup sizes upward, e.g., +2 means the client's old bra was two cup sizes too small).

Data: You have collected data from four recent clients.

Client Cup Size Change (Y) Age (X1) Years Since Last Fitting (X2)
1 1 25 2
2 3 45 10
3 0 30 1
4 2 50 5

Our model is: .

Step 1: Construct the Y vector and X matrix

The vector contains the outcomes. The matrix contains a leading column of ones for the intercept , followed by the columns for our predictors and .

Step 2: Calculate and the products and

First, we find the transpose of :

Now, we perform the matrix multiplications:

Step 3: Calculate the inverse

This is the most calculation-intensive step. For a 3x3 matrix, the inverse is , where is the adjugate matrix (the transpose of the cofactor matrix).

  1. Determinant:


  2. Adjugate Matrix (result of cofactor calculation, then transposed):

  3. Inverse:

Step 4: Calculate the coefficient vector

Finally, we multiply the inverse by :

So, our estimated coefficient vector is . This gives us , , and . Note: The calculation shown here has a small discrepancy due to rounding the inverse matrix. A precise calculation yields , , and . The complexity highlights why computers are typically used, but the manual process is what solidifies the mechanics. For our purposes, understanding the process is key.


Numerical Example 2: Polyandrous Relationship Study

Scenario: For your research on polyandrous relationships, you want to model Relationship Satisfaction (on a 1-10 scale) based on the weekly Hours of Quality Time the hinge partner spends with the entire group and the average Frequency of Daily Communication (e.g., check-in texts) with each partner.

Data: You have data from four individuals in a vee relationship.

Person Satisfaction (Y) Quality Time (X1, hrs/wk) Communication (X2, avg/day)
1 8 10 5
2 6 5 10
3 9 12 8
4 7 8 2

Our model is: .

Step 1: Construct the Y vector and X matrix

Step 2: Calculate and

Step 3: Calculate the inverse

Again, we compute the determinant and adjugate.

  1. Determinant:

  2. Inverse (calculated using the adjugate method and dividing by the determinant):

Step 4: Calculate the coefficient vector

The calculation (again, subject to rounding) yields the coefficients , , and . The precise values are , , and , once more showing the sensitivity of the hand calculation.


Conclusion

In this lesson, you have performed the complete sequence of manual calculations to find the OLS coefficients for two multiple linear regression models. We have focused exclusively on the "how," grounding your understanding in the underlying matrix operations.

Key Takeaways:

  • Multiple linear regression models are most efficiently solved using matrix algebra.
  • The OLS solution is given by the formula .
  • The process involves setting up the vector and matrix (with its column of ones), computing the transpose , performing matrix multiplications to get and , finding the inverse of , and finally multiplying to get the coefficient vector .

You have now built the model and found its parameters. The next logical and crucial step is to understand what these numbers mean. In our next lesson, we will move from calculation to interpretation, exploring how to explain the marginal effect of each predictor while holding others constant, which is the key to unlocking the explanatory power of your models.