rguides

How to Extract Coefficients from a Model in R

To extract coefficients from a fitted model in R, use coef(). It returns a named numeric vector of the fitted parameters and works on nearly every model type — lm, glm, lmer, nls, and most third-party model objects.

model <- lm(mpg ~ cyl + disp, data = mtcars)
coef(model)
# (Intercept)         cyl        disp 
#  34.660939   -1.587297   -0.020684

You can pull out a single coefficient by name: coef(model)["cyl"]. For confidence intervals, call confint(model). To get standard errors and p-values alongside estimates, summary(model)$coefficients works, but the output is an unstructured matrix.

A cleaner alternative is broom::tidy(model), which returns a tibble with columns for term, estimate, std.error, statistic, and p.value:

library(broom)
model <- lm(mpg ~ cyl + disp, data = mtcars)
tidy(model)
# # A tibble: 3 × 5
#   term        estimate std.error statistic  p.value
#   <chr>          <dbl>     <dbl>     <dbl>    <dbl>
# 1 (Intercept)  34.7       2.59      13.4   5.3e-13
# 2 cyl          -1.59      0.708     -2.24  3.4e-2 
# 3 disp         -0.0207    0.0103    -2.01  5.5e-2

The tidy data frame is easier to pipe into ggplot for coefficient plots, filter by significance, or export as a CSV. broom::glance(model) gives model-level statistics like R² and AIC; broom::augment(model) adds fitted values and residuals back to the original data for diagnostics. For most reporting tasks, broom::tidy() combined with dplyr::filter(p.value < 0.05) keeps only the statistically significant predictors in your output, which is cleaner than printing the full summary table every time.

See also