Skip to content

Fix novel level value in step_lencode_glm() - #285

Open
taekop wants to merge 1 commit into
tidymodels:mainfrom
taekop:embed-243-lencode-new
Open

taekop wants to merge 1 commit into
tidymodels:mainfrom
taekop:embed-243-lencode-new

Conversation

@taekop

@taekop taekop commented Sep 29, 2026

Copy link
Copy Markdown

Closes #243.

step_lencode_glm() set the value used for novel/unseen levels to a trimmed mean of the per-level coefficients, which gives every level equal weight regardless of how many observations it has. For a factor with one dominant level and many small ones, this pushed the novel-level value far away from the outcome as a whole.

The value is now the coefficient of an intercept-only GLM fit to the whole outcome (weighted the same way as the per-level model), so it reflects the overall/global outcome rather than an unweighted average across levels.

step_lencode_bayes() and step_lencode_mixed() have the same issue (they also fall back to an unweighted average/trim of per-level effects for ..new) but are out of scope here.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

..new is calculated wrong in lencode steps

1 participant