Type: Package
Title: Output Results from 'rms' Models for Medical Journals
Version: 1.0.0
Date: 2025-06-16
Description: Provides streamlined functions for summarising and visualising regression models fitted with the 'rms' package, in the preferred format for medical journals. The 'modelsummary_rms()' function produces concise summaries for linear, logistic, and Cox regression models, including automatic handling of models containing restricted cubic spline (RCS) terms. The resulting summary dataframe can be easily converted into publication-ready documents using the 'flextable' and 'officer' packages. The 'ggrmsMD()' function creates clear and customizable plots ('ggplot2' objects) to visualise RCS terms.
License: MIT + file LICENSE
Encoding: UTF-8
URL: https://rmsmd.github.io/rmsMD/
BugReports: https://github.com/rmsMD/rmsMD/issues/
RoxygenNote: 7.3.2
Imports: rms, ggplot2, rlang, cowplot
Suggests: knitr, rmarkdown, devtools, officer, flextable, dplyr, testthat (≥ 3.0.0), vdiffr
VignetteBuilder: knitr
Config/testthat/edition: 3
NeedsCompilation: no
Packaged: 2025-06-17 16:14:43 UTC; samueltingle
Author: Samuel Tingle ORCID iD [aut, cre], Georgios Kourounis ORCID iD [aut]
Maintainer: Samuel Tingle <samjamestingle@gmail.com>
Repository: CRAN
Date/Publication: 2025-06-17 23:50:02 UTC

Create plots for RCS variables from an rms model

Description

The ggrmsMD function processes the output from models fitted using the rms package and produces one or more ggplot2 objects visualising restricted cubic splines (RCS). The function detects RCS terms in the model and plots them all, with a suitable y-axis selected based on the model type. This outputs a list of plots, or a multi-panel figure using the combined argument. As outputs are ggplot objects they can easily be further customised by the user.

Usage

ggrmsMD(
  modelfit,
  data,
  noeffline = TRUE,
  shade_inferior = "none",
  combined = TRUE,
  ylab = NULL,
  xlabs = NULL,
  titles = NULL,
  ylim = NULL,
  log_y = FALSE,
  log_y_breaks = NULL,
  xlims = NULL,
  log_x_vars = NULL,
  log_x_breaks = NULL,
  lrm_prob = FALSE,
  var = NULL,
  np = 400,
  ...
)

Arguments

modelfit

A model object from ols, lrm, or cph (from the rms package).

data

The dataset used to fit the model.

noeffline

Logical. If TRUE (default), adds a horizontal dashed line at 1 for odds/hazard ratio plots.

shade_inferior

Character. Options are "none" (default), "higher", or "lower". Applies red/green shading above or below 1 on the y-axis to indicate worse/better outcomes.

combined

Logical. If TRUE, returns a single multi-panel plot using cowplot::plot_grid().

ylab

Optional character. Override the default y-axis label.

xlabs

A named list of x-axis labels for each variable. E.g., ⁠list(age = "Age (years)", bmi = "BMI (kg/m²"))⁠.

titles

A named list of plot titles for each variable.

ylim

Numeric vector (length 2). y-axis limits applied to all plots. E.g., c(0.5, 2).

log_y

Logical. If TRUE, y-axis is log10-transformed.

log_y_breaks

Optional numeric vector specifying y-axis tick marks when log_y = TRUE. E.g., c(0.25, 0.5, 1, 2, 4).

xlims

A named list of x-axis limits per variable. E.g., list(age = c(20, 80)).

log_x_vars

Character vector. Names of variables for which x-axis should be log10-transformed.

log_x_breaks

A named list specifying x-axis tick marks for variables with log10-transformed x-axis.

lrm_prob

Logical. If TRUE and model is lrm, plots predicted probabilities instead of odds ratios.

var

Character vector. Optional. Variables to plot. If NULL (default), all RCS variables in the model will be plotted.

np

Integer. Number of points used to predict spline curves. Default is 400. Consider increasing when using log-transformed x-axes.

...

Additional arguments passed to cowplot::plot_grid() when combined = TRUE.

Value

A ggplot object (if one variable is plotted), a list of ggplot objects (if multiple variables), or a single combined cowplot plot if combined = TRUE.

Examples

# For details examples and plots please see the provided vignettes


Create model summary for rms models

Description

The modelsummary_rms function processes the output from models fitted using the rms package and generates a summarized dataframe of the results. This summary is tailored for publication in medical journals, presenting effect estimates, confidence intervals, and p-values.

Usage

modelsummary_rms(
  modelfit,
  combine_ci = TRUE,
  round_dp_coef = 3,
  round_dp_p = 3,
  rcs_overallp = TRUE,
  hide_rcs_coef = TRUE,
  exp_coef = NULL,
  fullmodel = FALSE,
  MI_lrt = FALSE
)

Arguments

modelfit

The output from an rms model.

combine_ci

If TRUE, combines the effect estimates and 95% confidence intervals into a single column. Default is TRUE.

round_dp_coef

Specifies the number of decimal places to display for the effect estimates. Default is 3.

round_dp_p

Specifies the number of decimal places to display for P values. Default is 3.

rcs_overallp

If TRUE, provides an overall P value for Restricted Cubic Spline (RCS) terms, sourced from anova(modelfit). Automatically selects appropriate test (LR, F or Wald)

hide_rcs_coef

If TRUE, hides the individual coefficients for Restricted Cubic Spline (RCS) variables.

exp_coef

If TRUE, outputs the exponentiated coefficients (exp(coef)) as the effect estimates. Applicable only for model types other than ols, lrm, or cph. If NULL, no exponentiation is performed. Default is NULL.

fullmodel

If TRUE, includes all intermediate steps in the summary, allowing users to verify and compare with standard model outputs.

MI_lrt

If TRUE then overall p-values for RCS terms from models with multiple imputed data from fit.mult.impute will represent likelihood ratio chi-square tests from rms::processMI(), rather than Wald tests.

Value

Returns a dataframe of results. This can easily be outputted to word using packages such as flextable and officer.

Examples

# For detailed examples please see the provided vignettes


Simulated Data for the Vignette

Description

Generates a synthetic dataset for testing and demonstration purposes in the rmsMD package.

Usage

simulated_rmsMD_data(type = c("complete_case", "missing_for_MI"))

Arguments

type

Character string; either "complete_case" (no missing data) or "missing_for_MI" (introduces 10% missing data in each predictor).

Value

A data frame with simulated variables: age, bmi, sex, smoking, majorcomplication, lengthstay, time, and event.