Learn R Programming

speccurvieR (version 1.0.0)

se_boot: Estimates bootstrapped standard errors for regression models

Description

Takes in a data frame, regression formula, and bootstrapping parameters and estimates bootstrapped standard errors for models with and without fixed effects. The model is refit on `n_samples` resamples of `sample_size` observations drawn with replacement, and the standard deviation of the resampled coefficients is rescaled by `sqrt(sample_size / nrow(data))` to estimate the standard error of the full-sample estimator (an m-out-of-n bootstrap; when `sample_size` equals `nrow(data)` this is the ordinary nonparametric bootstrap).

Usage

se_boot(
  data,
  formula,
  n_x,
  n_samples,
  sample_size,
  weights = NULL,
  fam_obj = NULL
)

Value

A named list containing bootstrapped standard errors for each coefficient.

Arguments

data

A data frame containing the variables provided in `formula`.

formula

A string containing a regression formula, with or without fixed effects.

n_x

An integer representing the number of independent variables in the regression.

n_samples

An integer indicating how many bootstrap resamples to draw, i.e. how many times the model is refit.

sample_size

An integer indicating how many observations are drawn (with replacement) in each bootstrap resample.

weights

Optional string with the column name in `data` that contains weights.

fam_obj

Optional `family` object (as returned by e.g. `binomial()`) used to fit each resampled model with `glm()`. Defaults to `NULL`, fitting linear models with `lm()` (or `feols()` when the formula contains fixed effects). Fixed effects are not supported together with a `family` object.

Examples

Run this code

se_boot(data = bottles, formula = "Salnty ~ T_degC + ChlorA + O2Sat",
        n_x = 3, n_samples = 4, sample_size = 300)

# \donttest{
se_boot(data = data.frame(x1 = rnorm(50000, mean=4, sd=10),
                          x2 = rnorm(50000, sd=50),
                          ID = rep(1:100, 500),
                          area = rep(1:50, 1000),
                          y = rnorm(50000)),
        formula = "y ~ x1 + x2 | ID",
        n_x = 2, n_samples = 10, sample_size = 1000)
# }

Run the code above in your browser using DataLab