## ------------------------------------------
## Small reproducible example (for speed reasons, we chose a too small number of bootstrap samples)
## ------------------------------------------
set.seed(1)
n <- 30
J <- 2
unit <- rep(1:n, each = J)
W_true <- rnorm(n)
W_obs <- rep(W_true, each = J) + rnorm(n * J, sd = 0.5)
Z1 <- rep(rnorm(n), each = J)
y <- rep(1 + 2 * W_true - 0.5 * Z1[seq(1, n * J, by = J)], each = J) +
rnorm(n * J)
sim_data <- data.frame(
unit = unit,
y = y,
W1 = W_obs,
Z1 = Z1
)
# For speed reasons, we use a very small number of bootstrap samples
fit <- eiv_mlr(
y ~ W(W1) + Z(Z1),
data = sim_data,
B = 10,
t_grid_length = 20
)
coef(fit)
summary(fit)
## ------------------------------------------
## Additional examples (not run during checks)
## ------------------------------------------
# \donttest{
## ------------------------------------------
## Example using included dataset
## ------------------------------------------
fit <- eiv_mlr(
bmi ~ W(energy + protein + fat) + Z(age_in_month),
data = dietary_white_women,
weight_method = "minimax",
B = 100,
t_grid_length = 200
)
summary(fit)
confint(fit)
## ------------------------------------------
## Simulated example with replication
## ------------------------------------------
set.seed(1)
n <- 200
J <- 2
unit <- rep(1:n, each = J)
W_true <- rnorm(n)
W_obs <- rep(W_true, each = J) + rnorm(n * J, sd = 0.5)
Z1 <- rep(rnorm(n), each = J)
y <- rep(1 + 2 * W_true - 0.5 * Z1[seq(1, n * J, by = J)], each = J) +
rnorm(n * J)
sim_data <- data.frame(
unit = unit,
y = y,
W1 = W_obs,
Z1 = Z1
)
fit_rep <- eiv_mlr(
y ~ W(W1) + Z(Z1),
data = sim_data,
B = 20
)
summary(fit_rep)
## ------------------------------------------
## Simulated example without replication
## ------------------------------------------
sim_norep <- sim_data[!duplicated(sim_data$unit), ]
fit_norep <- eiv_mlr(
y ~ W(W1) + Z(Z1),
data = sim_norep,
B = 20
)
summary(fit_norep)
# }
Run the code above in your browser using DataLab