1
$\begingroup$

I have been working with lmer in lme4, and wanted to construct a density curve of the slopes produced by my model (rather than just confidence intervals). The model output of lmer produces a slope, and something referred to as 'std. error'. If I calculate the standard deviation from the standard error, the standard deviation is much higher than I would have expected.

I investigated this further by using confint to select 1000 random confidence intervals, and comparing the outputted slopes to an rnorm using both what I calculated the standard deviation would be, and the standard error given by lmer. As you can see, the standard error is much closer to the slopes from random confidence intervals than it is to the standard deviation. Am I right in thinking that what is referred to as standard error in the lmer output is, at least for the purposes of the density distribution of slopes, standard deviation?

Some example code:

library(lme4)

set.seed(123)

#generate random dataset
df <- data.frame(weight=(rnorm(10000, 1, 0.3)),
                 height=(rnorm(10000, 5, 6)),
                 species = rep(c("mudkip", "torchic", "treecko"), length.out = 10000)) 
# model

mod <- lmer(data=df, weight ~ height + (1|species), REML=F)

slope <- coef(summary(mod))[ , "Estimate"][2]
se <- coef(summary(mod))[ , "Std. Error"][2]

sd <- se * sqrt(10000)

# Randomly extract slopes for varying confidence intervals

slope_num <- 1
ci_slope <- c()
for(i in runif(1000)){
  ci <- confint(mod,method="Wald", level=i)
  lwr <- colnames(ci)[1]
  upr <- colnames(ci)[2]
  ci_slope_lwr <- ci["height", lwr]
  ci_slope_upr <- ci["height", upr]
  slope_num <- slope_num + 1
  ci_slope <- c(ci_slope, ci_slope_lwr, ci_slope_upr)
}

# Generate rnorms using Std. Error and calculated standard deviation

rnorm_se <- rnorm(1000, slope, se)
rnorm_sd <- rnorm(1000, slope, sd)

# Comparative plots

plot(density(rnorm_se), lwd=2)
lines(density(ci_slope), col="blue")
lines(density(rnorm_sd), col="red") # I can't construct a readable graph that can fit sd with anything else

Plot of rnorm using 'Std. Error', rnorm using standard deviation, and density of slopes from random confidence intervals

$\endgroup$

1 Answer 1

3
$\begingroup$

The "standard error" of a parameter is the standard deviation of the parameter's sampling distribution (e.g. wiki). In other words, theoretically, if you were to sample new data and rerun the analysis again and again, you would end up with a distribution of slope parameters, and standard error is an estimate of the standard deviation of that distribution.

Where I think you're confused is that when the parameter in question is the sample mean, there is a simple relationship between the sample standard deviation and the standard error of the mean (that is, the standard deviation of the sampling distribution of the estimated mean): $\text{SEM} = \frac{SD}{\sqrt{n}}$. This relationship doesn't apply to parameter estimates from regression models.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.