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 support for mgcv::gam() #135

Merged
merged 6 commits into from
Sep 1, 2022
Merged

Add support for mgcv::gam() #135

merged 6 commits into from
Sep 1, 2022

Conversation

juliasilge
Copy link
Member

@juliasilge juliasilge commented Aug 17, 2022

Closes #131

library(vetiver)
library(mgcv)
#> Loading required package: nlme
#> This is mgcv 1.8-40. For overview type 'help("mgcv-package")'.
training_sim <- gamSim(1, n = 50, scale = 2)
#> Gu & Wahba 4 term additive model

model_fit <- mgcv::gam(y ~ s(x1, bs = 'ps', sp = 0.6) + 
                           s(x2, bs = 'ps', sp = 0.6) + x3, 
                       data = training_sim, method="REML")
summary(model_fit)
#> 
#> Family: gaussian 
#> Link function: identity 
#> 
#> Formula:
#> y ~ s(x1, bs = "ps", sp = 0.6) + s(x2, bs = "ps", sp = 0.6) + 
#>     x3
#> 
#> Parametric coefficients:
#>             Estimate Std. Error t value Pr(>|t|)    
#> (Intercept)   8.4262     0.7017  12.009  3.9e-14 ***
#> x3           -0.9844     1.2596  -0.782     0.44    
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> 
#> Approximate significance of smooth terms:
#>         edf Ref.df     F  p-value    
#> s(x1) 6.056  6.813 6.377 8.48e-05 ***
#> s(x2) 6.028  6.802 7.155 2.58e-05 ***
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> 
#> R-sq.(adj) =  0.689   Deviance explained = 77.2%
#> -REML = 117.71  Scale est. = 4.4707    n = 50

v <- vetiver_model(model_fit, "simulated-gam")
v
#> 
#> ── simulated-gam ─ <butchered_gam> model for deployment 
#> A generalized additive model (gaussian family, identity link) using 3 features

library(plumber)
pr() %>% vetiver_api(v)
#> # Plumber router with 2 endpoints, 4 filters, and 1 sub-router.
#> # Use `pr_run()` on this object to start the API.
#> ├──[queryString]
#> ├──[body]
#> ├──[cookieParser]
#> ├──[sharedSecret]
#> ├──/logo
#> │  │ # Plumber static router serving from directory: /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/vetiver
#> ├──/ping (GET)
#> └──/predict (POST)

Created on 2022-08-17 with reprex v2.0.2

We need to fix up the butcher method for mgcv::gam(), though.

Merge branch 'main' into add-mgcv

# Conflicts:
#	NAMESPACE
#	NEWS.md
#	man/handler_startup.Rd
#	man/vetiver_create_description.Rd
#	man/vetiver_create_meta.Rd
#	man/vetiver_create_ptype.Rd
@juliasilge juliasilge merged commit 962261e into main Sep 1, 2022
@juliasilge juliasilge deleted the add-mgcv branch September 1, 2022 16:56
juliasilge added a commit that referenced this pull request Sep 26, 2022
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.

Support for mgcv::gam() models
1 participant