comp_boot_mul_ind: Calculate a single replication of the multiplier bootstrap...

Description Usage Arguments Value Examples

View source: R/ols-boot-multiplier.R

Description

comp_boot_mul_ind calculates a single replication of the multiplier bootstrap for an OLS fitted dataset based on an lm fitted object in R. This is given by the following expression:

\frac{1}{n}∑_{i=1}^{n} e_{i}\widehat{J}^{-1}X_{i}(Y_{i}-X_{i}^{T} \widehat{β})

.

Usage

1
comp_boot_mul_ind(J_inv_X_res, e)

Arguments

J_inv_X_res

A d \times \d matrix given by the expression ∑_{i=1}^{n}\widehat{J}^{-1}X_{i}(Y_{i}-X_{i}^{T} \widehat{β}).

e

multiplier bootstrap weights. This is an n \times 1 vector of mean zero, variance 1 random variables.

n

Number of observations (rows) of the underlying dataset. In the given notation we assume our dataset has n observations and d features (including an intercept)

Value

A tibble of the bootstrap standard errors.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
## Not run: 
# Run an linear model (OLS) fit
set.seed(162632)
n <- 1e2
X <- stats::rnorm(n, 0, 1)
y <- 2 + X * 1 + stats::rnorm(n, 0, 1)
lm_fit <- stats::lm(y ~ X)

# Calculate the necessary required inputs for the bootstrap
J_inv <- summary.lm(lm_fit)$cov.unscaled
X <- qr.X(lm_fit$qr)
res <- residuals(lm_fit)
n <- length(res)
J_inv_X_res <-
  1:nrow(X) %>%
  purrr::map(~ t(J_inv %*% X[.x, ] * res[.x])) %>%
  do.call(rbind, .)

# Generate a single random vector of length n, containing
# mean 0, variance 1 random variables
e <- rnorm(n, 0, 1)

# Run a single replication of the multiplier bootstrap
mult_boot_single_rep <-
  comp_boot_mul_ind(
    n = n,
    J_inv_X_res = J_inv_X_res,
    e = e
  )
# Display the output
print(mult_boot)

## End(Not run)

shamindras/maar documentation built on Sept. 19, 2021, 10:21 p.m.