Explain why the shuffle happens separately in each room and why labels must be sampled without replacement.
Worked allocation: one common design
After attempting the template, compare this completed allocation. pens has one row per pen; design shuffles diets within rooms.
library("dplyr")library("tibble")pens <-tibble(pen_id =sprintf("P%02d", 1:16),room =factor(rep(paste0("Room ", 1:4), each =4)))labels <-rep(c("Control", "High fibre"), each =2)set.seed(505)design <- pens |>group_by(room) |>mutate(diet =sample(labels)) |>ungroup()
Checkpoint 1
This executed check uses the completed design above.
design |>count(room, diet)
# A tibble: 8 × 3
room diet n
<fct> <chr> <int>
1 Room 1 Control 2
2 Room 1 High fibre 2
3 Room 2 Control 2
4 Room 2 High fibre 2
5 Room 3 Control 2
6 Room 3 High fibre 2
7 Room 4 Control 2
8 Room 4 High fibre 2
nrow(design)
[1] 16
n_distinct(design$pen_id)
[1] 16
Expected: eight room-by-diet combinations with two pens each, 16 rows and 16 unique IDs.
Show these checks to the instructor before adding a response.
Task 2: the assumption record
Record the response unit and its possible values, then the supplied values for:
the control expectation in Room 1
the diet effect and its scale
room differences on the model score scale
remaining variation and any equal-exposure assumption
The zero room effect belongs to Room 1. These are scenario assumptions that we can question.
First simulation
13:55–14:25
Task 3: score, mean and response
Complete the two model lines in your script:
Incomplete student template (pseudocode):
eta = beta_0 + beta_diet * (diet == "High fibre") +
room_effect
mu = YOUR_INVERSE_LINK
Choose eta, plogis(eta) or exp(eta) from your recipe. The supplied generator draws a response for each pen using seed 1501, 1502, 1503 or 1504.
Worked Gaussian draw
This is Group 1’s illustration: Room 1 control mean 720 g/day, diet difference 45 g/day, residual SD 60. Other groups use their own family and inverse link.
The formula compares diets while allowing room differences. model_family is already set for your group.
Record the generating coefficient, fitted coefficient, and any warnings. Compare the first and second datasets.
Interpretation card
Group
Generating value
What to report
1
+45
Expected gain difference in g/day
2
0.60
Odds ratio, exp(beta_diet)
3
0.65
Expected-count ratio, exp(beta_diet)
4
0.92
Expected FCR ratio, exp(beta_diet)
For Groups 2–4, the generating coefficient is the logarithm of the value shown. The fitted coefficient usually differs because the observations vary.
When a fit is unstable
For a binary response, 16 pens can leave very few observed events in some rooms or diets.
A warning, extreme coefficient or huge standard error belongs in your record. Ask the instructor before interpreting that estimate.
Keep the dataset. Explain its valid generator and the difficulty in estimating its treatment effect.
Task 6: another group’s assumptions
At 15:30, pass your record clockwise. Check:
Do the unit and response support agree with the code?
Does the mean stay in its valid range?
Does the effect interpretation match the link?
Which assumption should we change in a sensitivity analysis?
Each group reports one defended choice and one assumption to investigate.
After-class work
Watch the GLM consolidation recording after today’s activity. It explains the modelling choices you have now used.
Complete the short reflection and R checks in the after-class activity. Bring your corrected script, one model assumption to vary, and a proposal for what “detecting the effect” should mean to Week 6.
Allow about 60 minutes including the recording.
Individual exit question
A simulated experiment gives a clear difference between diets.
Why does that single result fail to establish adequate power? State what you would keep fixed and what you would repeat.
Also name one value your group’s response can take and one it cannot take.