stan-dev / stan-dev/rstanarm

Why does stan_lm ignore a factor level in a model with no intercept?

Open
#557 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
R
Stars
401
Forks
136
PR merge metrics
No merged PRs in 30d

Description

Originally pointed out on the forum in https://discourse.mc-stan.org/t/why-does-stan-lm-ignore-a-factor-level-in-a-model-with-no-intercept/24877.

@bgoodri stan_lm still drops a factor level even if the intercept is omitted, e.g. stan_lm(mpg ~ 0 + as.factor(cyl), data = mtcars, prior = R2(0.5, "mean")). This contradicts the behavior of lm and stan_glm. Is this intentional or a bug?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the stan_lm example with mtcars and compare its factor-level handling against lm and stan_glm when the intercept is omitted. Trace the stan_lm model-matrix construction and confirm that the completed behavior retains all factor levels in the no-intercept case.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.