View source: R/AUC_nominal_ordinal.R
| orc_table | R Documentation |
Computes the ordinal c-index (ORC) as the mean of pairwise AUCs across all outcome category pairs, closely matching the SPSS implementation discussed earlier. For each pair of categories '(i, j)', the function restricts the data to those two categories and computes the AUC using the pair-specific conditional probability
P(Y = j \mid Y \in \{i,j\}, x) = p_j / (p_i + p_j).
orc_table(outcome, probs, categories = NULL, na_rm = TRUE)
outcome |
A vector containing the observed ordinal dependent variable. May be a numeric/integer vector or an ordered/unordered factor. Its unique values define the outcome categories. |
probs |
A numeric matrix or data frame of predicted probabilities with one row per observation and one column per outcome category. |
categories |
Optional vector giving the category values in the same order as the columns of 'probs'. If 'NULL', the sorted unique values of 'outcome' are used. |
na_rm |
If 'TRUE', observations with missing values in 'outcome' or 'probs' are removed listwise. |
A weighted version is also reported using weights n_i n_j. This
weighted version is a practical extension and not the original ORC definition.
This implementation is closest to the probability-based pairwise ORC definition: for each pair '(i, j)', it uses a pair-specific score derived from the model predictions. For standard proportional-odds models, this produces the same ranking-based ORC as score-based implementations using a single linear predictor or expected-value score.
A list with class '"orc_result"' containing:
Data frame with outcome variable summary information.
Data frame with one row per category pair and columns 'category_i', 'category_j', 'n_i', 'n_j', 'auc', 'weight'.
Data frame with unweighted and weighted ORC.
Numeric scalar, mean of pairwise AUCs.
Numeric scalar, weighted mean of pairwise AUCs using 'n_i * n_j'.
Category vector actually used.
Number of valid cases used.
Van Calster, B., Van Belle, V., Vergouwe, Y., & Steyerberg, E. W. (2012). Discrimination ability of prediction models for ordinal outcomes: relationships between existing measures and a new measure. Statistics in Medicine, 31(21), 2317-2331.
# Example with artificial probabilities:
# outcome <- c(1, 1, 2, 2, 3, 3)
# probs <- rbind(
# c(.60, .30, .10),
# c(.50, .35, .15),
# c(.25, .55, .20),
# c(.20, .50, .30),
# c(.10, .35, .55),
# c(.05, .25, .70)
# )
# res <- orc_table(outcome, probs)
# res$pairwise
# res$summary
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.