In an experimental study of rat growth originally discussed by Box (1950), rats were assigned to three treatment groups: a Control group receiving no additive, a Thiouracil group, and a Thyroxin group administered through their drinking water. Body weights (in grams) were measured across five occasions: Baseline (Week 0), Week 1, Week 2, Week 3, and Week 4. Following an accident, three rats were removed from the Thyroxin group, resulting in an unbalanced dataset of 27 rats and 135 total observations.
The objective of this analysis is to determine whether rat body weight differs significantly across treatment groups and measurement occasions, and specifically to investigate whether the trajectory of body weight changes over time depends on the treatment received (Treatment × Time interaction).
# Load required packages
library(nlmm)
library(tidyverse)
library(rstatix)
library(ggpubr)
# Load dataset from the nlmm package
data("rats", package = "nlmm")
# Convert id, trt, and time into factors with meaningful labels
rats <- rats %>%
mutate(
id = factor(id),
trt = factor(
trt,
levels = c(1, 2, 3),
labels = c("Control", "Thiouracil", "Thyroxin")
),
time = factor(
time,
levels = 0:4,
labels = c("Week 0", "Week 1", "Week 2", "Week 3", "Week 4")
)
)
# Inspect structure, dimensions, first few rows, and group counts
str(rats)## 'data.frame': 135 obs. of 4 variables:
## $ id : Factor w/ 27 levels "1","2","3","4",..: 1 2 3 4 5 6 7 8 9 10 ...
## $ time: Factor w/ 5 levels "Week 0","Week 1",..: 1 1 1 1 1 1 1 1 1 1 ...
## $ trt : Factor w/ 3 levels "Control","Thiouracil",..: 1 1 1 1 1 1 1 1 1 1 ...
## $ y : int 57 60 52 49 56 46 51 63 49 57 ...
## [1] 135 4
## id time trt y
## 1 1 Week 0 Control 57
## 2 2 Week 0 Control 60
## 3 3 Week 0 Control 52
## 4 4 Week 0 Control 49
## 5 5 Week 0 Control 56
## 6 6 Week 0 Control 46
##
## Control Thiouracil Thyroxin
## 50 50 35
y, continuous/scale).trt: Control, Thiouracil, Thyroxin).time:
Week 0, Week 1, Week 2, Week 3, Week 4).id, \(N = 27\)).Why Long Format and Subject IDs Are Necessary: The
rats dataset is already structured in long format where
each row represents a single observation for a given rat at a specific
week, which is required by rstatix and ggplot2
to map repeated measurements properly. Including the subject identifier
(id) is essential in a mixed-design ANOVA because it links
repeated measurements to the same individual rat, allowing the model to
partition within-subject variance from random error.
# Compute sample size, mean, and SD for each Treatment x Time combination
summary_stats <- rats %>%
group_by(trt, time) %>%
get_summary_stats(y, type = "mean_sd")
knitr::kable(summary_stats, caption = "Summary Statistics of Rat Body Weight (g) by Treatment and Week")| time | trt | variable | n | mean | sd |
|---|---|---|---|---|---|
| Week 0 | Control | y | 10 | 54.000 | 5.437 |
| Week 1 | Control | y | 10 | 78.500 | 9.641 |
| Week 2 | Control | y | 10 | 106.000 | 9.922 |
| Week 3 | Control | y | 10 | 130.100 | 12.565 |
| Week 4 | Control | y | 10 | 160.600 | 15.196 |
| Week 0 | Thiouracil | y | 10 | 54.700 | 4.692 |
| Week 1 | Thiouracil | y | 10 | 76.300 | 7.917 |
| Week 2 | Thiouracil | y | 10 | 95.800 | 8.496 |
| Week 3 | Thiouracil | y | 10 | 108.200 | 9.750 |
| Week 4 | Thiouracil | y | 10 | 124.000 | 11.255 |
| Week 0 | Thyroxin | y | 7 | 55.571 | 2.992 |
| Week 1 | Thyroxin | y | 7 | 75.857 | 6.440 |
| Week 2 | Thyroxin | y | 7 | 104.857 | 11.097 |
| Week 3 | Thyroxin | y | 7 | 132.714 | 16.978 |
| Week 4 | Thyroxin | y | 7 | 162.857 | 21.505 |
# 1. Boxplot across measurement occasions differentiated by treatment
ggboxplot(
rats,
x = "time",
y = "y",
color = "trt",
palette = "jco",
xlab = "Measurement Occasion",
ylab = "Body Weight (grams)",
title = "Distribution of Rat Body Weight Across Weeks by Treatment"
)# 2. Interaction plot showing mean body weight trajectories
rats %>%
group_by(trt, time) %>%
summarise(mean_weight = mean(y), .groups = "drop") %>%
ggplot(aes(x = time, y = mean_weight, color = trt, group = trt)) +
geom_line(linewidth = 1) +
geom_point(size = 2.5) +
labs(
title = "Mean Body Weight Trajectories Over Time by Treatment Group",
x = "Measurement Occasion",
y = "Mean Body Weight (grams)",
color = "Treatment"
) +
theme_minimal()# Shapiro-Wilk test for each Treatment x Time cell
normality_res <- rats %>%
group_by(trt, time) %>%
shapiro_test(y)
knitr::kable(normality_res, caption = "Shapiro-Wilk Normality Test Results")| time | trt | variable | statistic | p |
|---|---|---|---|---|
| Week 0 | Control | y | 0.9604475 | 0.7909628 |
| Week 1 | Control | y | 0.9207427 | 0.3631906 |
| Week 2 | Control | y | 0.9775558 | 0.9507577 |
| Week 3 | Control | y | 0.9277231 | 0.4258738 |
| Week 4 | Control | y | 0.9539306 | 0.7150685 |
| Week 0 | Thiouracil | y | 0.9455834 | 0.6166327 |
| Week 1 | Thiouracil | y | 0.9714265 | 0.9037469 |
| Week 2 | Thiouracil | y | 0.9408453 | 0.5624572 |
| Week 3 | Thiouracil | y | 0.9781832 | 0.9547076 |
| Week 4 | Thiouracil | y | 0.9358011 | 0.5073039 |
| Week 0 | Thyroxin | y | 0.8879694 | 0.2642379 |
| Week 1 | Thyroxin | y | 0.7889824 | 0.0318177 |
| Week 2 | Thyroxin | y | 0.9595209 | 0.8146140 |
| Week 3 | Thyroxin | y | 0.8755771 | 0.2075286 |
| Week 4 | Thyroxin | y | 0.8603143 | 0.1523744 |
Interpretation: [State whether \(p
> 0.05\) across cells and note that mixed ANOVA is generally
robust to minor deviations given small group sizes (\(n = 7\) to \(10\))].
# Identify statistical outliers and extreme outliers
outliers_res <- rats %>%
group_by(trt, time) %>%
identify_outliers(y)
outliers_res## # A tibble: 2 × 6
## time trt id y is.outlier is.extreme
## <fct> <fct> <fct> <int> <lgl> <lgl>
## 1 Week 1 Thiouracil 19 61 TRUE FALSE
## 2 Week 2 Thiouracil 19 78 TRUE FALSE
Interpretation: [Identify any extreme outliers
(is.extreme == TRUE) and explain whether they reflect
natural biological variation or warrant retention].
# Levene's test at each measurement occasion
levene_res <- rats %>%
group_by(time) %>%
levene_test(y ~ trt)
knitr::kable(levene_res, caption = "Levene's Test for Homogeneity of Variances")| time | df1 | df2 | statistic | p |
|---|---|---|---|---|
| Week 0 | 2 | 24 | 2.0593812 | 0.1494791 |
| Week 1 | 2 | 24 | 1.1759702 | 0.3256745 |
| Week 2 | 2 | 24 | 0.4045716 | 0.6717284 |
| Week 3 | 2 | 24 | 1.6664135 | 0.2100488 |
| Week 4 | 2 | 24 | 2.2798813 | 0.1240166 |
Interpretation: [Report whether \(p > 0.05\) at each week, indicating equal error variances across treatment groups].
# Pivot data to wide format (one row per rat) for Box's M test
rats_wide <- rats %>%
pivot_wider(
id_cols = c(id, trt),
names_from = time,
values_from = y,
names_prefix = "time_"
)
box_m(
rats_wide %>% select(starts_with("time_")),
rats_wide$trt
)## # A tibble: 1 × 4
## statistic p.value parameter method
## <dbl> <dbl> <dbl> <chr>
## 1 22.4 0.839 30 Box's M-test for Homogeneity of Covariance Matric…
Interpretation: [Evaluate Box’s M test using \(\alpha = 0.001\); if \(p > 0.001\), homogeneity of covariance matrices is satisfied].
# Conduct two-way mixed-design repeated measures ANOVA
res.aov <- anova_test(
data = rats,
dv = y,
wid = id,
between = trt,
within = time
)
# Display full output including Mauchly's Test of Sphericity and Greenhouse-Geisser corrections
res.aov## ANOVA Table (type III tests)
##
## $ANOVA
## Effect DFn DFd F p p<.05 ges
## 1 trt 2 24 7.884 2.00e-03 * 0.307
## 2 time 4 96 745.920 2.38e-71 * 0.910
## 3 trt:time 8 96 16.586 3.42e-15 * 0.310
##
## $`Mauchly's Test for Sphericity`
## Effect W p p<.05
## 1 time 0.011 1.41e-17 *
## 2 trt:time 0.011 1.41e-17 *
##
## $`Sphericity Corrections`
## Effect GGe DF[GG] p[GG] p[GG]<.05 HFe DF[HF] p[HF]
## 1 time 0.342 1.37, 32.82 6.00e-26 * 0.356 1.42, 34.13 6.80e-27
## 2 trt:time 0.342 2.73, 32.82 1.73e-06 * 0.356 2.84, 34.13 1.13e-06
## p[HF]<.05
## 1 *
## 2 *
## ANOVA Table (type III tests)
##
## Effect DFn DFd F p p<.05 ges
## 1 trt 2.00 24.00 7.884 2.00e-03 * 0.307
## 2 time 1.37 32.82 745.920 6.00e-26 * 0.910
## 3 trt:time 2.73 32.82 16.586 1.73e-06 * 0.310
time and
trt:time. If \(p <
0.05\), state that sphericity is violated and report the
Greenhouse–Geisser corrected degrees of freedom and \(p\)-values].trt):
\(F(\text{df}_1, \text{df}_2) =
\text{[Value]}, p = \text{[Value]}, \eta^2_G = \text{[Value]}\).
[Interpret significance].time): \(F(\text{df}_1, \text{df}_2) = \text{[Value]}, p =
\text{[Value]}, \eta^2_G = \text{[Value]}\). [Interpret
significance].trt:time): \(F(\text{df}_1, \text{df}_2) = \text{[Value]}, p =
\text{[Value]}, \eta^2_G = \text{[Value]}\). [Interpret
significance].Because the Treatment × Time interaction is statistically significant, simple main effects are examined below.
# One-way ANOVA comparing treatments at each week
one_way_trt <- rats %>%
group_by(time) %>%
anova_test(dv = y, wid = id, between = trt) %>%
get_anova_table()
knitr::kable(one_way_trt, caption = "Simple Main Effect of Treatment at Each Week")| time | Effect | DFn | DFd | F | p | p<.05 | ges |
|---|---|---|---|---|---|---|---|
| Week 0 | trt | 2 | 24 | 0.236 | 7.92e-01 | 0.019 | |
| Week 1 | trt | 2 | 24 | 0.266 | 7.69e-01 | 0.022 | |
| Week 2 | trt | 2 | 24 | 3.173 | 6.00e-02 | 0.209 | |
| Week 3 | trt | 2 | 24 | 10.041 | 6.78e-04 | * | 0.456 |
| Week 4 | trt | 2 | 24 | 17.798 | 1.82e-05 | * | 0.597 |
# Pairwise comparisons using Tukey's HSD
tukey_trt <- rats %>%
group_by(time) %>%
tukey_hsd(y ~ trt)
knitr::kable(tukey_trt, caption = "Tukey's HSD Pairwise Comparisons by Week")| time | term | group1 | group2 | null.value | estimate | conf.low | conf.high | p.adj | p.adj.signif |
|---|---|---|---|---|---|---|---|---|---|
| Week 0 | trt | Control | Thiouracil | 0 | 0.7000000 | -4.487581 | 5.8875807 | 0.9394817 | ns |
| Week 0 | trt | Control | Thyroxin | 0 | 1.5714286 | -4.145007 | 7.2878641 | 0.7735318 | ns |
| Week 0 | trt | Thiouracil | Thyroxin | 0 | 0.8714286 | -4.845007 | 6.5878641 | 0.9234749 | ns |
| Week 1 | trt | Control | Thiouracil | 0 | -2.2000000 | -11.458665 | 7.0586650 | 0.8249543 | ns |
| Week 1 | trt | Control | Thyroxin | 0 | -2.6428571 | -12.845409 | 7.5596948 | 0.7958740 | ns |
| Week 1 | trt | Thiouracil | Thyroxin | 0 | -0.4428571 | -10.645409 | 9.7596948 | 0.9935446 | ns |
| Week 2 | trt | Control | Thiouracil | 0 | -10.2000000 | -21.072183 | 0.6721825 | 0.0688373 | ns |
| Week 2 | trt | Control | Thyroxin | 0 | -1.1428571 | -13.123419 | 10.8377044 | 0.9692398 | ns |
| Week 2 | trt | Thiouracil | Thyroxin | 0 | 9.0571429 | -2.923419 | 21.0377044 | 0.1639000 | ns |
| Week 3 | trt | Control | Thiouracil | 0 | -21.9000000 | -36.328775 | -7.4712252 | 0.0024809 | ** |
| Week 3 | trt | Control | Thyroxin | 0 | 2.6142857 | -13.285450 | 18.5140211 | 0.9115928 | ns |
| Week 3 | trt | Thiouracil | Thyroxin | 0 | 24.5142857 | 8.614550 | 40.4140211 | 0.0021393 | ** |
| Week 4 | trt | Control | Thiouracil | 0 | -36.6000000 | -54.248561 | -18.9514386 | 0.0000761 | **** |
| Week 4 | trt | Control | Thyroxin | 0 | 2.2571429 | -17.190625 | 21.7049103 | 0.9548342 | ns |
| Week 4 | trt | Thiouracil | Thyroxin | 0 | 38.8571429 | 19.409375 | 58.3049103 | 0.0001225 | *** |
Summary: [Identify at which weeks treatment groups begin to differ significantly and which pairs differ].
# Repeated measures ANOVA across time within each treatment group
one_way_time <- rats %>%
group_by(trt) %>%
anova_test(dv = y, wid = id, within = time) %>%
get_anova_table()
knitr::kable(one_way_time, caption = "Simple Main Effect of Time Within Each Treatment")| trt | Effect | DFn | DFd | F | p | p<.05 | ges |
|---|---|---|---|---|---|---|---|
| Control | time | 1.32 | 11.90 | 398.811 | 0.0e+00 | * | 0.928 |
| Thiouracil | time | 1.77 | 15.90 | 225.074 | 0.0e+00 | * | 0.896 |
| Thyroxin | time | 1.15 | 6.91 | 160.945 | 3.8e-06 | * | 0.903 |
# Paired pairwise comparisons using Holm-adjusted p-values
pwc_time <- rats %>%
group_by(trt) %>%
pairwise_t_test(
y ~ time,
paired = TRUE,
p.adjust.method = "holm"
)
knitr::kable(pwc_time, caption = "Holm-Adjusted Pairwise Comparisons Across Weeks")| trt | .y. | group1 | group2 | n1 | n2 | statistic | df | p | p.adj | p.adj.signif |
|---|---|---|---|---|---|---|---|---|---|---|
| Control | y | Week 0 | Week 1 | 10 | 10 | -16.019955 | 9 | 0.0000001 | 0.0000002 | **** |
| Control | y | Week 0 | Week 2 | 10 | 10 | -23.517885 | 9 | 0.0000000 | 0.0000000 | **** |
| Control | y | Week 0 | Week 3 | 10 | 10 | -20.973218 | 9 | 0.0000000 | 0.0000000 | **** |
| Control | y | Week 0 | Week 4 | 10 | 10 | -23.371099 | 9 | 0.0000000 | 0.0000000 | **** |
| Control | y | Week 1 | Week 2 | 10 | 10 | -18.333333 | 9 | 0.0000000 | 0.0000001 | **** |
| Control | y | Week 1 | Week 3 | 10 | 10 | -15.779497 | 9 | 0.0000001 | 0.0000002 | **** |
| Control | y | Week 1 | Week 4 | 10 | 10 | -19.020014 | 9 | 0.0000000 | 0.0000001 | **** |
| Control | y | Week 2 | Week 3 | 10 | 10 | -12.966654 | 9 | 0.0000004 | 0.0000004 | **** |
| Control | y | Week 2 | Week 4 | 10 | 10 | -18.263242 | 9 | 0.0000000 | 0.0000001 | **** |
| Control | y | Week 3 | Week 4 | 10 | 10 | -17.996615 | 9 | 0.0000000 | 0.0000001 | **** |
| Thiouracil | y | Week 0 | Week 1 | 10 | 10 | -12.698561 | 9 | 0.0000005 | 0.0000028 | **** |
| Thiouracil | y | Week 0 | Week 2 | 10 | 10 | -22.042472 | 9 | 0.0000000 | 0.0000000 | **** |
| Thiouracil | y | Week 0 | Week 3 | 10 | 10 | -21.790900 | 9 | 0.0000000 | 0.0000000 | **** |
| Thiouracil | y | Week 0 | Week 4 | 10 | 10 | -20.116320 | 9 | 0.0000000 | 0.0000001 | **** |
| Thiouracil | y | Week 1 | Week 2 | 10 | 10 | -14.602202 | 9 | 0.0000001 | 0.0000010 | **** |
| Thiouracil | y | Week 1 | Week 3 | 10 | 10 | -11.935489 | 9 | 0.0000008 | 0.0000033 | **** |
| Thiouracil | y | Week 1 | Week 4 | 10 | 10 | -12.225412 | 9 | 0.0000007 | 0.0000033 | **** |
| Thiouracil | y | Week 2 | Week 3 | 10 | 10 | -7.262080 | 9 | 0.0000475 | 0.0000896 | **** |
| Thiouracil | y | Week 2 | Week 4 | 10 | 10 | -9.254888 | 9 | 0.0000068 | 0.0000204 | **** |
| Thiouracil | y | Week 3 | Week 4 | 10 | 10 | -7.317464 | 9 | 0.0000448 | 0.0000896 | **** |
| Thyroxin | y | Week 0 | Week 1 | 7 | 7 | -12.454224 | 6 | 0.0000164 | 0.0000982 | **** |
| Thyroxin | y | Week 0 | Week 2 | 7 | 7 | -13.961015 | 6 | 0.0000084 | 0.0000736 | **** |
| Thyroxin | y | Week 0 | Week 3 | 7 | 7 | -13.107208 | 6 | 0.0000122 | 0.0000852 | **** |
| Thyroxin | y | Week 0 | Week 4 | 7 | 7 | -14.031461 | 6 | 0.0000082 | 0.0000736 | **** |
| Thyroxin | y | Week 1 | Week 2 | 7 | 7 | -11.982711 | 6 | 0.0000205 | 0.0000982 | **** |
| Thyroxin | y | Week 1 | Week 3 | 7 | 7 | -10.938029 | 6 | 0.0000347 | 0.0000982 | **** |
| Thyroxin | y | Week 1 | Week 4 | 7 | 7 | -12.434615 | 6 | 0.0000165 | 0.0000982 | **** |
| Thyroxin | y | Week 2 | Week 3 | 7 | 7 | -8.559550 | 6 | 0.0001396 | 0.0001396 | *** |
| Thyroxin | y | Week 2 | Week 4 | 7 | 7 | -11.588968 | 6 | 0.0000248 | 0.0000982 | **** |
| Thyroxin | y | Week 3 | Week 4 | 7 | 7 | -14.772955 | 6 | 0.0000060 | 0.0000605 | **** |
Summary: [Describe how body weight changes across weeks within Control, Thiouracil, and Thyroxin groups].
[Explain how the simple main effects clarify when and where the growth curves diverge—specifically comparing Thiouracil’s stunted growth trajectory against Control and Thyroxin].
[A two-way mixed-design repeated measures ANOVA was conducted to examine the effects of treatment (Control, Thiouracil, Thyroxin) and time (Weeks 0–4) on rat body weight (\(N = 27\)). There was a [significant/non-significant] main effect of treatment, \(F(\text{df}_1, \text{df}_2) = \text{[Value]}, p = \text{[Value]}, \eta^2_G = \text{[Value]}\), and a statistically significant main effect of time, \(F(\text{df}_1, \text{df}_2) = \text{[Value]}, p = \text{[Value]}, \eta^2_G = \text{[Value]}\). Crucially, these main effects were qualified by a statistically significant Treatment × Time interaction, \(F(\text{df}_1, \text{df}_2) = \text{[Value]}, p = \text{[Value]}, \eta^2_G = \text{[Value]}\). Post hoc simple main effects analyses revealed that while treatment groups did not differ significantly at baseline (Week 0), significant divergence emerged by [Week X], where rats treated with Thiouracil exhibited significantly lower weight gain compared to the Control and Thyroxin groups (\(p < .05\)). Biologically, Thiouracil acts as an antithyroid agent that suppresses thyroid hormone synthesis and slows metabolic growth rate in rats, whereas Thyroxin maintains growth rates comparable to untreated controls. Because this experiment was conducted solely on laboratory rats, these findings should not be generalized directly to human health.]
In answer to the central research question, yes—the effect of treatment on rat body weight depends significantly on the measurement occasion. While all groups begin at comparable baseline weights, growth trajectories diverge over the four-week period due to the growth-suppressing effect of Thiouracil relative to Control and Thyroxin treatments.
• Box, G. E. P. (1950). Problems in the analysis of growth and wear curves. Biometrics, 6(4), 362–389.
• Datanovia. (2026). Mixed ANOVA in R: One Between- and One Within-Subjects Factor. datanovia.com
• Geraci, M. (2023). nlmm: Generalized Laplace Mixed-Effects Models (Dataset: rats). rdrr.io