Description Usage Arguments Value Examples
View source: R/ols-boot-multiplier.R
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{β})
.
1 | comp_boot_mul_ind(J_inv_X_res, e)
|
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) |
A tibble of the bootstrap standard errors.
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.