R Under development (unstable) (2026-01-12 r89300 ucrt) -- "Unsuffered Consequences" Copyright (C) 2026 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > # test_contrast_utils.R > > library(lmerTest) Loading required package: lme4 Loading required package: Matrix Attaching package: 'lmerTest' The following object is masked from 'package:lme4': lmer The following object is masked from 'package:stats': step > > ########## > # Test that a message is printed if some cells have zero data: > # Missing a single cell: > data("cake", package="lme4") > cake4 <- cake > cake4$temperature <- factor(cake4$temperature, ordered=FALSE) > cake4 <- droplevels(subset(cake4, !(recipe == "A" & temperature == "175") )) > with(cake4, table(recipe, temperature)) temperature recipe 175 185 195 205 215 225 A 0 15 15 15 15 15 B 15 15 15 15 15 15 C 15 15 15 15 15 15 > > fm1 <- lmer(angle ~ recipe * temperature + (1|recipe:replicate), cake4) fixed-effect model matrix is rank deficient so dropping 1 column / coefficient > an <- anova(fm1) Missing cells for: recipeA:temperature175. Interpret type III hypotheses with care. > txt <- capture.output(an <- anova(fm1), type = "message") > stopifnot(length(grep("Missing cells for:", txt)) > 0, + length(grep("Interpret type III hypotheses with care.", txt)) > 0) > > ########## > # Test that a message is printed if some cells have zero data: > # Missing diagonal: > cake4 <- cake > cake4$temperature <- factor(cake4$temperature, ordered=FALSE) > cake4 <- droplevels(subset(cake4, temperature %in% levels(cake4$temperature)[1:3])) > cake4 <- droplevels(subset(cake4, !((recipe == "A" & temperature == "175") | + (recipe == "B" & temperature == "185") | + (recipe == "C" & temperature == "195") ))) > cake4$temp0 <- cake4$temp - mean(cake4$temp) > with(cake4, table(recipe, temperature)) temperature recipe 175 185 195 A 0 15 15 B 15 0 15 C 15 15 0 > > fm1 <- lmer(angle ~ recipe * temperature + (1|recipe:replicate), cake4) fixed-effect model matrix is rank deficient so dropping 3 columns / coefficients > an <- anova(fm1) Missing cells for: recipeA:temperature175, recipeB:temperature185, recipeC:temperature195. Interpret type III hypotheses with care. > txt <- capture.output(an <- anova(fm1), type = "message") > stopifnot(length(grep("Missing cells for:", txt)) > 0, + length(grep("Interpret type III hypotheses with care.", txt)) > 0) > > ########## > # Test that a message is NOT printed with centered covariates: > fm1 <- lmer(angle ~ recipe * temp0 + (1|recipe:replicate), cake4) > an <- anova(fm1) > txt <- capture.output(an <- anova(fm1), type = "message") > stopifnot(length(grep("Missing cells for:", txt)) == 0, + length(grep("Interpret type III hypotheses with care.", txt)) == 0) > # Note: in many cases a message would not be printed anyway because the > # columns sums in the rdX design matrix would not be exactly zero but just a > # small number very close to zero. > > > > > proc.time() user system elapsed 2.15 0.17 2.31