plot.orm: Plot the prediction with confidence intervals

View source: R/ormPredictionplot.R

plot.ormR Documentation

Plot the prediction with confidence intervals

Description

This function plots the model predictions given that all variables that are not included in the plot are kept constant. Hence it requires at least one variable to produce a plot. returns a ggplot object that can be further customized like any other ggplot

Usage

## S3 method for class 'orm'
plot(
  x,
  xval,
  plot_cols = c(),
  plot_rows = c(),
  label_with_colname = TRUE,
  facet_labels = NULL,
  xlab = NULL,
  ylab = NULL,
  np = 100,
  fun = stats::plogis,
  boot.type = "bca",
  conf.int = 0.95,
  ...
)

Arguments

x

an object created by Predict

xval

The model value plotted on the x axis

plot_cols

A vector of strings with other model components that should be plotted. These are put on columns.

plot_rows

A vector of strings with other model components that should be plotted. These are put on rows.

label_with_colname

Should he variable name also be included on plot row and column names

facet_labels

A named list of new names for variables on rows and columns

xlab

A custom x-axis value (if specified)

ylab

A custom y-axis value (if specified)

np

the number of equally-spaced points computed for continuous predictors that vary, i.e., when the specified value is . or NA

fun

an optional transformation of the linear predictor. Specify fun='mean' if the fit is a proportional odds model fit and you ran bootcov with coef.reps=TRUE. This will let the mean function be re-estimated for each bootstrap rep to properly account for all sources of uncertainty in estimating the mean response. fun can be a general function and can compute confidence limits (stored as a list in the limits attribute) of the transformed parameters such as means.

boot.type

set to 'bca' to compute BCa confidence limits or 'basic' to use the basic bootstrap. The default is to compute percentile intervals

conf.int

confidence level (highest posterior density interval probability for Bayesian models). Default is 0.95. Specify FALSE to suppress.

...

additional parameters that will be passed to Predict

Value

a ggplot plot object

See Also

Predict, datadist, orm

Examples

#load the libraries
library(rms)
library(ormPlot)

#make the datadist
dd<-datadist(educ_data)
options(datadist='dd')

#create the model
cran_model <- orm(educ_3 ~ Rural + sex + max_SEP_3 + cran_rzs, data = educ_data)

#plot the predictions of the model for varying one variable only
plot(cran_model, cran_rzs)

#customize the plotting varying all variables
plot(cran_model, cran_rzs,
      plot_cols = max_SEP_3,
      plot_rows = c(Rural, sex),

      #setting new x-label (optional)
     xlab = "Cranial volume (residuals to age an birth date)",

     #setting new facet labels (optional)
     facet_labels = list(Rural = c("Urban", "Rural"),
                          sex = c("Boys","Girls"))
     )

rix133/ormPlot documentation built on Sept. 20, 2023, 5:53 a.m.