tef_rlm_boot: Bootstrapped robust linear model

View source: R/tef_rlm_boot.R

tef_rlm_bootR Documentation

Bootstrapped robust linear model

Description

Run a rlm model nBoot times, then include the bootstrapped parameter estimates (and summary of quantiles thereof) in the rlm output. Also includes out-of-sample delta-R-squared. If parameter distributions are *anywhere near* decision thresholds, using nBoot>2000 (or even much higher) is recommended.

Usage

tef_rlm_boot(formIn, datIn, nBoot = 500, useLM = F)

Arguments

formIn

Model formula, as with lm() or rlm()

datIn

Data, as with lm() or rlm()

nBoot

Number of resamples [with replacement]

useLM

Override the standard rlm() implementation to use basic lm() instead

Details

Wraps rlm() or lm() and then bootstraps [fits models to datasets sampled with replacement] that model nBoot times. Then fits models to nBoot random 80 percent of data and tests the delta R-squared of each numeric or logical parameter when predicting the out-of-sample 20 percent.

Value

An augmented rlm or lm object that includes several new items: $bootSummary, $boots (all bootstrapped parameters), $bootQs (quantiles of bootstrapped parameters), $dRsq (all out-of-sample proportional reduction of error), $dRsqQs (quantiles of out-of-sample proportional reduction of error), and $results (strings, formatted for RMarkdown, including whole-sample slope, bootstrapped CI, and median out-of-sample dRSq).

For an explanation specific objects see comment(model$boots), comment(model$dRsq), or comment(model$bootSummary).

Examples

dat <- data.frame(x=rnorm(50))
dat$y <- dat$x + rnorm(50)
dat$z <- dat$y - rnorm(50)
dat$z[2] <- NA # the function is robust to NAs
m <- tef_rlm_boot(y~x*z,dat)
m$bootSummary # to get a summary of the fit[s]
comment(m$bootSummary) # to get an explanation of the summary data frame


akcochrane/TEfits documentation built on June 12, 2025, 11:10 a.m.