glmmTMB ordinal support - #1221
Conversation
|
Thanks for starting this! Two things I noticed testing it on the
I have a branch that handles both, plus main...jmgirard:insight:glmmtmb-ordinal Happy to open it as a PR, or you can cherry-pick from it into this one, whichever you prefer. One thing on the parameters side: |
Thresholds are stored by glmmTMB as softmax-parameterized family parameters (psi) and the intercept is fixed to zero via an internal map. To match ordinal::clm()/clmm(), find_parameters() and get_parameters() now return the thresholds ahead of the slopes and drop the intercept, get_varcov() transforms the covariance matrix to the threshold scale with the delta method, get_statistic() derives Wald statistics from it (it previously errored on the row-count mismatch), and get_predicted() returns per-category probabilities via predict(type = "probs") for "expectation" and the most likely category for "classification".
Clears the two lint-changed-files diagnostics and the one spelling error introduced by the glmmTMB ordinal() support. The remaining lints and spelling words in these checks predate this branch.
|
Great, thanks a lot! Let me check how Also, I noticed that |
|
Good questions, luckily both should be covered in the branch already.
On CI: the ordinal work is lint- and spelling-clean now; what's still red comes from main (the brms tests on Windows, styling on |
|
Short note: Please don't focus too much on CI-tests, they're not fully reliable, AFAIK, and also yield some false-positives. Main formatting is now done by air, so not all lintr-comments must be followed (although there are always some useful comments). |
|
Let me start a copilot review, I'll also review this PR later in office. |
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved moderate issues affect prediction dispatch, covariance transformation, and prediction argument forwarding.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Adds glmmTMB::ordinal() support across parameter extraction, covariance/statistic calculations, predictions, and variance estimates.
Changes:
- Adds threshold-aware parameters and delta-method covariance handling.
- Supports probability and classification predictions.
- Adds tests and documentation updates.
File summaries
| File | Summary / review note |
|---|---|
tests/testthat/test-glmmTMB-ordinal.R |
Adds ordinal model coverage. |
R/utils_glmmtmb_ordinal.R |
Adds ordinal helpers; moderate issue with forwarding prediction arguments. |
R/get_varcov.R |
Adds ordinal covariance handling; moderate issue with supplied robust covariances. |
R/get_statistic.R |
Adds ordinal Wald statistics. |
R/get_predicted_mixed.R |
Adds ordinal prediction dispatch; moderate issue missing the expected alias. |
R/get_parameters_mixed.R |
Adds threshold parameter extraction. |
R/find_parameters_mixed.R |
Adds ordinal parameter discovery. |
R/compute_variances.R |
Adds ordinal variance handling. |
NEWS.md |
Documents ordinal support; nit regarding placement under the development section. |
inst/WORDLIST |
Adds softmax vocabulary. |
Review details
Suppressed comments (2)
R/get_predicted_mixed.R:120
expectedis an established alias that.get_predicted_args()normalizes toexpectation(R/get_predicted_args.R:108-110), but it is absent from this dispatch list. Consequently,get_predicted(x, predict = "expected")skips this ordinal handler and the generic glmmTMB path returns a transformed scalar link prediction rather than the per-category probability table. Includeexpectedhere.
ordinal_types <- c(
"expectation",
"expected",
"response",
"prediction",
R/utils_glmmtmb_ordinal.R:138
- This ordinal path drops the
...arguments before callingpredict(), even thoughget_predicted.glmmTMB()forwards those arguments for other families and the public API documents them as prediction-method arguments. Options such asna.actionor other supportedpredict.glmmTMB()controls are therefore silently ignored for ordinal models; preserve the remaining dots when constructing this call while overriding the arguments managed by insight.
rez <- stats::predict(
x,
newdata = my_args$data,
type = "probs",
re.form = my_args$re.form,
allow.new.levels = my_args$allow_new_levels,
se.fit = !classification
- Files reviewed: 10/10 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
insight 1.5.4 was released to CRAN without the ordinal support, so the previous floor (1.5.3.2) no longer enforces easystats/insight#1221.
…rward dots insight 1.5.4 was released without the ordinal support, so the NEWS entry moves from the released section to (devel). get_varcov() now rejects supplied covariance matrices for the ordinal family explicitly (they would be on the internal softmax scale), and the ordinal prediction path forwards remaining dot-arguments to predict(), as the other families do.
|
Great, thanks a lot! Looks good to me! |
|
Will run a final local check, and then merge |
…ight#1221) (#1253) * fix standard errors for glmmTMB ordinal() models The thresholds of glmmTMB's ordinal family are not part of the summary coefficient table, so .se_fixed_effects_glmmTMB() silently recycled the slope SEs over the thresholds (or errored when the lengths were not multiples). Standard errors are now taken from insight::get_varcov(), which returns them on the threshold scale via the delta method. * require insight >= 1.5.4.1 insight 1.5.4 was released to CRAN without the ordinal support, so the previous floor (1.5.3.2) no longer enforces easystats/insight#1221. * Add remotes * set versoin in NEWS * add glmmTMB to remotes --------- Co-authored-by: Daniel <mail@danielluedecke.de>
Fixes #1220