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

Why does plotGAM only allow smooth terms #4

Open
jh-206 opened this issue Nov 10, 2018 · 0 comments
Open

Why does plotGAM only allow smooth terms #4

jh-206 opened this issue Nov 10, 2018 · 0 comments

Comments

@jh-206
Copy link

jh-206 commented Nov 10, 2018

if (base::grepl(pattern = interaction.smooth, old.covariates, fixed=T)) {

Hi there. The plotGAM function stops execution if the covariate is not a smooth term. It doesn't allow tensor product terms (mgcv::te) or normal terms. But when I comment out those lines of code that check for s(, the function works perfectly well. It seems like you would want the plotting function to support a broader class of functions that can be used in GAMs, since you might have a GAM model with both smooth terms and tensor product terms and want to visualize the covariates together.

The plotGAM function includes a ggtitle that would have to be updated, and I plan work on that and submit a pull request, but I wanted to open the issue first to make sure.

Minimal example:

library(mgcv); library(voxel)
set.seed(123)
x <- seq(0, 3*pi, by = .1)
y <- 5 + cos(x) + rnorm(length(x), sd = .5)

fit_s <- mgcv::gam(y ~ s(x))
fit_te <- mgcv::gam(y ~ te(x))
fit_ols <- mgcv::gam(y ~ x)

voxel::plotGAM(fit_s, smooth.cov = 'x', plotCI = F) # runs
voxel::plotGAM(fit_te, smooth.cov = 'x', plotCI = F) # Error
voxel::plotGAM(fit_ols, smooth.cov = 'x', plotCI = F) # Error

If you comment out the code I highlighted at the top, the bottom 2 plot calls would work fine (albeit with a misleading title)

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

No branches or pull requests

1 participant