How to extract coefficients from a model in R

· 1 min read · Updated March 15, 2026 · beginner
r statistics regression models

Extracting coefficients from fitted models is a common task in R.

Using coef

The primary function is coef:

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

# Access by name
coef(model)["cyl"]
#       cyl 
# -1.587297

Using broom

The broom package provides tidy data frames:

library(broom)
model <- lm(mpg ~ cyl + disp + hp, data = mtcars)
tidy(model)
# # A tibble: 4 × 5
#   term        estimate std.error statistic  p.value
#   <chr>          <dbl>     <dbl>     <dbl>    <dbl>
# 1 (Intercept)  34.0       2.65     12.8   4.4e-12
# 2 cyl          -1.48      0.71     -2.09  4.8e-2 
# ...

GLM and Confidence Intervals

For logistic regression, coefficients are on the log-odds scale. Use exp() to convert to odds ratios:

model_glm <- glm(am ~ mpg + cyl, data = mtcars, family = binomial)
coef(model_glm)
exp(coef(model_glm))

# Confidence intervals
confint(model)
#                  2.5 %    97.5 %
# (Intercept)  24.945    43.377
# cyl          -2.363    -0.592

See Also