Plotting GAM interactions

Nonlinear Modeling with Generalized Additive Models (GAMs) in R

Noam Ross

Senior Research Scientist, EcoHealth Alliance

Using mgcv's plot() command with interactions.

plot(mod_2d)

Nonlinear Modeling with Generalized Additive Models (GAMs) in R

Using mgcv's plot() with interactions

plot(mod_2d, scheme = 1)

Nonlinear Modeling with Generalized Additive Models (GAMs) in R

Using mgcv's plot() with interactions

plot(mod_2d, scheme = 2)

Nonlinear Modeling with Generalized Additive Models (GAMs) in R

Customizing interaction plots with vis.gam()

vis.gam(x,
        view = NULL,
        cond = list(),
        n.grid = 30,
        too.far = 0,
        col = NA,
        color = "heat",
        contour.col = NULL,
        se = -1,
        type = "link",
        plot.type = "persp",
        zlim = NULL,
        nCol = 50,
        ...)
Nonlinear Modeling with Generalized Additive Models (GAMs) in R

Customizing interaction plots with vis.gam()

vis.gam(x = mod,                # GAM object
        view = c("x1", "x2"),   # variables
        plot.type = "persp")    # kind of plot 

Nonlinear Modeling with Generalized Additive Models (GAMs) in R

Customizing interaction plots with vis.gam() (2)

vis.gam(x = mod,                # GAM object
        view = c("x1", "x2"),   # variables
        plot.type = "contour")  # kind of plot 

Nonlinear Modeling with Generalized Additive Models (GAMs) in R

Customizing interaction plots with vis.gam()

vis.gam(mod, view = c("x1", "x2"), plot.type = "contour", too.far = 0.1)
vis.gam(mod, view = c("x1", "x2"), plot.type = "contour", too.far = 0.05)

Nonlinear Modeling with Generalized Additive Models (GAMs) in R

Options for perspective plots

vis.gam(x = mod, view = c("x1", "x2"), 
        plot.type = "persp", se = 2)                  

Nonlinear Modeling with Generalized Additive Models (GAMs) in R

Options for perspective plots

vis.gam(g, view = c("x1", "x2"), plot.type = "persp", 
                                 theta = 220)
vis.gam(g, view = c("x1", "x2"), plot.type = "persp", 
                                 phi = 55)
vis.gam(g, view = c("x1", "x2"), plot.type = "persp", 
                                 r = 0.1)

Nonlinear Modeling with Generalized Additive Models (GAMs) in R

Options for contour plots

vis.gam(g, view = c("x1", "x2"), plot.type = "contour",
                                 color = "gray")
vis.gam(g, view = c("x1", "x2"), plot.type = "contour",
                                 contour.col = "blue")
vis.gam(g, view = c("x1", "x2"), plot.type = "contour",
                                 nlevels = 20)

Nonlinear Modeling with Generalized Additive Models (GAMs) in R

Now let's make some plots!

Nonlinear Modeling with Generalized Additive Models (GAMs) in R

Preparing Video For Download...