Skip to content

Why does plotGAM only allow smooth terms #4

@jh-206

Description

@jh-206

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions