Learn R Programming

robmed (version 0.6.0)

boot_samples: Draw bootstrap samples

Description

Draw bootstrap samples to be used for (fast and robust) bootstrap tests for mediation analysis. Note that this function is intended for use in simulation studies, it is not expected to be called by the user.

Usage

boot_samples(n, R)

Arguments

n

an integer giving the number of observations in the original data set.

R

an integer giving the number of bootstrap samples to be generated.

Value

An object of class "boot_samples" with the following components:

indices

an integer matrix in which each column contains the indices of the corresponding bootstrap sample.

seed

the state of the random number generator before the bootstrap samples were drawn

See Also

test_mediation()

Examples

Run this code
# NOT RUN {
# control parameters
n <- 100
a <- b <- c <- 0.2

# generate data
set.seed(20150326)
x <- rnorm(n)
m <- a * x + rnorm(n)
y <- b * m + c * x + rnorm(n)
simulated_data <- data.frame(x, y, m)

# perform boostrap tests
indices <- boot_samples(n, R = 5000)
standard_boot <- test_mediation(simulated_data,
                                x = "x", y = "y", m = "m",
                                robust = FALSE,
                                indices = indices)
summary(standard_boot)
robust_boot <- test_mediation(simulated_data,
                              x = "x", y = "y", m = "m",
                              robust = TRUE,
                              indices = indices)
summary(robust_boot)
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab