Title: Cumulative Odds Ratio Plot
Version: 1.0.2
Description: Create cumulative odds ratio plot to visually inspect the proportional odds assumption from the proportional odds model.
License: MIT + file LICENSE
Encoding: UTF-8
RoxygenNote: 7.3.2
URL: https://github.com/Yongxi-Long/CORPlot
BugReports: https://github.com/Yongxi-Long/CORPlot/issues
Suggests: testthat (≥ 3.0.0)
Config/testthat/edition: 3
Depends: R (≥ 3.5)
LazyData: true
Imports: ggplot2, knitr, stats, VGAM
NeedsCompilation: no
Packaged: 2025-09-26 14:25:18 UTC; ylong
Author: Yongxi Long [aut, cre, cph]
Maintainer: Yongxi Long <y.long@lumc.nl>
Repository: CRAN
Date/Publication: 2025-10-03 12:50:02 UTC

Create Cumulative Odds Ratio Plot

Description

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.

Usage

CORPlot(
  data = NULL,
  formula = NULL,
  GroupName = NULL,
  upper = FALSE,
  confLevel = 0.95,
  OR_df = NULL
)

Arguments

data

A data frame containing the outcome and covariate(s). Required if OR_df is not supplied

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., mRS ~ group). Required if OR_df is not supplied.

GroupName

Optional character string specifying the name of the grouping (exposure) variable for which odds ratios are to be extracted. If NULL (default), the first covariate in the formula is used.

upper

Logical; if FALSE (default), odds ratios correspond to the probability of the outcome being less than or equal to each cut-point. If TRUE, odds ratios are based on the probability of being greater than or equal to each cut-point.

confLevel

Confidence level; default is 0.95

OR_df

Optional data frame of externally computed odds ratios. Must contain at least the following columns:

  • Label (character or factor): cut-point labels, with one row labeled "common OR" (case-insensitive).

  • OR (numeric): odds ratio estimates.

  • lowerCI (numeric): lower confidence interval bound.

  • upperCI (numeric): upper confidence interval bound.

If supplied, the arguments data, formula, and GroupName are ignored.

Details

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.

Value

A list with two elements:

Examples

# 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"]]

Perform Cumulative Logistic Regression and Extract Binary Odds Ratios

Description

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

Usage

PerformLogReg(data, formula, GroupName = NULL, upper = FALSE, confLevel = 0.95)

Arguments

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. mRS ~ group).

GroupName

Optional character string specifying the name of the grouping (exposure) variable for which odds ratios are to be extracted. If NULL (default), the first covariate in the formula is used.

upper

Logical; if FALSE (default), odds ratios correspond to the probability of the outcome being less than or equal to each cut-point. If TRUE, odds ratios are based on the probability of being greater than or equal to each cut-point.

confLevel

Confidence level; default is 0.95

Details

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.

Value

A data frame with one row per binary cut-point. Columns are:

Label

Text label of the cut-point (e.g. "mRS <= 2").

OR

Estimated odds ratio for GroupName.

lower95CI

Lower bound of the 95% confidence interval.

upper95CI

Upper bound of the 95% confidence interval.

Examples

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")
}


Perform Proportional Odds Model and Extract the Common Odds Ratio

Description

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

Usage

PerformPO(data, formula, GroupName = NULL, upper = FALSE, confLevel = 0.95)

Arguments

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. mRS ~ group).

GroupName

Optional character string specifying the name of the grouping (exposure) variable for which odds ratios are to be extracted. If NULL (default), the first covariate in the formula is used.

upper

Logical; if FALSE (default), odds ratios correspond to the probability of the outcome being less than or equal to each cut-point. If TRUE, odds ratios are based on the probability of being greater than or equal to each cut-point.

confLevel

Confidence level; default is 0.95

Details

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.

Value

A data frame with one row. Columns are:

Label

common OR

OR

Estimated common odds ratio for GroupName.

lower95CI

Lower bound of the 95% confidence interval.

upper95CI

Upper bound of the 95% confidence interval.

Examples

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")
}

MR CLEAN trial data

Description

Patient outcome data from the MR CLEAN trial

Usage

df_MR_CLEAN

Format

df_MR_CLEAN

A data frame with 500 rows and 2 columns:

mRS

Modified Rankin Scale

group

Treatment group assignment; 1 = Intervention; 0 = Control

sex

Sex indicator; 1 = women; 0 = men

Source

DOI: 10.1056/NEJMoa1411587