| animal | heart_girth_cm | body_length_cm | weight_kg |
|---|---|---|---|
| 1 | 135 | 140 | 305 |
| 2 | 142 | 145 | 342 |
| 3 | 150 | 152 | 357 |
| 4 | 155 | 158 | 389 |
| 5 | 160 | 160 | 401 |
| 6 | 165 | 166 | 412 |
| 7 | 170 | 168 | 438 |
| 8 | 175 | 170 | 466 |
| 9 | 180 | 172 | 472 |
| 10 | 185 | 175 | 503 |
| 11 | 190 | 178 | 530 |
| 12 | 195 | 180 | 548 |
Statistical thinking — linear models
Wednesday, 19 August 2026
By the end of this activity, you will be able to:
Fit and interpret a simple linear regression model
Understand slope and intercept in a biological context.
Use the regression model for prediction.
Assess model fit using R2 and diagnostic plots
In animal production, body weight is an important indicator of health, growth, and productivity. However, weighing large animals like cattle or sheep can be time-consuming or impractical. Body measurements (like heart girth or body length) are often used to estimate weight using regression models
Rocha-Silva et al. Trop Anim Health Prod 56, 42 (2024)
| animal | heart_girth_cm | body_length_cm | weight_kg |
|---|---|---|---|
| 1 | 135 | 140 | 305 |
| 2 | 142 | 145 | 342 |
| 3 | 150 | 152 | 357 |
| 4 | 155 | 158 | 389 |
| 5 | 160 | 160 | 401 |
| 6 | 165 | 166 | 412 |
| 7 | 170 | 168 | 438 |
| 8 | 175 | 170 | 466 |
| 9 | 180 | 172 | 472 |
| 10 | 185 | 175 | 503 |
| 11 | 190 | 178 | 530 |
| 12 | 195 | 180 | 548 |
“girth” -> “omkreds”
Plot weight_kg vs. heart_girth_cm
Describe the trend (positive, linear, strength, etc.).
Discuss: Why might heart girth be a good predictor of weight?
At school you probably learned this (or something like it)
\[ y = m x + b \]
In statistics we tend to write it this way
\[ \hat{y}_i = \beta_0 + \beta_1 x_i \]
We fit linear models using lm()
look at the model estimates
Use the model to predict the weight of an animal with the following heart_girth_cm:
Compare predicted and observed values for these animals
predict()In R we can use predict() to do the calculations
Call:
lm(formula = weight_kg ~ heart_girth_cm, data = cattle)
Residuals:
Min 1Q Median 3Q Max
-10.9652 -5.2152 0.9026 5.7848 10.4265
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -232.6704 19.6128 -11.86 3.25e-07 ***
heart_girth_cm 3.9735 0.1169 34.00 1.14e-11 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 7.403 on 10 degrees of freedom
Multiple R-squared: 0.9914, Adjusted R-squared: 0.9906
F-statistic: 1156 on 1 and 10 DF, p-value: 1.145e-11
We estimate the two unknown parameters in the model using a procedure known as least squares, where we minimise the Residual Sum of Squares \(\mathrm{RSS} = \sum_{i=1}^n (y_i - \hat{y}_i)^2\)
Estimates of parameters (\(\beta_j\)) are for the population based on the fit to our sample of data
Data were 20 observations generated from the following model
\[\mu_i = 0.7 + 0.8x_i \;\;\;\; y_i \sim N(\mu_i, \sigma = 1)\]
Fitted model estimates are: \(\hat{\beta}_0\) = 0.32 and \(\hat{\beta}_1\) = 0.999
The parameters are means & the uncertainty in the estimated values is captured by their standard errors
Confidence intervals for the estimates: