UNSW Sydney · FACULTY OF ENGINEERING

CVEN9407 Chap.5 Two-Variable Regression and Ordinary Least Squares

- one subject, every graph, every model, every mark
6 Chapters4-page Bible
Our own words - no uploaded lecturer files
Updated for this semester
Chapter 5 of 12 · CVEN9407

Two-Variable Regression and Ordinary Least Squares

This chapter fits the first regression line of the course by hand. It defines regression as the study of conditional means, separates the population regression function from the sample line that estimates it, and explains the role of the stochastic error term.

Least squares is derived from the goal of minimising squared residuals, and a ten-household trip-generation example is worked from a full table of sums to the slope, the intercept and R squared. The chapter closes with what R squared can and cannot tell you.

The two-variable model is small enough to compute on paper, which is why it is the place to understand what software does in every later regression.

The same logic of conditional means, residuals and squared-error minimisation carries straight into the multiple regression of crash frequency that forms the first project deliverable, and the Week 2 demonstration runs the same fit in R.

In this chapter

What this chapter covers

  • 01

    Regression as a line of conditional means

  • 02

    Population and sample regression functions

  • 03

    The stochastic error term and the residual

  • 04

    Least squares and the normal equations

  • 05

    Slope and intercept formulas

  • 06

    Total, explained and residual sums of squares

Worked example · free

Fitting a line from five summary totals

Q [3 marks]. For five road segments, the sum of X is 20, the sum of Y is 35, the sum of X squared is 90 and the sum of XY is 150. Find the least squares line. The mark allocation is our own practice weighting and is not an official university scheme.
Least squares on ten invented households.Least squares on ten invented households. Dots are observed daily trips against vehicles owned; the blue line is the fitted sample regression, each dashed amber segment is a residual, and the line passes through the mean point of 2.5 vehicles and 4.0 trips.012345246mean point (2.5, 4.0)fitted linevehicles per household
Least squares on ten invented households. Dots are observed daily trips against vehicles owned; the blue line is the fitted sample regression, each dashed amber segment is a residual, and the line passes through the mean point of 2.5 vehicles and 4.0 trips.
  • 1Means: X bar = 20 / 5 = 4 and Y bar = 35 / 5 = 7.
  • 1Deviation sums: sum of x squared = 90 - 5(16) = 10 and sum of xy = 150 - 5(4)(7) = 10.
  • 1Slope = 10 / 10 = 1.0 and intercept = 7 - 1.0(4) = 3, so the fitted line is Y hat = 3 + 1.0X.
Y hat = 3 + 1.0X; the line passes through the point of means (4, 7).
Sia tip — After any hand fit, substitute the mean of X into your line; if it does not return the mean of Y, an arithmetic slip has crept in.
Glossary

Key terms

Population regression function
The population regression function gives the expected value of the dependent variable for each value of the explanatory variable.
Stochastic disturbance
A stochastic disturbance is the deviation of an individual observation from its conditional mean in the population model.
Normal equations
The normal equations are the first-order conditions of least squares, solved together to give the intercept and slope.
Total sum of squares
The total sum of squares is the summed squared deviation of the dependent variable from its mean, split into explained and residual parts.
Sample regression function
The sample regression function is the fitted line computed from one sample, used to estimate the population regression function.
Explained sum of squares
The explained sum of squares is the variation of the fitted values around the mean of the dependent variable.
FAQ

Two-Variable Regression and Ordinary Least Squares FAQ

Why are residuals squared rather than simply added?

Positive and negative residuals would cancel out, so many different lines could make their sum zero. Squaring removes the sign and gives more weight to large misses, which produces a unique best-fitting line.

Does a high R squared mean the model is good?

Not on its own. R squared only measures how much variation the line explains in this sample. A model can have a high value and still have biased coefficients, misbehaving errors or no causal meaning.

What is the difference between the error term and the residual?

The error term is the unobservable deviation from the population line. The residual is the observable deviation from the fitted sample line, and it serves as the estimate of the error term.

Why does the fitted line always pass through the point of means?

The first normal equation forces the residuals to sum to zero, which can only happen if the fitted value at the mean of X equals the mean of Y. That property also gives a quick check on any hand calculation.

How do I read the slope in its units?

The slope is the change in the expected value of Y for a one-unit increase in X, in Y's units per X's units. In a trips-on-vehicles model, a slope of 0.7 means about 0.7 extra daily trips per extra vehicle, on average across households.

Study strategy

Assessment move

Fit at least two small datasets by hand using the shortcut formulas, then check them in R or Colab so you trust both. Keep four decimals until the final line. For each fit, state the slope in words with its units, and say what share of the variation the line explains. Then fit the same line in R or Colab and match every number on the output to the formula that produced it.

Working through Two-Variable Regression and Ordinary Least Squares in CVEN9407? Sia is AskSia’s AI Engineering tutor — ask any CVEN9407 Two-Variable Regression and Ordinary Least Squares question and get a clear, step-by-step explanation grounded in how CVEN9407 is taught and assessed. Read this chapter free, then take your hardest questions to Sia.

A+Everything unlocked
Unlocks this Bible + all 100 of your UNSW Sydney subjects - and 1,000+ Bibles across every Australian university.
Sia - your CVEN9407 tutor, unlimited, worked the way the exam marks it
The full 4-page Bible + practice bank with worked solutions
Chrome extension - sync your LMS so Sia knows your deadlines
Bilingual EN / Chinese on every Bible and every Sia answer
$0.99 Trial
30-day money-back · cancel in one tap · how it works
CVEN9407 · Transport Demand Modelling - independent study guide on the AskSia Library. More UNSW Sydney subjects · Microeconomics across all universities