Quiz 2

Introduction to Linear Regression

355 words
2 min read
Python Week 1: the first filter for runtime behavior
Visual companion
Python
Type and operator map

Python Week 1: the first filter for runtime behavior

View
Revision summary

What this note is really saying

Short form

# Introduction to Linear Regression ## 🎯 Learning Objectives - Formulate the simple linear regression model - Estimate parameters using **ordinary least squares (OLS)** - Interpret regression coefficients - Understand assumptions underpinning the model * * * ## 1.1 Intuition: Finding the Line of Best Fit Given a sc...

Introduction to Linear Regression

🎯 Learning Objectives

  • Formulate the simple linear regression model
  • Estimate parameters using ordinary least squares (OLS)
  • Interpret regression coefficients
  • Understand assumptions underpinning the model

1.1 Intuition: Finding the Line of Best Fit

Given a scatter plot of points (xi,yi)(x_i, y_i), we want to find the line that best predicts yy from xx. "Best" means minimising the sum of squared vertical distances.
🔑 Key Insight: Regression is about explaining variation in an outcome variable yy using one or more predictor variables xx.

1.2 The Simple Linear Regression Model

yi=β0+β1xi+εiy_i = \beta_0 + \beta_1 x_i + \varepsilon_i
Where:
  • yiy_i = response (dependent) variable
  • xix_i = predictor (independent) variable
  • β0\beta_0 = intercept (expected yy when x=0x = 0)
  • β1\beta_1 = slope (expected change in yy per unit change in xx)
  • εi\varepsilon_i = random error term, εiN(0,σ2)\varepsilon_i \sim N(0, \sigma^2)

1.3 Least Squares Estimation

Minimise S(β0,β1)=i=1n(yiβ0β1xi)2S(\beta_0, \beta_1) = \sum_{i=1}^n (y_i - \beta_0 - \beta_1 x_i)^2 Normal equations:
Sβ0=2(yiβ0β1xi)=0\frac{\partial S}{\partial \beta_0} = -2\sum(y_i - \beta_0 - \beta_1 x_i) = 0 Sβ1=2xi(yiβ0β1xi)=0\frac{\partial S}{\partial \beta_1} = -2\sum x_i(y_i - \beta_0 - \beta_1 x_i) = 0
Solution:
β^1=(xixˉ)(yiyˉ)(xixˉ)2=SxySxx\hat{\beta}_1 = \frac{\sum (x_i - \bar{x})(y_i - \bar{y})}{\sum (x_i - \bar{x})^2} = \frac{S_{xy}}{S_{xx}} β^0=yˉβ^1xˉ\hat{\beta}_0 = \bar{y} - \hat{\beta}_1 \bar{x}

1.4 Interpretation

  • β^1\hat{\beta}_1 = "a one-unit increase in xx is associated with a β^1\hat{\beta}_1 change in yy"
  • β^0\hat{\beta}_0 = "when x=0x = 0, the predicted yy is β^0\hat{\beta}_0" (may not be meaningful if x=0x=0 is outside data range)

✅ Practice Questions

Q1: Given data: (1,2), (2,4), (3,5), find β^0\hat{\beta}_0 and β^1\hat{\beta}_1.
Solution
xˉ=2\bar{x} = 2, yˉ=11/33.67\bar{y} = 11/3 \approx 3.67 Sxx=(12)2+(22)2+(32)2=1+0+1=2S_{xx} = (1-2)^2 + (2-2)^2 + (3-2)^2 = 1 + 0 + 1 = 2 Sxy=(12)(23.67)+(22)(43.67)+(32)(53.67)=(1)(1.67)+0+(1)(1.33)=1.67+1.33=3S_{xy} = (1-2)(2-3.67) + (2-2)(4-3.67) + (3-2)(5-3.67) = (-1)(-1.67) + 0 + (1)(1.33) = 1.67 + 1.33 = 3 β^1=3/2=1.5\hat{\beta}_1 = 3/2 = 1.5 β^0=3.671.5(2)=0.67\hat{\beta}_0 = 3.67 - 1.5(2) = 0.67 y^=0.67+1.5x\hat{y} = 0.67 + 1.5x Join Discord NextRegression Applications
Document outline

Keep your place and jump directly to a heading.

Table of Contents
System Normal // Awaiting Context

Intelligence Hub

Navigate the knowledge graph to generate context. The Hub adapts dynamically to surface backlinks, related notes, and metadata insights.