STATHARBOR ANALYTICS · INTRODUCTION TO STATISTICS · CHAPTER 13
Multiple Linear Regression
Multiple regression extends simple linear regression by including multiple explanatory variables. This allows us to assess the influence of each predictor on the response while controlling for others. This chapter covers model specification, interpretation, diagnostics and variable selection, with examples and code in R, Python and Julia.
Model Formulation
Suppose we have a response variable and predictors . The multiple regression model is We collect the predictors in a design matrix and estimate the coefficients by least squares: .
Interpretation of Coefficients
Each coefficient represents the expected change in for a one–unit increase in , holding all other predictors constant. This “partial effect” interpretation differs from simple regression, where the effect of is not adjusted for other variables. Coefficients can change substantially when predictors are added or removed, especially when predictors are correlated (multicollinearity).
Adjusted and Model Fit
The coefficient of determination measures the proportion of variance explained by the model. However, increases as more predictors are added even if they contribute little. The adjusted penalises model complexity:
Example: Predicting House Prices
Consider a dataset containing house prices (), square footage () and number of bedrooms (). We fit a multiple regression model.
Worked example
Multiple regression in Python, R and Julia.
import pandas as pd
import statsmodels.api as sm
data = pd.DataFrame({
'price': [250, 300, 320, 360, 400],
'sqft': [1400, 1600, 1700, 1875, 2000],
'bedrooms': [3, 3, 4, 4, 5]
})
X = data[['sqft', 'bedrooms']]
X = sm.add_constant(X)
model = sm.OLS(data['price'], X).fit()
print(model.summary())
df <- data.frame(price = c(250,300,320,360,400),
sqft = c(1400,1600,1700,1875,2000),
bedrooms = c(3,3,4,4,5))
fit <- lm(price ~ sqft + bedrooms, data = df)
summary(fit)
using DataFrames, GLM
df = DataFrame(price=[250,300,320,360,400],
sqft=[1400,1600,1700,1875,2000],
bedrooms=[3,3,4,4,5])
lm_fit = lm(@formula(price ~ sqft + bedrooms), df)
coef(lm_fit)
The summaries show estimated coefficients for square footage and bedrooms. Each slope reflects the expected price increase per unit of the predictor, adjusting for the other variable.
Diagnostics
As with simple regression, we must check linearity, homoscedasticity and normality of errors. Additional issues arise in multiple regression:
Multicollinearity: predictors that are highly correlated make coefficient estimates unstable. Assess this using variance inflation factors (VIF). Consider combining correlated predictors or using principal components.
Influential Observations: outliers or high–leverage points can disproportionately influence the fit. Use Cook’s distance and leverage plots.
Model Specification: omitted variables and interactions can bias estimates. Explore residual plots and consider transformations or adding quadratic terms.
Variable Selection
Selecting a subset of predictors balances model complexity and predictive accuracy. Common approaches include:
Forward selection: start with no variables and add predictors sequentially based on criteria (e.g., AIC, BIC).
Backward elimination: start with all predictors and remove the least significant one at each step.
Regularisation: techniques such as ridge regression and the lasso shrink coefficients and perform variable selection; see Chapter [chap:regression_regularisation] (beyond scope of this introductory text).
Exercises
Practice
Use a public dataset (e.g., cars dataset with mpg, horsepower, weight) to fit a multiple regression predicting mpg. Interpret the coefficients. Compute the adjusted .
Simulate data with two predictors where one is highly correlated with the other. Fit multiple regression and compute VIF. Observe the instability in coefficient estimates.
Use forward selection to choose predictors for predicting house prices from square footage, bedrooms and age of house. Perform this in R or Python.
Show that the least–squares estimator minimises the sum of squared residuals. Derive its unbiasedness and variance under the model assumptions.
References
Montgomery DC, Peck EA, Vining GG. Introduction to Linear Regression Analysis. 5th ed. Wiley; 2012.
Kutner MH, Nachtsheim CJ, Neter J, Li W. Applied Linear Statistical Models. 5th ed. McGraw–Hill; 2005.
Fox J. Applied Regression Analysis and Generalized Linear Models. 3rd ed. Sage; 2015.