Bootstrap Covariance and Distribution for Regression Coefficients
bootcov.Rdbootcov computes a bootstrap estimate of the covariance matrix for a set
of regression coefficients from ols, lrm, cph,
psm, Rq, and any
other fit where x=TRUE, y=TRUE was used to store the data used in making
the original regression fit and where an appropriate fitter function
is provided here. The estimates obtained are not conditional on
the design matrix, but are instead unconditional estimates. For
small sample sizes, this will make a difference as the unconditional
variance estimates are larger. This function will also obtain
bootstrap estimates corrected for cluster sampling (intra-cluster
correlations) when a "working independence" model was used to fit
data which were correlated within clusters. This is done by substituting
cluster sampling with replacement for the usual simple sampling with
replacement. bootcov has an option (coef.reps) that causes all
of the regression coefficient estimates from all of the bootstrap
re-samples to be saved, facilitating computation of nonparametric
bootstrap confidence limits and plotting of the distributions of the
coefficient estimates (using histograms and kernel smoothing estimates).
The loglik option facilitates the calculation of simultaneous
confidence regions from quantities of interest that are functions of
the regression coefficients, using the method of Tibshirani(1996).
With Tibshirani's method, one computes the objective criterion (-2 log
likelihood evaluated at the bootstrap estimate of \(\beta\) but with
respect to the original design matrix and response vector) for the
original fit as well as for all of the bootstrap fits. The confidence
set of the regression coefficients is the set of all coefficients that
are associated with objective function values that are less than or
equal to say the 0.95 quantile of the vector of B + 1 objective
function values. For the coefficients satisfying this condition,
predicted values are computed at a user-specified design matrix X,
and minima and maxima of these predicted values (over the qualifying
bootstrap repetitions) are computed to derive the final simultaneous
confidence band.
The bootplot function takes the output of bootcov and
either plots a histogram and kernel density
estimate of specified regression coefficients (or linear combinations
of them through the use of a specified design matrix X), or a
qqnorm plot of the quantities of interest to check for normality of
the maximum likelihood estimates. bootplot draws vertical lines at
specified quantiles of the bootstrap distribution, and returns these
quantiles for possible printing by the user. Bootstrap estimates may
optionally be transformed by a user-specified function fun before
plotting.
The confplot function also uses the output of bootcov but to
compute and optionally plot nonparametric bootstrap pointwise confidence
limits or (by default) Tibshirani (1996) simultaneous confidence sets.
A design matrix must be specified to allow confplot to compute
quantities of interest such as predicted values across a range
of values or differences in predicted values (plots of effects of
changing one or more predictor variable values).
bootplot and confplot are actually generic functions, with
the particular functions bootplot.bootcov and confplot.bootcov
automatically invoked for bootcov objects.
A service function called histdensity is also provided (for use with
bootplot). It runs hist and density on the same plot, using
twice the number of classes than the default for hist, and 1.5 times the
width than the default used by density.
A comprehensive example demonstrates the use of all of the functions.
When bootstrapping an ordinal model for a numeric Y (when ytarget is not specified), some original distinct Y values are not sampled so there will be fewer intercepts in the model. bootcov linearly interpolates and extrapolates to fill in the missing intercepts so that the intercepts are aligned over bootstrap samples. Also see the Hmisc ordGroupBoot function.
Usage
bootcov(fit, cluster, B=200, fitter,
coef.reps=TRUE, loglik=FALSE,
pr=FALSE, group=NULL, stat=NULL,
seed=sample(10000, 1), ytarget=NULL, ...)
bootplot(obj, which=1 : ncol(Coef), X,
conf.int=c(.9,.95,.99),
what=c('density', 'qqnorm', 'box'),
fun=function(x) x, labels., ...)
confplot(obj, X, against,
method=c('simultaneous','pointwise'),
conf.int=0.95, fun=function(x)x,
add=FALSE, lty.conf=2, ...)
histdensity(y, xlab, nclass, width, mult.width=1, ...)Arguments
- fit
a fit object containing components
xandy. For fits fromcph, the"strata"attribute of thexcomponent is used to obtain the vector of stratum codes.- obj
an object created by
bootcovwithcoef.reps=TRUE.- X
a design matrix specified to
confplot. Seepredict.rmsorcontrast.rms. Forbootplot,Xis optional.- y
a vector to pass to
histdensity.NAs are ignored.- cluster
a variable indicating groupings.
clustermay be any type of vector (factor, character, integer). Unique values ofclusterindicate possibly correlated groupings of observations. Note the data used in the fit and stored infit$xandfit$ymay have had observations containing missing values deleted. It is assumed that if there were any NAs, annaresidfunction exists for the class offit. This function restores NAs so that the rows of the design matrix coincide withcluster.- B
number of bootstrap repetitions. Default is 200.
- fitter
the name of a function with arguments
(x,y)that will fit bootstrap samples. Default is taken from the class offitif it isols,lrm,cph,psm,Rq.- coef.reps
set to
TRUEif you want to store a matrix of all bootstrap regression coefficient estimates in the returned componentboot.Coef.- loglik
set to
TRUEto store -2 log likelihoods for each bootstrap model, evaluated against the originalxandydata. The default is to do this whencoef.repsis specified asTRUE. The use ofloglik=TRUEassumes that anoos.loglikmethod exists for the type of model being analyzed, to calculate out-of-sample -2 log likelihoods (seermsMisc). After theB-2 log likelihoods (stored in the element namedboot.loglikin the returned fit object), theB+1element is the -2 log likelihood for the original model fit.- pr
set to
TRUEto print the current sample number to monitor progress.- group
a grouping variable used to stratify the sample upon bootstrapping. This allows one to handle k-sample problems, i.e., each bootstrap sample will be forced to select the same number of observations from each level of group as the number appearing in the original dataset. You may specify both
groupandcluster.- stat
a single character string specifying the name of a
statselement produced by the fitting function to save over the bootstrap repetitions. The vector of saved statistics will be in theboot.statspart of the list returned bybootcov.- seed
random number seed for
set.seed, defaults to a random integer between 1 and 10000; user should specify a constant for reproducibility- ytarget
when using
orm, setytarget=NAto save only the intercept that corresponds to the median Y. Setytargetto a specific value (including a character value) to use a different target for the sole retained intercept.- which
one or more integers specifying which regression coefficients to plot for
bootplot- conf.int
a vector (for
bootplot, default isc(.9,.95,.99)) or scalar (forconfplot, default is.95) confidence level.- what
for
bootplot, specifies whether a density or a q-q plot is made, aggplot2is used to produce a box plot of all coefficients over the bootstrap reps- fun
for
bootplotorconfplotspecifies a function used to translate the quantities of interest before analysis. A common choice isfun=expto compute anti-logs, e.g., odds ratios.- labels.
a vector of labels for labeling the axes in plots produced by
bootplot. Default is row names ofXif there are any, or sequential integers.- ...
For
bootcov, extra arguments to pass to any of the fitting functions. Forbootplotthese are optional arguments passed tohistdensity. Also may be optional arguments passed toplotbyconfplotor optional arguments passed tohistfromhistdensity, such asxlimandbreaks. The argumentprobability=TRUEis always passed tohist.- against
For
confplot, specifyingagainstcauses a plot to be made (or added to). Theagainstvariable is associated with rows ofXand is used as the x-coordinates.- method
specifies whether
"pointwise"or"simultaneous"confidence regions are derived byconfplot. The default is simultaneous.- add
set to
TRUEto add to an existing plot, forconfplot- lty.conf
line type for plotting confidence bands in
confplot. Default is 2 for dotted lines.- xlab
label for x-axis for
histdensity. Default islabelattribute or argument name if there is nolabel.- nclass
passed to
histif present- width
passed to
densityif present- mult.width
multiplier by which to adjust the default
widthpassed todensity. Default is 1.
Value
a new fit object with class of the original object and with the element
orig.var added. orig.var is
the covariance matrix of the original fit. Also, the original var
component is replaced with the new bootstrap estimates. The component
boot.coef is also added. This contains the mean bootstrap estimates
of regression coefficients (with a log scale element added if
applicable). boot.Coef is added if coef.reps=TRUE.
boot.loglik is added if loglik=TRUE. If stat is
specified an additional vector boot.stats will be contained in
the returned object. B contains the number of successfully fitted
bootstrap resamples. A component
clusterInfo is added to contain elements name and n
holding the name of the cluster variable and the number of clusters.
bootplot returns a (possible matrix) of quantities of interest and
the requested quantiles of them. confplot returns three vectors:
fitted, lower, and upper.
Details
If the fit has a scale parameter (e.g., a fit from psm), the log
of the individual bootstrap scale estimates are added to the vector
of parameter estimates and and column and row for the log scale are
added to the new covariance matrix (the old covariance matrix also
has this row and column).
For Rq fits, the tau, method, and hs
arguments are taken from the original fit.
Author
Frank Harrell
Department of Biostatistics
Vanderbilt University
fh@fharrell.com
Bill Pikounis
Biometrics Research Department
Merck Research Laboratories
https://billpikounis.com/wpb/
References
Feng Z, McLerran D, Grizzle J (1996): A comparison of statistical methods for clustered data analysis with Gaussian error. Stat in Med 15:1793–1806.
Tibshirani R, Knight K (1996): Model search and inference by bootstrap
"bumping". Department of Statistics, University of Toronto. Technical
report available from
http://www-stat.stanford.edu/~tibs/.
Presented at the Joint Statistical Meetings,
Chicago, August 1996.
See also
ordGroupBoot,
robcov, sample, rms,
lm.fit, lrm.fit, orm.fit,
survival-internal,
predab.resample, rmsMisc,
Predict, gendata,
contrast.rms, Predict, setPb,
multiwayvcov::cluster.boot