Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add check_convergence method for parsnip _glm model #605

Merged
merged 4 commits into from
Sep 10, 2023
Merged

Add check_convergence method for parsnip _glm model #605

merged 4 commits into from
Sep 10, 2023

Conversation

egouldo
Copy link
Contributor

@egouldo egouldo commented Sep 4, 2023

Created method for models fitted using the parsnip:: package with the glm engine. Here's a reproducible example to demonstrate it works:

# Example from https://parsnip.tidymodels.org/articles/Examples.html#linear_reg-models
library(tidymodels)
library(performance)
#> 
#> Attaching package: 'performance'
#> The following objects are masked from 'package:yardstick':
#> 
#>     mae, rmse
tidymodels_prefer()
data(Chicago)

n <- nrow(Chicago)
Chicago <- Chicago %>% select(ridership, Clark_Lake, Quincy_Wells)

Chicago_train <- Chicago[1:(n - 7), ]
Chicago_test <- Chicago[(n - 6):n, ]

linreg_reg_spec <- 
  linear_reg() %>% 
  set_engine("glm")
linreg_reg_spec
#> Linear Regression Model Specification (regression)
#> 
#> Computational engine: glm

set.seed(1)
linreg_reg_fit <- linreg_reg_spec %>% fit(ridership ~ ., data = Chicago_train)
linreg_reg_fit
#> parsnip model object
#> 
#> 
#> Call:  stats::glm(formula = ridership ~ ., family = stats::gaussian, 
#>     data = data)
#> 
#> Coefficients:
#>  (Intercept)    Clark_Lake  Quincy_Wells  
#>       1.6624        0.7738        0.2557  
#> 
#> Degrees of Freedom: 5690 Total (i.e. Null);  5688 Residual
#> Null Deviance:       245000 
#> Residual Deviance: 53530     AIC: 28910

# Define model checking function

check_convergence._glm <- function(x, ...){
  isTRUE(x$fit$converged)
}

# Apply model checking function

linreg_reg_fit %>% 
  check_convergence._glm()
#> [1] TRUE

Created on 2023-09-04 with reprex v2.0.2

@egouldo egouldo changed the title Add method for parsnip _glm model Add check_convergence method for parsnip _glm model Sep 4, 2023
@strengejacke
Copy link
Member

Thanks, looks good!

@strengejacke strengejacke merged commit eb8d4a1 into easystats:main Sep 10, 2023
17 of 25 checks passed
@egouldo egouldo deleted the patch-1 branch September 14, 2023 02:53
egouldo added a commit to egouldo/ManyAnalysts that referenced this pull request Jul 29, 2024
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.

2 participants