lm.bal: Do a balanced bootstrap on a linear model.

View source: R/bootstrap_functions.R

lm.balR Documentation

Do a balanced bootstrap on a linear model.

Description

This function calculates a linear regression of y versus x. The data are bootstrapped to generate confidence intervals around the slope and intercept. Optionally, the r2 value may also be calculated. The bootstrapped prediction interval around the fit may also be calculated.

Usage

lm.bal(
  x,
  y,
  xsd = 0,
  ysd = 0,
  n = 10000,
  ci.width = 95,
  method = c("ols", "ma", "rma"),
  pred.band = T,
  pred.limits = c(NA, NA),
  pred.steps = 25
)

Arguments

x

x-axis values, a numeric vector

y

y-axis values, a numeric vector

xsd

(optional) Either a single value or a vector with length equal to x. Used to generate normal distributions around each x value with SD equal to xsd.

ysd

(optional) Either a single value or a vector with length equal to y. Used to generate normal distributions around each y value with SD equal to ysd.

n

Number of bootstrap replicates to perform.

ci.width

Width of the confidence interval to use for hypothesis testing, a single numeric value between 1 and 100

method

Regression method. Either 'ols" for Ordinary Least Squares, 'ma' for Major Axis, or 'rma' for Reduced Major Axis.

pred.band

Compute the prediction interval? This is computationally intensive, especially for large datasets.

pred.limits

Lower and upper limits of the prediction interval. By default, these are the limits of the observed x-axis data.

pred.steps

# of steps to calculate the prediction interval at. Increase for higher resolution at cost of computation time.


JackAHutchings/jahrfun documentation built on June 8, 2025, 3:09 a.m.