Created
November 5, 2025 19:29
-
-
Save topepo/0d6f7b24284117d4e09015ddbfa33049 to your computer and use it in GitHub Desktop.
Avoid estimation for a model in tidymodels
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(tidymodels) | |
| actual_fit <- glm(mpg ~ ., data = mtcars) | |
| not_fit <- glm( | |
| mpg ~ ., | |
| data = mtcars, | |
| start = coef(actual_fit), | |
| control = glm.control(maxit = 1, trace = TRUE) | |
| ) | |
| # Can also trick tidymodels if we can initialize a model known to | |
| no_parsnip_fit <- | |
| linear_reg() |> | |
| set_engine( | |
| "glm", | |
| start = coef(actual_fit), | |
| control = glm.control(maxit = 1) | |
| ) |> | |
| fit(mpg ~ ., data = mtcars) | |
| waldo::compare( | |
| coef(actual_fit), | |
| no_parsnip_fit |> extract_fit_engine() |> coef() | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This doesn't seem to work if using other (non-estimated) coefficients:
Created on 2025-11-06 with reprex v2.1.1