Learn R Programming

sjstats (version 0.7.1)

se: Standard Error for variables or coefficients

Description

Compute standard error for a variable, for all variables of a data frame, for joint random and fixed effects coefficients of mixed models, or for intraclass correlation coefficients (ICC).

Usage

se(x, nsim = 100)

Arguments

x
(Numeric) vector, a data frame, a merMod-object as returned by the lmer-method, an ICC object (as obtained by the icc-function) or a list with estimate and p-value. For the latter case, the list must contain elements named estimate and p.value (see 'Examples' and 'Details').
nsim
Numeric, the number of simulations for calculating the standard error for intraclass correlation coefficients, as obtained by the icc-function.

Value

The standard error of x, or for each variable if x is a data frame, or for the coefficients of a mixed model (see coef.merMod).

Details

Unlike se.coef, which returns the standard error for fixed and random effects separately, this function computes the standard errors for joint (sums of) random and fixed effects coefficients. Hence, se() returns the appropriate standard errors for coef.merMod. The standard error for the icc is based on bootstrapping, thus, the nsim-argument is required. See 'Examples'. se() also returns the standard error of an estimate (regression coefficient) and p-value, assuming a normal distribution to compute the z-score from the p-value (formula in short: b / qnorm(p / 2)). See 'Examples'.

Examples

Run this code
se(rnorm(n = 100, mean = 3))

data(efc)
se(efc[, 1:3])

library(lme4)
fit <- lmer(Reaction ~ Days + (Days | Subject), sleepstudy)
se(fit)

# 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)
# dummy <- sleepstudy %>%
#   # generate 100 bootstrap replicates of dataset
#   bootstrap(100) %>%
#   # run mixed effects regression on each bootstrap replicate
#   mutate(models = lapply(.$strap, function(x) {
#     lmer(Reaction ~ Days + (Days | Subject), data = x)
#   })) %>%
#   # compute ICC for each "bootstrapped" regression
#   mutate(icc = unlist(lapply(.$models, icc)))
# # 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)## End(Not run)


Run the code above in your browser using DataLab