Learn R Programming

rms (version 6.8-0)

rexVar: rexVar

Description

Relative Explained Variation

Usage

rexVar(object, data, ns = 500, cint = 0.95)

Value

a vector (if bootstrapping or Bayesian posterior sampling was not done) or a matrix otherwise, with rows corresponding to predictors and colums REV, Lower, Upper. The returned object is of class rexVar.

Arguments

object

a fit from rms or rmsb

data

a data frame, data table, or list providing the predictors used in the original fit

ns

maximum number of bootstrap repetitions or posterior draws to use

cint

confidence interval coverage probability for nonparametric bootstrap percentile intervals, or probability for a Bayesian highest posterior density interval for the relative explained variations.

Author

Frank Harrell

Details

Computes measures of relative explained variation for each predictor in an rms or rmsb model fit object. This is similar to plot(anova(fit), what='proportion R2'). For an ols model the result is exactly that. Uncertainty intervals are computed if the model fit is from rmsb or was run through bootcov() with coef.reps=TRUE. The results may be printed, and there is also a plot method.

When object is not an ols fit, the linear predictor from the fit in object is predicted from the original predictors, resulting in a linear model with \(R^{2}=1.0\). The partial \(R^2\) for each predictor from a new ols fit is the relative explained variation. The process is repeated when bootstrap coefficients repetitions or posterior draws are present, to get uncertainty intervals. So relative explained variation is the proportion of variation in the initial model's predicted values (on the linear predictor scale) that is due to each predictor.

Nonlinear and interaction terms are pooled with main linear effect of predictors, so relative explained variation for a predictor measures its total impact on predicted values, either as main effects or effect modifiers (interaction components).

Examples

Run this code
set.seed(1)
n <- 100
x1 <- rnorm(n)
x2 <- rnorm(n)
x3 <- rnorm(n)
y  <- x1 + x2 + rnorm(n) / 2.
d <- data.frame(x1, x2, x3, y)
dd <- datadist(d); options(datadist='dd')
f  <- ols(y ~ pol(x1, 2) * pol(x2, 2) + x3,
          data=d, x=TRUE, y=TRUE)
plot(anova(f), what='proportion R2', pl=FALSE)
rexVar(f)
g <- bootcov(f, B=20, coef.reps=TRUE)
rexVar(g, data=d)
f <- orm(y ~ pol(x1,2) * pol(x2, 2) + x3,
         data=d, x=TRUE, y=TRUE)
rexVar(f, data=d)
g <- bootcov(f, B=20, coef.reps=TRUE)
rexVar(g, data=d)
if (FALSE) {
require(rmsb)
h <- blrm(y ~ pol(x1,2) * pol(x2, 2) + x3, data=d)
rexVar(h, data=d)
}
options(datadist=NULL)

Run the code above in your browser using DataLab