| Title: | Cumulative Odds Ratio Plot |
|---|---|
| Description: | Create cumulative odds ratio plot to visually inspect the proportional odds assumption from the proportional odds model. |
| Authors: | Yongxi Long [aut, cre, cph] |
| Maintainer: | Yongxi Long <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 1.0.1 |
| Built: | 2026-06-01 11:01:08 UTC |
| Source: | https://github.com/yongxi-long/corplot |
This function produces a cumulative odds ratio (COR) plot for an ordinal outcome. Users can either provide a dataset with a formula and grouping variable so that odds ratios are estimated internally, or supply a pre-computed data frame of odds ratios directly.
CORPlot( data = NULL, formula = NULL, GroupName = NULL, upper = FALSE, confLevel = 0.95, OR_df = NULL )CORPlot( data = NULL, formula = NULL, GroupName = NULL, upper = FALSE, confLevel = 0.95, OR_df = NULL )
data |
A data frame containing the outcome and covariate(s).
Required if |
formula |
A model formula specifying the ordinal outcome on the left-hand side
and the grouping variable (or covariates) on the right-hand side
(e.g., |
GroupName |
Optional character string specifying the name
of the grouping (exposure) variable for which odds ratios are
to be extracted. If |
upper |
Logical; if |
confLevel |
Confidence level; default is 0.95 |
OR_df |
Optional data frame of externally computed odds ratios. Must contain at least the following columns:
If supplied, the arguments |
If OR_df is not supplied, the function internally fits two models:
a multinomial regression via PerformLogReg to estimate binary odds ratios for each cutpoint,
and a proportional odds model via PerformPO to estimate the common odds ratio.
These are combined into a single data frame and visualized.
A list with two elements:
ORs: A data frame of odds ratios used for plotting.
plot: A ggplot2 object displaying the cumulative odds ratio plot.
# Use internal model fitting data(df_MR_CLEAN) res <- CORPlot( data = df_MR_CLEAN, formula = mRS ~ group, GroupName = "group", confLevel = 0.90 ) res[["Cumulative Odds Ratio Plot"]] # show the plot # Use external OR data.frame OR_df <- data.frame( Label = c("score<=1", "score<=2", "common OR"), OR = c(1.2, 1.5, 1.3), lowerCI = c(0.9, 1.1, 1.0), upperCI = c(1.6, 2.0, 1.7) ) res2 <- CORPlot(OR_df = OR_df) res2[["Cumulative Odds Ratio Plot"]]# Use internal model fitting data(df_MR_CLEAN) res <- CORPlot( data = df_MR_CLEAN, formula = mRS ~ group, GroupName = "group", confLevel = 0.90 ) res[["Cumulative Odds Ratio Plot"]] # show the plot # Use external OR data.frame OR_df <- data.frame( Label = c("score<=1", "score<=2", "common OR"), OR = c(1.2, 1.5, 1.3), lowerCI = c(0.9, 1.1, 1.0), upperCI = c(1.6, 2.0, 1.7) ) res2 <- CORPlot(OR_df = OR_df) res2[["Cumulative Odds Ratio Plot"]]
Patient outcome data from the MR CLEAN trial
df_MR_CLEANdf_MR_CLEAN
df_MR_CLEANA data frame with 500 rows and 2 columns:
Modified Rankin Scale
Treatment group assignment; 1 = Intervention; 0 = Control
Sex indicator; 1 = women; 0 = men
DOI: 10.1056/NEJMoa1411587
Fits a cumulative logistic regression model for an ordinal outcome using VGAM, and extracts the estimated binary odds ratios and 95% confidence intervals for the specified grouping variable across all possible cutpoints
PerformLogReg(data, formula, GroupName = NULL, upper = FALSE, confLevel = 0.95)PerformLogReg(data, formula, GroupName = NULL, upper = FALSE, confLevel = 0.95)
data |
A data frame containing variables in the model |
formula |
A formula specifying the model, with an ordinal
outcome on the left-hand side and one or more predictors
on the right-hand side (e.g. |
GroupName |
Optional character string specifying the name
of the grouping (exposure) variable for which odds ratios are
to be extracted. If |
upper |
Logical; if |
confLevel |
Confidence level; default is 0.95 |
The function uses vglm with
cumulative family to fit an ordinal
regression model without the proportional odds assumption
(parallel = FALSE). Confidence intervals are computed
using confint; if this fails, confidence
intervals are returned as NA.
A data frame with one row per binary cut-point. Columns are:
Text label of the cut-point (e.g. "mRS <= 2").
Estimated odds ratio for GroupName.
Lower bound of the 95% confidence interval.
Upper bound of the 95% confidence interval.
if (requireNamespace("VGAM", quietly = TRUE)) { # Simulated data set.seed(123) dat <- data.frame( mRS = factor(sample(0:3, 100, replace = TRUE), ordered = TRUE), group = sample(c("A", "B"), 100, replace = TRUE) ) # Fit and extract odds ratios PerformLogReg(dat, mRS ~ group, GroupName = "group") }if (requireNamespace("VGAM", quietly = TRUE)) { # Simulated data set.seed(123) dat <- data.frame( mRS = factor(sample(0:3, 100, replace = TRUE), ordered = TRUE), group = sample(c("A", "B"), 100, replace = TRUE) ) # Fit and extract odds ratios PerformLogReg(dat, mRS ~ group, GroupName = "group") }
Fits a proportional odds model for an ordinal outcome using VGAM, and extracts the estimated common odds ratio and its 95% confidence intervals for the specified grouping variable
PerformPO(data, formula, GroupName = NULL, upper = FALSE, confLevel = 0.95)PerformPO(data, formula, GroupName = NULL, upper = FALSE, confLevel = 0.95)
data |
A data frame containing variables in the model |
formula |
A formula specifying the model, with an ordinal
outcome on the left-hand side and one or more predictors
on the right-hand side (e.g. |
GroupName |
Optional character string specifying the name
of the grouping (exposure) variable for which odds ratios are
to be extracted. If |
upper |
Logical; if |
confLevel |
Confidence level; default is 0.95 |
The function uses vglm with
cumulative family to fit an ordinal
regression model with the proportional odds assumption
(parallel = TRUE). Confidence intervals are computed
using confint; if this fails, confidence
intervals are returned as NA.
A data frame with one row. Columns are:
common OR
Estimated common odds ratio for GroupName.
Lower bound of the 95% confidence interval.
Upper bound of the 95% confidence interval.
if (requireNamespace("VGAM", quietly = TRUE)) { # Simulated data set.seed(123) dat <- data.frame( mRS = factor(sample(0:3, 100, replace = TRUE), ordered = TRUE), group = sample(c("A", "B"), 100, replace = TRUE) ) # Fit and extract the common odds ratio PerformPO(dat, mRS ~ group, GroupName = "group") }if (requireNamespace("VGAM", quietly = TRUE)) { # Simulated data set.seed(123) dat <- data.frame( mRS = factor(sample(0:3, 100, replace = TRUE), ordered = TRUE), group = sample(c("A", "B"), 100, replace = TRUE) ) # Fit and extract the common odds ratio PerformPO(dat, mRS ~ group, GroupName = "group") }