Dyr og Data

Statistical thinking — linear models

Gavin Simpson

Aarhus University

Mona Larsen

Aarhus University

Wednesday, 19 August 2026

Learning Objectives

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

Context

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)

Cattle body measurments

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”

Cattle body measurments

Tasks

  1. Plot weight_kg vs. heart_girth_cm

  2. Describe the trend (positive, linear, strength, etc.).

  3. Discuss: Why might heart girth be a good predictor of weight?

Equation for a straight line

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 \]

Schematic

Model fitting

We fit linear models using lm()

m <- lm(
  weight_kg ~ heart_girth_cm,
  data = cattle
)

look at the model estimates

m

Call:
lm(formula = weight_kg ~ heart_girth_cm, data = cattle)

Coefficients:
   (Intercept)  heart_girth_cm  
      -232.670           3.974  

Prediction

Use the model to predict the weight of an animal with the following heart_girth_cm:

  1. 175cm
  2. 135cm
  3. 195cm

Compare predicted and observed values for these animals

predict()

In R we can use predict() to do the calculations

predict_data <- data.frame(heart_girth_cm = c(175, 135, 195))
predict(m, newdata = predict_data)
       1        2        3 
462.7006 303.7587 542.1716 

Model summary

summary(m)

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

Model diagnostics

gglm(m)

Linear regression

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\)

Linear regression

Estimates of parameters (\(\beta_j\)) are for the population based on the fit to our sample of data

Linear regression

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:

  • \(\beta_0 \pm t_{0.975} \mathrm{SE}_{\beta_0}\) = -0.401, 1.041
  • \(\beta_1 \pm t_{0.975} \mathrm{SE}_{\beta_1}\) = 0.741, 1.256