R/ordinal-assessment.R
fastglm_ordinal_assess.RdCompares predicted cumulative probabilities with observed frequencies, scores the full ordered prediction distribution, and optionally compares predictor slopes across binary divisions of the outcome scale or tests the common-slope restriction using an analytic score statistic.
fastglm_ordinal_assess(
object,
newdata = NULL,
y = NULL,
weights = NULL,
offset = NULL,
bins = 10L,
proportional.odds = FALSE,
po.control = list(),
po.test = c("none", "score"),
po.terms = NULL,
po.test.control = list(),
po.estimation = c("ML", "meanBR"),
keep.rows = NULL,
sink = NULL
)
# S3 method for class 'fastglm_ordinal_assessment'
print(x, digits = max(3L, getOption("digits") - 3L), ...)
# S3 method for class 'fastglm_ordinal_assessment'
plot(x, type = c("calibration", "proportional.odds"), level = 0.95, ...)a converged fastglm_ordinal model.
prediction data frame or matrix, as in predict.
ordered outcomes, category labels, numeric codes in the fitted
category order, or a matrix of category counts. Required with
newdata; otherwise defaults to the retained fitting response or
rereads the original response of an ordinal source fit.
Named count columns are aligned with the fitted category labels.
frequency weights. Defaults to the fitting weights only when
both newdata and y are omitted; otherwise defaults to one.
Counts times weights, or individual weights, must be integer frequencies.
optional replacement prediction offset.
positive integer number of equal-width calibration bins on \([0,1]\). Bin boundaries do not depend on observed outcomes.
also fit separate mean bias-reduced binary models at each threshold, using the fitted cumulative link and the assessment rows and offsets. Reported slopes use the ordinal sign convention. Complementary-log-log fits model \(Y\leq j\) directly; logit and probit fits use their equivalent reversed-tail representation for \(Y>j\).
named list containing tol and/or maxit for
these auxiliary binary fits; defaults are 1e-8 and 200.
"none" (default) or "score" for an analytic
expected-information score test of the common-slope restriction.
optional formula term names, or predictor column names for a matrix fit, to test jointly. The default tests all location predictors. All columns belonging to a selected formula term are included. For a partial model, the default selects its varying terms and tests their equal-slope restrictions while leaving other varying effects unrestricted. Already-common terms add no restrictions, rather than zero-effect tests.
named list containing tol and/or maxit
for the requested null refit; defaults are 1e-10 and 500.
"ML" (default) or "meanBR" for the
score-test null fit. See fastglm_po_test for the interpretation
and limitations of the mean-bias-reduced alternative.
retain the individual row-score table. The default,
NULL, retains it for dense or explicitly supplied evaluation data
and omits it when rereading a fitted source. Retaining source rows requires
memory proportional to the number of observations.
optional function of (value, chunk_index) receiving a
data frame of row scores for each original source block. For example,
this function can write each block to a file. Its return value is ignored.
It is used only when assessing the original fitted source.
an ordinal assessment object.
number of significant digits used for printing.
additional arguments passed to the plotting function; unused by the print method.
cumulative calibration or the descriptive proportional-odds slope comparison.
level for separate Wald intervals in the slope display. These are not simultaneous intervals or tests of differences between thresholds.
An object of class fastglm_ordinal_assessment, containing
scores, the overall frequency-weighted losses; rows, individual
row averages and exclusions (NULL when keep.rows=FALSE);
calibration, predicted and observed
cumulative probabilities by threshold and bin; and proportional.odds,
the optional slope comparison table. proportional.odds.test is
NULL unless requested; otherwise it records statistic,
df, p.value, available, tested terms and columns,
null convergence, frequency, warnings, and an unavailability reason
and explanation. It also records the evaluation source,
category order, and exclusion counts. Plot methods use these saved tables.
The ranked probability score (rps) is
\(\sum_{j=1}^{K-1}\{F_j-I(Y\leq j)\}^2\);
rps_normalized divides by \(K-1\), and lies between zero and one.
log_loss is \(-\log p_Y\). All are losses: smaller values are
better. Grouped rows average the individual-outcome losses, rather than
squaring differences from grouped outcome proportions. Overall scores
average over the included individual frequency. Log probabilities are
evaluated directly without clipping. A positive count in a category with
structural probability zero has infinite log loss; a zero count contributes
zero. Extremely small positive probabilities can have a finite log loss
even when the displayed probability underflows to zero.
Missing outcomes, weights, predictors, or offsets, and zero-frequency rows,
are retained in rows with missing scores and an exclusion reason.
Infinite predictors or offsets are errors. Empty calibration bins remain
in the table with zero frequency and missing means. With no usable outcomes,
overall scores are missing. Bins include their lower boundary; the last bin
also includes one. Fitting rows omitted under na.exclude
are restored when assessing the original response. Explicit responses with
no newdata must match the retained design rows.
Scores on the fitting outcomes describe apparent performance. Supplying
held-out outcomes evaluates the frozen model; the function does not establish
that those outcomes were excluded during fitting. The optional binary fits
use the supplied assessment outcomes and design when supplied. They affect
only the proportional-odds display, never predictions or scores. The dashed
reference slopes always come from the original ordinal model.
Positive slopes correspond to higher outcomes, matching the ordinal model.
The binary estimates are correlated, and bias reduction can produce different
finite-sample changes at each threshold. Their separate standard errors are
descriptive; neither interval overlap nor this plot is a formal test of
proportional odds. Thresholds with no outcome variation or unsuccessful
fits retain their status and have unavailable estimates. A threshold is also
unavailable when binary count conversion would round a positive minority
frequency away (unrepresentable_binary_counts). Calibration alone
is also not a test of proportional odds.
With po.test="score", a common-slope null on the fitted link is refitted to
the included assessment outcomes, predictors, frequencies, and offsets.
Maximum likelihood is the default, including when object used
mean bias reduction. Set po.estimation="meanBR" to request a
mean-bias-reduced null explicitly. The resulting ordinary efficient score
retains its nuisance projection and has only first-order justification;
it can be conservative in small samples. The null refit
affects neither the original model nor the prediction scores. With
supplied outcomes, the test concerns the common-slope restriction in those
outcomes, rather than calibration of the original model's coefficients.
The score uses expected Fisher information, averaged analytically over
possible outcomes under this null, and projects out the threshold,
common-slope, and any untested varying-effect nuisance scores. No
resampling is used for its p-value.
If s design columns are tested across K categories, the
asymptotic chi-square reference has s*(K-2) degrees of freedom.
For a common-slope fit, other predictors retain common slopes in both the
null and the local alternative. For a partial fit, other varying effects
remain unrestricted. The latter uses the term-equality construction in
fastglm_po_test. The descriptive binary-slope comparison is
available only for common-slope fits. Independent observations and a
correctly specified, identifiable interior null are required. The
approximation can be inaccurate in small or sparse samples; a large
p-value does not establish proportional odds. The test is not a robust,
cluster-adjusted, or higher-order bias-corrected test.
The score test uses dense data or a repeatable source, at least three declared
categories, at least one tested predictor, and positive frequency in every
category. Empty categories, deficient rank, failed null fits, and
unavailable information produce missing statistics and p-values with an
explicit reason. Categories and degrees of freedom are not silently
reduced, and the calculation does not switch to a mean bias-reduced fit.
The descriptive slope comparison and formal test can be requested
independently. Formula term selection requires retained design assignments
from a current ordinal fit, including when model=FALSE.
Scoring and calibration use blocks of rows and require work proportional to the number of rows times the number of categories. The optional binary comparison fits one model per threshold without expanding frequency rows. The score test also processes frequencies without expanding observations; its information matrix grows with the predictor and category dimensions.
For an ordinal source fit with no supplied evaluation data, scoring and
calibration reread the recorded source once. The same frequency, offset,
category, and prediction calculations as dense assessment are used.
The source must return unchanged rows and values. Weights and offsets
cannot be replaced in this mode. Summary storage depends on the number of
categories and bins; row calculations use the current source block.
keep.rows=TRUE collects the row table, while sink can save
it block by block. Source assessment describes apparent performance on
the fitting outcomes. The optional common-slope score test requires
additional source passes for refitting and information accumulation.
Descriptive binary-slope comparisons still require explicit evaluation data.
The plot method uses ggplot2 when it is installed and base graphics
otherwise. With ggplot2, main, xlab, ylab, xlim, ylim, pch, col,
and cex are honored, and main titles the whole figure.
Epstein, E. S. (1969). A scoring system for probability forecasts of ranked categories. Journal of Applied Meteorology, 8, 985–987.
Gneiting, T. and Raftery, A. E. (2007). Strictly proper scoring rules, prediction, and estimation. Journal of the American Statistical Association, 102, 359–378. doi:10.1198/016214506000001437 .
Brant, R. (1990). Assessing proportionality in the proportional odds model for ordinal logistic regression. Biometrics, 46, 1171–1178. doi:10.2307/2532457 .
SAS Institute Inc. (2013). SAS/STAT 12.3 User's Guide. The LOGISTIC Procedure, Score Statistics and Tests, pp. 4246–4248. Expected and observed information define distinct finite-sample score calculations; this implementation uses expected information.