ordPredArgmax: Argmax Mapping from an Estimated Probability Distribution (EPD) to a Predicted Class
Description
Deterministically maps each row of an estimated probability distribution (EPD)
matrix to a single predicted class by taking the index of the maximum
probability. Rows are normalized to sum to one (within tolerance). Ties can
be broken by first, last, or at random among maximizers.
Usage
ordPredArgmax(P, tie_break = c("first", "random", "last"), tol = 1e-12)
Value
An integer vector of length \(n\) with the predicted class indices
in \(\{1,\ldots,k\}\) for each row of P.
Arguments
P
A numeric matrix of size \(n \times k\), where each row contains
the estimated probabilities \(\hat\pi_{ij}\) for subject \(i\) and
classes \(j = 1,\ldots,k\). Values must be nonnegative; rows are
normalized to sum to one if needed.
tie_break
Character string indicating how to break ties among
equal maxima. One of "first" (default), "last",
or "random".
tol
Numeric tolerance used for (i) row-sum checks and (ii) equality
when identifying ties among maximum probabilities. Defaults to 1e-12.
Details
The function normalizes each row of P to sum to one (within
tol). Rows with (near) zero total probability trigger an error.
If multiple classes achieve the same (within tol) maximum probability,
the returned class depends on tie_break:
"first" — smallest index among maximizers (default).
"last" — largest index among maximizers.
"random" — one index sampled uniformly from the set of
maximizers.