Repository navigation
Fix clmm() submodel fits with the cloglog and loglog links - #613
Merged
Merged
Conversation
# Conflicts: # man/projpred-package.Rd
aloctavodia
approved these changes
Nov 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
For a single group-level term
(1 | <group>),ordinal::clmm()uses C code that swaps the linkscloglogandloglog(runehaubo/ordinal#76, open). projpred passes the link of the reference model toclmm()infit_cumul_mlvl(). Thus, for abrms::cumulative(link = "cloglog")reference model, projpred fitted the multilevel submodels with the loglog link. projpred then computed their predictions with the cloglog link inordinal:::predict.clm(). Submodels with more than one group-level term use the R code ofclmm(), which is correct.Example with
clmm()alone: data from a cumulative cloglog model with 4 categories, 400 observations and no group effect. ordinal 2025.12.29 and 2026.7-26 give the same numbers. The defaultclmm()fit has about the log-likelihood of theclm()loglog fit. WithuseMatrix = TRUE, it has about that of theclm()cloglog fit.clm(link = "cloglog")clm(link = "loglog")clmm(y ~ x + (1 | g), link = "cloglog")clmm.control(useMatrix = TRUE)In projpred (master fa9a9e1, ordinal 2026.7-26), I called
fit_cumul_mlvl()withlink = "cloglog"on augmented data. The data came from a cumulative cloglog model with the thresholds -0.8, 0.2 and 1.1 and with group effects (300 observations, 15 groups). The fit gave the thresholds 0.154, 1.092 and 2.198. The R code ofclmm()gives -0.727, 0.235 and 1.089. The category probabilities fromsubprd_augdat()differed from the true category probabilities by up to 0.562 in absolute value (0.176 with the R code). Some predicted probabilities were 0 where the true probability was not, so the KL divergence was infinite.Changes
This PR passes
useMatrix = TRUEtoclmm()for thecloglogandlogloglinks, so thatclmm()uses its R code.clmm()then cannot useucminf(), so these fits use the defaultnlminb()optimizer. They are about 4 to 6 times slower. One fit with 300 observations, 4 categories, 2 predictors and 20 groups took 0.45 to 0.68 s. The fit with the C code anducminf()took 0.10 to 0.12 s. These are three runs on one laptop with ordinal 2025.12.29. The other links do not change. Inordinal:::getCtrlArgs(), auseMatrixargument in...takes precedence overcontrol, so the setting also applies when the user passescontrol.Side effects
Two side effects for these two links:
clmm()withuseMatrix = TRUEstops ifnAGQis not 1. projpred does not passnAGQtoclmm(). A user who passes it in...now gets this error instead of a fit with the wrong link.method = "ucminf"gives theclmm()warning thatclmm()usesnlminb()instead.Documentation
The PR documents the exception for these two links in
?projpred-package. The regeneratedman/projpred-package.Rdalso moves the paragraph aboutucminf()forclmm()(#596) to theordinal::clmm()item, where the roxygen source has it. The old.Rdhad it under theMASS::polr()item.Tests
Tests:
test_fit_cumul_mlvl.R. It uses data from a cloglog model and from a loglog model, both without group effects. Thefit_cumul_mlvl()fit equals theclm()fit with the same link withinexpect_equal(tolerance = 0.05). Its largest absolute coefficient difference to that fit is less than 1/5 of the one to theclm()fit with the other link. Both hold with and without acontrolfrom the user. Without the change inR/divergence_minimizers.R, 6 of these expectations fail.test_fit_cumul_mlvl.Ruseswithr::local_seed()instead ofset.seed(), so the tests leave the random seed of the session unchanged (as required since Tests: leave the R session unchanged after the tests and remove the manual cleanup #586).NOT_CRAN=trueon 8c9fd76: 40 files, 58,045 expectations, 0 failures, 5 skipped. The later commits change only comments, documentation, NEWS andtest_fit_cumul_mlvl.R. That test file passes on 7baf8ce (38 expectations).