Learn R Programming

regplot (version 0.2)

regplot: Plots a regression nomogram showing covariate distribution.

Description

regplot plots a regression nomogram. Covariate distributions are superimposed on nomogram scales and the plot is animated to allow on-the-fly changes to distribution representation and to enable outcome calculation.

Usage

regplot(reg, dummies = FALSE, center = TRUE, observation = NULL,
  title = NULL, points = TRUE, failtime = NULL, prfail = TRUE,
  baseS = NULL, odds = FALSE, droplines = FALSE, nsamp = 5000,
  showi = TRUE, showP = TRUE, rank = NULL, subticks = FALSE,
  interval = NULL, colors = NULL)

Arguments

reg

A regression object of either class glm, glm.nb, lm, survreg or coxph

dummies

TRUE to treat dummy indicators of factor variables as distinct binary variables, with their own nomogram panel. Otherwise different categories of the factor are represented on the same panel.

center

Produces plot in which regression score contributions of continuous data are plotted with respect to mean values of non-factors.

observation

An observation, data frame, whose values are superimposed on the plot. Must include all variables used in the regression formula.

title

A heading title written to the plot

points

If FALSE the regression scores \(\beta\)\(x\) are shown. Otherwise the scale is represented by a 0-100 "points" scale.

failtime

Specifies the cut-off time(s) for plotting the risk nomogram of a coxph or survreg regression (if failtime=NULL, cut-off is the median of time variable)

prfail

For survival models. TRUE if probability of failure before failtime is summarised, otherwise after failtime.

baseS

Only relevant for coxph regressions and, if non-null, specifies the baseline survival probability, or probabilities, corresponding to the specified failtime (otherwise this probability is computed within regplotusing function basehaz).

odds

For probability outcomes (logistic, cox and survreg models), the output nomogram scale is odds rather than probability.

droplines

Draws faint vertical lines showing score contributions to an observation.

nsamp

The size of a random sample of data to plot distributions (if huge data plotting may be slow).

showi

Whether interactions (if present) are to be shown as a panel of the plot.

showP

Whether P-value regression coefficient asterisk codes are to be displayed.

rank

Allows panels to be ranked by importance to the regression. Importance is measured by standard deviation along nomogram scales (equivalent to standardized regression coefficients for non-factors) NULL for no ranking (ordered as the regression), otherwise "decreasing" or "increasing".

subticks

Whether to put intervening minor tick marks on axes.

interval

draws an interval (confidence or prediction) for outcomes associated with the observation (see Details)

colors

A list of colors that will override the default colors. May include: dencol color fill of density plots, boxcol color fill of frequency boxes, obscol color of superimposed observation, spkcol color of spikes.

Value

If points=TRUE a points.tables object is returned as a list of dataframes, each frame giving points per covariate, and a total points-to-outcome look-up table.

Details

Creates a nomogram representation of a fitted regression. The distribution of covariates in the model, and of the total regression score, can be superimposed on the nomogram scales. Also the values of a particular observation can be overlaid, with outcome calculated. If interval is specified a (95%) confidence interval on the outcome is displayed. For lm and glm OLS regressions a prediction interval can be requested. The plot is active for mouse input allowing on-the-fly changes to distribution type (boxes, spikes, box plot, density, empirical cdf, violin and bean plots) and also to observation values, making it a regression calculator. The regression object reg parameter must have been fitted by either glm, lm, survreg, coxph or glm.nb. For glm, the supported family/link pairings are: gaussian/identity, binomial/logit, and poisson/log. For survreg the distribution may be lognormal, gaussian, weibull, exponential or loglogistic. For glm.nb (negative binomial regression) only log-link is allowed.

Examples

Run this code
# NOT RUN {
library(survival)
 data(pbc) 
 pbc$catbili <- cut(pbc$bili,breaks=c(-Inf, 2, 4, Inf),
                labels=c("low","medium","high"))
 pbc$died <- pbc$status==2
 pbccox <-  coxph(formula = Surv(time,died) ~  age + catbili + sex + 
                  copper +stage + trt,data=pbc)
 ## Plot a Cox survival model, showing data for the first observation.
 ## Display risk for 730, and 1825 days
  regplot(pbccox,observation=pbc[1,],  failtime = c(730,1825), prfail = TRUE ) 
 ## Plot a Weibull model 
  pbcweib <-  survreg(formula = Surv(time,died) ~  age + catbili + sex + 
                  copper +stage + trt,dist="weibull", data=pbc)
 regplot(pbcweib,observation=pbc[1,], failtime = 1825, prfail = TRUE ) 
 ## Plot a logistic regression, showing odds scale and confidence interval
 pbcglm <- glm(died ~  age + catbili + sex + copper,family = "binomial", data=pbc )
 regplot(pbcglm, observation=pbc[1,], odds=TRUE,interval="confidence")
# }

Run the code above in your browser using DataLab