lm.boot: Linear model bootstrap.

View source: R/simpleboot.R

lm.bootR Documentation

Linear model bootstrap.

Description

Bootstrapping of linear model fits (using lm). Bootstrapping can be done by either resampling rows of the original data frame or resampling residuals from the original model fit.

Usage

lm.boot(lm.object, R, rows = TRUE, new.xpts = NULL, ngrid = 100,
        weights = NULL)

Arguments

lm.object

A linear model fit, produced by lm.

R

The number of bootstrap replicates to use.

rows

Should we resample rows? Setting rows to FALSE indicates resampling of residuals.

new.xpts

Values at which you wish to make new predictions. If specified, fitted values from each bootstrap sample will be stored.

ngrid

If new.xpts is NULL and the regression is 2 dimensional, then predictions are made on an evenly spaced grid (containing ngrid points) spanning the range of the predictor values.

weights

Reseampling weights; a vector of length equal to the number of observations.

Details

Currently, "lm.simpleboot" objects have a simple print method (which shows the original fit), a summary method and a plot method.

Value

An object of class "lm.simpleboot" (which is a list) containing the elements:

method

Which method of bootstrapping was used (rows or residuals).

boot.list

A list containing values from each of the bootstrap samples. Currently, bootstrapped values are model coefficients, residual sum of squares, R-square, and fitted values for predictions.

orig.lm

The original model fit.

new.xpts

The locations where predictions were made.

weights

The resampling weights. If none were used, this component is NULL

Author(s)

Roger D. Peng

See Also

The plot.lm.simpleboot method.

Examples

data(airquality)
attach(airquality)
set.seed(30)
lmodel <- lm(Ozone ~ Wind)
lboot <- lm.boot(lmodel, R = 1000)
summary(lboot)

## With weighting
w <- runif(nrow(model.frame(lmodel)))
lbootw <- lm.boot(lmodel, R = 1000, weights = w)
summary(lbootw)

## Resample residuals
lboot2 <- lm.boot(lmodel, R = 1000, rows = FALSE)
summary(lboot2)

simpleboot documentation built on Sept. 11, 2024, 6:21 p.m.