Sub topic 1
Starting point: simple linear regression in brief
Prerequisites
This chapter assumes you know descriptive statistics, the normal distribution, t-tests and p-values, and the meaning of slope and intercept in a straight-line fit. You should be able to read a regression output table.
Simple linear regression
A simple linear regression models a dependent variable Y with one independent variable X:
Y = b0 + b1X + e
The intercept b0 is the predicted value of Y when X is zero. The slope b1 is the expected change in Y for a one-unit increase in X. The term e is the error. Ordinary least squares (OLS) chooses b0 and b1 to minimize the sum of squared residuals.
The multiple regression model and partial slopes
Multiple regression adds more independent variables:
Y = b0 + b1X1 + b2X2 + ... + bkXk + e
Each slope bj is a partial slope. It gives the change in Y for a one-unit increase in Xj, holding the other X variables constant. A partial slope can differ from the slope you would get from a simple regression on Xj alone, because the other variables absorb part of the effect.
The assumptions behind the model
The standard errors and tests below are valid only when these assumptions hold:
- The relationship is linear in the parameters.
- The errors have a mean of zero and are uncorrelated with each X.
- The errors have constant variance (homoskedasticity).
- The errors are uncorrelated across observations.
- The errors are normally distributed, which matters in small samples.
- No independent variable is an exact linear combination of the others.
> Violating an assumption does not always bias the coefficients. It often biases the standard errors, so the t-tests and F-test can mislead you.
Testing individual coefficients with t-tests
To test H0: bj = 0, compute t = bj / s(bj), where s(bj) is the standard error of the estimate. With n observations and k independent variables, the degrees of freedom are n - k - 1. Reject H0 when the absolute t-statistic exceeds the critical value at your chosen significance level.
Testing coefficients jointly: the F-test and ANOVA table
The F-test asks whether all slopes are zero at once: H0: b1 = b2 = ... = bk = 0. The ANOVA table splits total variation into regression and residual parts:
| Source | Sum of squares | df | Mean square |
|---|---|---|---|
| Regression | SSR | k | MSR = SSR / k |
| Residual | SSE | n - k - 1 | MSE = SSE / (n - k - 1) |
The statistic is F = MSR / MSE, with numerator df k and denominator df n - k - 1. Reject H0 when F exceeds the critical value.
import numpy as np
import statsmodels.api as sm
rng = np.random.default_rng(42)
n = 200
x1 = rng.normal(size=n)
x2 = rng.normal(size=n)
y = 1.0 + 2.0 * x1 - 1.0 * x2 + rng.normal(size=n)
X = sm.add_constant(np.column_stack([x1, x2]))
model = sm.OLS(y, X).fit()
print(model.params)
print(model.tvalues)
print(model.fvalue, model.f_pvalue)Exercise
A regression has n = 60 observations and k = 3 independent variables. What are the degrees of freedom for each coefficient t-test, and what are the numerator and denominator degrees of freedom for the F-test?
Show answer
The t-test has 56 degrees of freedom (60 - 3 - 1). The F-test has numerator df 3 and denominator df 56, written F(3, 56).