A simulated dataset of weekly NutritionScore measurements collected from 41 schools across three districts of WaszKrak megapolis (Districts 7, 12, and 23) over 26 weeks. The dataset is designed to illustrate nested (hierarchical) ANOVA with fixed effects, post-hoc comparisons, and the detection of a single outlier school.
NutritionScore is a composite index (0–100) derived from weekly AI health checks performed on students — measuring weight indicators, biochemical markers, and energy levels. It is updated every Friday by the SynBio TierCare diagnostic system.
The story
The dataset originates from a tip sent by Tomasz Bernat, a mathematics teacher at School 4 in District 12, who noticed that his students were unable to concentrate and were falling asleep by 10am. The school nutritionist reported that NutriFirst program scores were within normal range. Bernat did not believe the scores.
Beta and Bit obtained a leaked export of the school monitoring system
covering all 41 schools. The nested ANOVA revealed that School 4 — the
only school enrolled in the NutriFirst program (SynBio batch
SB-2046-NF-07) — scored more than 20 points below every other school
in District 12, and below the District 7 mean, despite District 12 being
a substantially wealthier district.
A data entry error by a procurement clerk had assigned School 4 to a cartridge batch intended exclusively for districts with MedScore below 55. The batch had reduced protein bioavailability. The error was statistically visible. The students' fatigue was not a mystery. It was a data point.
Statistical design
Schools are nested within districts — School 4 in District 12 is a different entity from School 4 in District 7. Both district and school are treated as fixed effects (not random), because the analysis concerns these specific schools and districts, not schools and districts in general.
The nested model is:
which in R notation is equivalent to aov(Score ~ district/school).
The key finding is a significant school(district) term, driven
entirely by School 4 in District 12. Post-hoc Tukey comparisons confirm
that School 4 differs significantly from every other District 12 school
(all adjusted p < 0.001).
Format
A data frame with 1,066 rows and 5 variables:
- school
Character. School identifier, e.g.
"D12_S4". Format: district prefix + underscore +S+ school number within district. Schools are uniquely identified within districts —D7_S1andD12_S1are different schools.- week
Integer (1–26). Observation week within the 26-week monitoring period. Week 1 corresponds to the start of the academic term. NutritionScore is recorded once per week per school.
- district
Factor with 3 levels:
"D7","D12","D23". Ordered by socioeconomic status: D7 (lowest) < D12 (middle) < D23 (highest). District determines baseline NutritionScore through access to food infrastructure, healthcare, and algorithmic resource allocation.- nutrifirst
Logical.
TRUEif the school is enrolled in SynBio's NutriFirst synthetic food programme (cartridge batchSB-2046-NF-07). Only one school in the dataset hasnutrifirst = TRUE: School 4 in District 12 ("D12_S4"). This school was assigned to the batch by a data entry error — the clerk mistyped the district code. The batch is otherwise distributed exclusively to schools in districts with MedScore below 55.- Score
Numeric (0–100). Weekly NutritionScore for the school, averaged across all students in that school for that week. Derived from SynBio TierCare AI health checks. Higher values indicate better nutritional status. The true school mean is stable across weeks; within-school week-to-week variation reflects natural measurement noise (SD ≈ 4 points).
Source
Simulated dataset generated by data-raw/generate_nutrition.R.
The data structure is based on the chapter "The Outlier" in
Equations from District 7: A Practical Guide to Linear Models
(BetaBit StatPunk universe). All values are fictional.
See also
lifecalc for the full LifeCalc social scoring dataset
vignette("nested-anova", package = "RougeLM")for a worked example
Examples
data(nutrition)
# District-level summary
aggregate(Score ~ district, data = nutrition, FUN = mean)
#> Error in eval(predvars, data, env): object 'Score' not found
aggregate(Score ~ district, data = nutrition, FUN = sd)
#> Error in eval(predvars, data, env): object 'Score' not found
# School-level means
school_means <- aggregate(Score ~ district + school + nutrifirst,
data = nutrition, FUN = mean)
#> Error in eval(predvars, data, env): object 'Score' not found
school_means[order(school_means$Score), ]
#> Error: object 'school_means' not found
# Identify the outlier school
school_means[school_means$nutrifirst == TRUE, ]
#> Error: object 'school_means' not found
# Nested ANOVA: schools nested within districts, both fixed effects
model <- aov(Score ~ district + district:school,
data = school_means)
#> Error: object 'school_means' not found
summary(model)
#> Error: object 'model' not found
# Post-hoc comparisons within District 12
if (requireNamespace("emmeans", quietly = TRUE)) {
library(emmeans)
emm <- emmeans(model,
specs = ~ school,
data = school_means[school_means$district == "D12", ])
pairs(emm, adjust = "tukey")
}
#> Error: object 'model' not found
# Visualise: school means coloured by district and NutriFirst status
if (requireNamespace("ggplot2", quietly = TRUE)) {
library(ggplot2)
ggplot(school_means,
aes(x = district, y = Score,
colour = district, shape = nutrifirst)) +
geom_jitter(width = 0.15, size = 3) +
scale_shape_manual(values = c("FALSE" = 16, "TRUE" = 8)) +
labs(title = "NutritionScore by district and school",
subtitle = "Star = NutriFirst batch SB-2046-NF-07") +
theme_minimal()
}
#> Error: object 'school_means' not found