Get Started

Extracting coefficients

We often want to know what values a model estimates as coefficients. Although the summary() function provides the model outputs, we might also want to directly access model outputs.

The fixed-effects estimates can be called directly using the fixef() function. The random-effects estimates can be called directly using the ranef() function. We can also extract confidence intervals for the fixed-effects using the function confint().

The broom.mixed package also contains tidy methods for extracting model results from lmer() models, namely the tidy() function. However, these results are more complex and less tidy than many tidy outputs due to the complexity of mixed-effect models.

A lmer model has been fit for you and saved as out.

This is a part of the course

“Hierarchical and Mixed Effects Models in R”

View Course

Exercise instructions

  • Extract the fixed-effect coefficients using fixef() with the saved model out.
  • Extract the random-effect coefficients using the ranef() with the saved model out.
  • Estimate the 95% confidence intervals using the confint() function with the saved model out.
  • Use the tidy() with out and conf.int = TRUE to repeat your previous three code calls with one tidy command.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Extract the fixed-effect coefficients
___

# Extract the random-effect coefficients
___

# Estimate the confidence intervals 
___

# Use the tidy function
___
Edit and Run Code

This exercise is part of the course

Hierarchical and Mixed Effects Models in R

AdvancedSkill Level
4.6+
19 reviews

In this course you will learn to fit hierarchical models with random effects.

This chapter providers an introduction to linear mixed-effects models. It covers different types of random-effects, describes how to understand the results for linear mixed-effects models, and goes over different methods for statistical inference with mixed-effects models using crime data from Maryland.

Exercise 1: Linear mixed effect model- Birth rates dataExercise 2: Building a lmer model with random effectsExercise 3: Including a fixed effectExercise 4: Random-effect slopesExercise 5: Uncorrelated random-effect slopeExercise 6: Fixed- and random-effect predictorExercise 7: Understanding and reporting the outputs of a lmerExercise 8: Comparing print and summary outputExercise 9: Extracting coefficients
Exercise 10: Displaying the results from a lmer modelExercise 11: Statistical inference with Maryland crime dataExercise 12: Visualizing Maryland crime dataExercise 13: Rescaling slopesExercise 14: Null hypothesis testingExercise 15: Controversies around P-valuesExercise 16: Model comparison with ANOVA

What is DataCamp?

Learn the data skills you need online at your own pace—from non-coding essentials to data science and machine learning.

Start Learning for Free