knitr::opts_chunk$set(collapse = TRUE, comment = "#>")

Fit a model with lm():

model <- lm(mpg ~ 1 + cyl, mtcars)
coefs <- coef(model)

# prediction for 8 cylinders
coefs["(Intercept)"] + 8 * coefs["cyl"]

predict(model, data.frame(cyl = 8L))


tjmahr/solarizeddocx documentation built on May 4, 2022, 3:35 p.m.