Explain what the repeated observations tell us

Class 10: 60-minute follow-up

Gavin Simpson

Aarhus University

Wednesday, 11 November 2026

After class: 60 minutes

Minutes Work
15 Revisit the two designs and this deck
20 Run or read the explicit calf change comparison
25 Explain both studies, sketch growth curves, update project plan

Use the worksheet. Both datasets and complete reference results are provided.

Two designs, one shared feature

The calves stay on their assigned diet. We observe how their weights change.

The cows receive both rations, in a randomly assigned order. We compare intake within the same animal.

Both repeat observations on animals. Only the crossover switches treatment within an animal.

Reload the calf example explicitly

library("dplyr")

library("lme4")
library("performance")
library("marginaleffects")
d <- readr::read_csv("data/calf-growth.csv")
d <- d |>
  mutate(
    room = factor(room),
    calf = factor(calf),
    diet = factor(diet, levels = c("Control", "Enhanced")),
    time_factor = factor(time_week, levels = c(0, 2, 4, 6, 8))
  )
d |>
  distinct(calf, diet) |>
  count(diet)

There are 16 calves assigned to each diet, with five weights per calf.

Reload the calf example explicitly

# A tibble: 2 × 2
  diet         n
  <fct>    <int>
1 Control     16
2 Enhanced    16

Fit, then ask for the diet gap at each visit

calf_fit <- lmer(
  weight_kg ~ room + diet * time_factor + (1 | calf),
  data = d,
  REML = TRUE
)
calf_gaps <- avg_comparisons(
  calf_fit,
  variables = "diet",
  by = "time_factor",
  re.form = NA
)
calf_gaps

Each row is Enhanced minus Control in kg. The baseline gap is measured before the diets start.

Fit, then ask for the diet gap at each visit


 time_factor Estimate Std. Error      z Pr(>|z|)   S  2.5 % 97.5 %
           0    0.025       1.99 0.0126    0.990 0.0 -3.872   3.92
           2    0.471       1.99 0.2367    0.813 0.3 -3.427   4.37
           4    3.245       1.99 1.6320    0.103 3.3 -0.652   7.14
           6    2.626       1.99 1.3206    0.187 2.4 -1.271   6.52
           8    3.222       1.99 1.6204    0.105 3.2 -0.675   7.12

Term: diet
Type: response
Comparison: Enhanced - Control

Ask how the gap changed from baseline

We want the week-8 gap minus the week-0 gap.

stopifnot(
  identical(as.character(calf_gaps$time_factor), c("0", "2", "4", "6", "8"))
)
change_weights <- matrix(c(-1, 0, 0, 0, 1), ncol = 1)
change_gap <- hypotheses(calf_gaps, hypothesis = change_weights)
change_gap

 Estimate Std. Error    z Pr(>|z|)    S 2.5 % 97.5 %
      3.2      0.797 4.01   <0.001 14.0  1.64   4.76

Term: custom

The five weights subtract the first row and add the last. Checking row order prevents subtracting the wrong visits.

What if we ignored the repeated calves?

independent_fit <- lm(weight_kg ~ room + diet * time_factor, data = d)
independent_gaps <- avg_comparisons(
  independent_fit,
  variables = "diet",
  by = "time_factor"
)
independent_change <- hypotheses(
  independent_gaps,
  hypothesis = change_weights
)
independent_change

A calf’s usual weight difference cancels from its change. Here recognising pairing makes the change comparison more precise.

What if we ignored the repeated calves?


 Estimate Std. Error    z Pr(>|z|)   S 2.5 % 97.5 %
      3.2        2.7 1.18    0.237 2.1  -2.1    8.5

Term: custom

Check the remaining uncertainty

print(
  check_model(
    calf_fit,
    check = c("linearity", "qq"),
    residual_type = "normal"
  )
)

A reassuring plot cannot prove that a calf’s nearby weights have no shared influences left after allowing for its usual weight. Class 11 examines change through time further.

Crossover: what must your explanation include?

Our 24 cows were assigned to AB or BA, with both rations present in both periods.

intake_kg_day ~ treatment + period + sequence + (1 | cow) allows for period and cows’ usual differences in appetite.

avg_comparisons() estimates B minus A. avg_predictions() estimates mean intake under each ration.

The earlier ration must no longer affect the later outcome. Neither a sequence term nor a reassuring model check establishes this.

Prepare the bridge to Class 11

The calf model estimates five occasion means. It does not choose a continuous growth curve between them.

Sketch two plausible curves through the pattern of mean weights. Could growth be steady? Could it slow?

Keep both curves within weeks 0–8. Explain why predictions beyond the measured period need extra justification.

Finish the worksheet and one project action

Explain the calf allocation count, the change comparison and one remaining assumption.

Explain the cow sequence assignment, the B–A comparison and the washout assumption.

Save your project’s next action. Bring the worksheet and the two growth-curve sketches to Class 11.