- Linear regression is used to predict a value.
- It models the relationship between two variables.
- The relationship is represented by a straight line.
- It helps us understand how one variable affects another.
2026-03-07
We will use the trees dataset in R and study how tree girth affects tree volume.
x = tree girth
y = tree volume
\[ y = mx + b \] - \(y\) = predicted value
- \(x\) = input variable
- \(m\) = slope of the line
- \(b\) = intercept
This slide shows the relationship between Girth and Volume using a scatter plot.
This slide shows the linear regression line fitted to the data.
The linear regression equation is: \[ y = mx + b \] The slope \(m\) tells us how much \(y\) changes when \(x\) increases by 1.
For the trees dataset the model gives \[ y = 5.07x - 36.94 \]
This means: \[ m = 5.07 \] So for every increase of 1 unit in Girth, the Volume increases by about 5.07 units.
ggplot(data = trees, aes(x = Girth, y = Volume)) + geom_point() + geom_smooth(method = "lm", se = FALSE)