Calculate Total and Partial g-indexes for an rms Fit
Calculate Total and Partial g-indexes for an rms Fit
gIndex computes the total g-index for a model based on the vector of linear predictors, and the partial g-index for each predictor in a model. The latter is computed by summing all the terms involving each variable, weighted by their regression coefficients, then computing Gini's mean difference on this sum. For example, a regression model having age and sex and age*sex on the right hand side, with corresponding regression coefficients b1,b2,b3 will have the g-index for age computed from Gini's mean difference on the product of age c("times\n", "\t(b1+b3∗w)") where w is an indicator set to one for observations with sex not equal to the reference value. When there are nonlinear terms associated with a predictor, these terms will also be combined.
A print
method is defined, and there is a plot method for displaying g-indexes using a dot chart.
These functions use Hmisc::GiniMd.
gIndex(object, partials=TRUE, type=c('ccterms','cterms','terms'), lplabel=if(length(object$scale)&& is.character(object$scale)) object$scale[1]else'X*Beta', fun, funlabel=if(missing(fun)) character(0)else deparse(substitute(fun)), postfun=if(length(object$scale)==2) exp elseNULL, postlabel=if(length(postfun)) ifelse(missing(postfun),if((length(object$scale)>1)&& is.character(object$scale)) object$scale[2]else'Anti-log', deparse(substitute(postfun)))else character(0),...)## S3 method for class 'gIndex'print(x, digits=4, abbrev=FALSE, vnames=c("names","labels"),...)## S3 method for class 'gIndex'plot(x, what=c('pre','post'), xlab=NULL, pch=16, rm.totals=FALSE,sort=c('descending','ascending','none'),...)
Arguments
object: result of an rms fitting function
partials: set to FALSE to suppress computation of partial gs
type: defaults to 'ccterms' which causes partial discrimination indexes to be computed after maximally combining all related main effects and interactions. The is usually the only way that makes sense when considering partial linear predictors. Specify type='cterms' to only combine a main effect with interactions containing it, not also with other main effects connected through interactions. Use type='terms' to separate interactions into their own effects.
lplabel: a replacement for default values such as "X*Beta" or "log odds"/
fun: an optional function to transform the linear predictors before computing the total (only) g. When this is present, a new component gtrans is added to the attributes of the object resulting from gIndex.
funlabel: a character string label for fun, otherwise taken from the function name itself
postfun: a function to transform g such as exp
(anti-log), which is the default for certain models such as the logistic and Cox models
postlabel: a label for postfun
...: For gIndex, passed to predict.rms. Ignored for print. Passed to dotchart2
for plot.
x: an object created by gIndex (for print or plot)
digits: causes rounding to the digits decimal place
abbrev: set to TRUE to abbreviate labels if vname="labels"
vnames: set to "labels" to print predictor labels instead of names
what: set to "post" to plot the transformed g-index if there is one (e.g., ratio scale)
xlab: x-axis label; constructed by default
pch: plotting character for point
rm.totals: set to TRUE to remove the total g-index when plotting
sort: specifies how to sort predictors by g-index; default is in descending order going down the dot chart
Details
For stratification factors in a Cox proportional hazards model, there is no contribution of variation towards computing a partial g
except from terms that interact with the stratification variable.
Returns
gIndex returns a matrix of class "gIndex" with auxiliary information stored as attributes, such as variable labels. GiniMd returns a scalar.
References
David HA (1968): Gini's mean difference rediscovered. Biometrika 55:573--575.