# NOT RUN {
library(lme4)
library(sjmisc)
# compute standard error for vector
se(rnorm(n = 100, mean = 3))
# compute standard error for each variable in a data frame
data(efc)
se(efc[, 1:3])
# compute standard error for merMod-coefficients
library(lme4)
fit <- lmer(Reaction ~ Days + (Days | Subject), sleepstudy)
se(fit)
# compute odds-ratio adjusted standard errors, based on delta method
# with first-order Taylor approximation.
data(efc)
efc$services <- sjmisc::dicho(efc$tot_sc_e, dich.by = 0)
fit <- glm(
services ~ neg_c_7 + c161sex + e42dep,
data = efc,
family = binomial(link = "logit")
)
se(fit)
# compute odds-ratio adjusted standard errors for generalized
# linear mixed model, also based on delta method
# create binary response
sleepstudy$Reaction.dicho <- dicho(sleepstudy$Reaction, dich.by = "median")
fit <- glmer(
Reaction.dicho ~ Days + (Days | Subject),
data = sleepstudy,
family = binomial("logit")
)
se(fit)
# compute standard error for proportions
efc$e42dep <- to_label(efc$e42dep)
se(table(efc$e42dep))
# including weights
efc$weights <- rnorm(nrow(efc), 1, .25)
se(xtabs(efc$weights ~ efc$e42dep))
# compute standard error from regression coefficient and p-value
se(list(estimate = .3, p.value = .002))
# }
# NOT RUN {
# compute standard error of ICC for the linear mixed model
icc(fit)
se(icc(fit))
# the standard error for the ICC can be computed manually in this way,
# taking the fitted model example from above
library(dplyr)
library(purrr)
dummy <- sleepstudy %>%
# generate 100 bootstrap replicates of dataset
bootstrap(100) %>%
# run mixed effects regression on each bootstrap replicate
# and compute ICC for each "bootstrapped" regression
mutate(
models = map(strap, ~lmer(Reaction ~ Days + (Days | Subject), data = .x)),
icc = map_dbl(models, ~icc(.x))
)
# now compute SE and p-values for the bootstrapped ICC, values
# may differ from above example due to random seed
boot_se(dummy, icc)
boot_p(dummy, icc)
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab