Researchers assign Control or Enhanced feed to each of 32 calves, balancing the two diets within each of four rooms. They weigh each calf at weeks 0, 2, 4, 6 and 8. These invented records illustrate longitudinal data: measurements collected from the same animals over time.
week counts weeks since researchers assigned the diets. They record week 0 before feeding starts.
Read the same calf study
# A tibble: 3 × 4
calf diet week weight_kg
<fct> <fct> <dbl> <dbl>
1 C01 Control 0 47.9
2 C01 Control 2 58.6
3 C01 Control 4 65.8
Today: how does growth change?
Time
Work
08:00–08:45
Recall and time relationships
08:45–09:10
Trajectory detective
09:10–09:25
Break
09:25–10:25
Fit, predict and check
10:25–10:40
Break
10:40–11:30
Own projects and reports
Opening recall: what was assigned?
A calf keeps its assigned diet for eight weeks. Weighing it again does not assign another diet.
To how many calves do researchers assign a diet?
What do repeated weights tell us about the same calf?
How does this differ from Class 10’s crossover study, where an animal receives both treatments in a planned order?
Look at each calf’s path
ggplot(d, aes(week, weight_kg, group = calf, colour = diet)) +geom_line(alpha = .4) +labs(x ="Week", y ="Weight (kg)") +theme_minimal()
Each line joins one calf’s five weights. Do calves start at different weights, and does their gain appear to slow?
Treat visits as groups or use numerical weeks?
A separate mean for each visit
A chosen relationship with weeks
Fits the observed visits flexibly
Describes a line or curve
Does not describe gaps between visits
Can describe values between visits
Estimates more separate mean weights
Assumes a particular shape
Both must still account for weights from the same calf.
Fit a straight growth line
Some calves remain heavier than others after allowing for diet and room. (1 | calf) gives each calf a shared weight difference, called a random intercept.
diet * week allows each diet a different starting weight and growth rate. A difference in growth rates is a diet-by-time interaction. We include room because researchers assigned both diets within each room.
Fit a straight growth line
Linear mixed model fit by REML ['lmerMod']
Formula: weight_kg ~ diet * week + room + (1 | calf)
Data: d
REML criterion at convergence: 748.1
Scaled residuals:
Min 1Q Median 3Q Max
-2.52444 -0.54958 0.06794 0.63671 2.19582
Random effects:
Groups Name Variance Std.Dev.
calf (Intercept) 28.957 5.381
Residual 3.227 1.796
Number of obs: 160, groups: calf, 32
Fixed effects:
Estimate Std. Error t value
(Intercept) 39.25054 2.16935 18.093
dietEnhanced 0.20788 1.96511 0.106
week 4.53100 0.07101 63.810
roomR2 0.05862 2.72041 0.022
roomR3 2.40960 2.72041 0.886
roomR4 4.03347 2.72041 1.483
dietEnhanced:week 0.42749 0.10042 4.257
Correlation of Fixed Effects:
(Intr) dtEnhn week roomR2 roomR3 roomR4
dietEnhancd -0.453
week -0.131 0.145
roomR2 -0.627 0.000 0.000
roomR3 -0.627 0.000 0.000 0.500
roomR4 -0.627 0.000 0.000 0.500 0.500
dtEnhncd:wk 0.093 -0.204 -0.707 0.000 0.000 0.000
A difference in growth rate
The straight model’s week coefficient is Control’s gain in kg per week.
dietEnhanced:week is the extra gain per week for Enhanced.
The diet coefficient alone describes the week-0 difference.
Our question: by week 8, how much heavier is the expected Enhanced calf than the expected Control calf?
Let growth slow down
Calves may gain weight quickly at first and more slowly later. I(week^2) lets both diet paths bend by the same amount; this shared bend is called common curvature.