boot_lm: Bootstrapping for linear models

View source: R/boot_lm.R

boot_lmR Documentation

Bootstrapping for linear models

Description

Bootstraping for linear models

Usage

boot_lm(
  object,
  f = NULL,
  R = 999,
  psim = 2,
  resid.type = c("resample", "normal", "wild"),
  data = NULL,
  verbose = TRUE,
  ...
)

Arguments

object

object of class lm

f

function to be applied (and bootstrapped), default coef

R

number of bootstrap samples, default 999

psim

simulation level for simulate_lm

resid.type

either “resample”, “normal” or “wild”.

data

optional data argument (useful/needed when data are not in an available environment).

verbose

logical (default TRUE) whether to print message if model does not converge. (rare for linear models).

...

additional arguments to be passed to function boot

Details

The residuals can either be generated by resampling with replacement (default), from a normal distribution (parameteric) or by changing their signs (wild). This last one is called “wild bootstrap”.

Note

at the moment, when the argument data is used, it is not possible to check that it matches the original data used to fit the model. It will also override the fetching of data.

Examples


require(car)
data(barley, package = "nlraa")
## Fit a linear model (quadratic)
fit.lm <- lm(yield ~ NF + I(NF^2), data = barley)

## Bootstrap coefficients by default
fit.lm.bt <- boot_lm(fit.lm)
## Compute confidence intervals
confint(fit.lm.bt, type = "perc")
## Visualize
hist(fit.lm.bt, 1, ci = "perc", main = "Intercept")
hist(fit.lm.bt, 2, ci = "perc", main = "NF term")
hist(fit.lm.bt, 3, ci = "perc", main = "I(NF^2) term")



nlraa documentation built on May 29, 2024, 2:01 a.m.