How do you fit a model with lm() or glm() in R, and how do the formula syntax and summary()/coef()/predict() work?

Quick Overview

Asks how to fit linear and generalized linear models in R with lm() and glm(), and how formulas, summary(), coef() and predict() work. Tests formula operators, factor coding, model families and links, and predictions on the link versus the response scale.

How do you fit a model with lm() or glm() in R, and how do the formula syntax and summary()/coef()/predict() work?

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: medium

Interview Round: Other

How do you fit a model with `lm()` or `glm()` in R, and how do the formula syntax and `summary()`/`coef()`/`predict()` work? ```hint Read a formula as columns For each formula operator, ask which columns end up in the model matrix that R actually fits. ``` ```hint Check the prediction scale For a logistic model, ask what scale the numbers returned by `predict()` are on by default. ``` ### What a Strong Answer Covers - How a formula specifies the response and predictors, including the intercept, interactions, `I()` and factors - When to use `lm()` and when `glm()`, and what the `family` argument sets - What `summary()`, `coef()` and `predict()` return for each kind of model - The difference between the link scale and the response scale for `glm` predictions - Common pitfalls with new data, factor levels and missing values ### Follow-up Questions - How would you get a 95% prediction interval for a new car from the `lm` fit, and how does it differ from a confidence interval? - How do you interpret the `wt` coefficient in the logistic model, and how would you turn it into an odds ratio? - How would you model counts that are overdispersed relative to a Poisson distribution?

Overview: Asks how to fit linear and generalized linear models in R with lm() and glm(), and how formulas, summary(), coef() and predict() work. Tests formula operators, factor coding, model families and links, and predictions on the link versus the response scale.

General logo
General
Nov 25, 2026
mediumData ScientistOtherData Manipulation (SQL/Python)
0
0

How do you fit a model with lm() or glm() in R, and how do the formula syntax and summary()/coef()/predict() work?

What a Strong Answer Covers Guidance

  • How a formula specifies the response and predictors, including the intercept, interactions, I() and factors
  • When to use lm() and when glm() , and what the family argument sets
  • What summary() , coef() and predict() return for each kind of model
  • The difference between the link scale and the response scale for glm predictions
  • Common pitfalls with new data, factor levels and missing values

Follow-up Questions Guidance

  • How would you get a 95% prediction interval for a new car from the lm fit, and how does it differ from a confidence interval?
  • How do you interpret the wt coefficient in the logistic model, and how would you turn it into an odds ratio?
  • How would you model counts that are overdispersed relative to a Poisson distribution?