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 glm engine for linear_reg() #624

Merged
merged 8 commits into from
Dec 15, 2021
Merged

Add glm engine for linear_reg() #624

merged 8 commits into from
Dec 15, 2021

Conversation

juliasilge
Copy link
Member

Closes #623

library(parsnip)

linear_reg() %>% 
  set_engine("glm") %>%
  translate()
#> Linear Regression Model Specification (regression)
#> 
#> Computational engine: glm 
#> 
#> Model fit template:
#> stats::glm(formula = missing_arg(), data = missing_arg(), weights = missing_arg(), 
#>     family = stats::gaussian)

Created on 2021-12-13 by the reprex package (v2.0.1)

@juliasilge
Copy link
Member Author

We can pass in expressions to the family engine argument:

library(parsnip)

spec1 <- 
  linear_reg() %>% 
  set_engine("glm", family = statmod::tweedie) 

spec1 %>% translate()
#> Linear Regression Model Specification (regression)
#> 
#> Engine-Specific Arguments:
#>   family = statmod::tweedie
#> 
#> Computational engine: glm 
#> 
#> Model fit template:
#> stats::glm(formula = missing_arg(), data = missing_arg(), weights = missing_arg(), 
#>     family = statmod::tweedie)

spec1 %>% fit(breaks ~ ., data = warpbreaks)
#> parsnip model object
#> 
#> 
#> Call:  stats::glm(formula = breaks ~ ., family = ~statmod::tweedie, 
#>     data = data)
#> 
#> Coefficients:
#> (Intercept)        woolB     tensionM     tensionH  
#>      39.278       -5.778      -10.000      -14.722  
#> 
#> Degrees of Freedom: 53 Total (i.e. Null);  50 Residual
#> Null Deviance:       9233 
#> Residual Deviance: 6748  AIC: NA

spec2 <- 
  linear_reg() %>% 
  set_engine("glm", family = stats::poisson(link = "sqrt")) 

spec2 %>% translate()
#> Linear Regression Model Specification (regression)
#> 
#> Engine-Specific Arguments:
#>   family = stats::poisson(link = "sqrt")
#> 
#> Computational engine: glm 
#> 
#> Model fit template:
#> stats::glm(formula = missing_arg(), data = missing_arg(), weights = missing_arg(), 
#>     family = stats::poisson(link = "sqrt"))

spec2 %>% fit(breaks ~ ., data = warpbreaks)
#> parsnip model object
#> 
#> 
#> Call:  stats::glm(formula = breaks ~ ., family = ~stats::poisson(link = "sqrt"), 
#>     data = data)
#> 
#> Coefficients:
#> (Intercept)        woolB     tensionM     tensionH  
#>      6.2620      -0.5059      -0.8545      -1.3644  
#> 
#> Degrees of Freedom: 53 Total (i.e. Null);  50 Residual
#> Null Deviance:       297.4 
#> Residual Deviance: 212.7     AIC: 495.3

Created on 2021-12-13 by the reprex package (v2.0.1)

@juliasilge
Copy link
Member Author

I added a tiny translate() example about the engine argument, and did the same for logistic_reg() to close #619.

@topepo topepo merged commit adcfd18 into main Dec 15, 2021
@topepo topepo deleted the linear-reg-glm branch December 15, 2021 19:31
@github-actions
Copy link

This pull request has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue.

@github-actions github-actions bot locked and limited conversation to collaborators Dec 30, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

glm engine for linear reg
3 participants