plotGAM: GAM plotting using ggplot2

Description Usage Arguments Value See Also Examples

View source: R/plotGAM.R

Description

GAM plotting using ggplot2

Usage

1
2
plotGAM(gamFit, smooth.cov, groupCovs = NULL, orderedAsFactor = T,
  rawOrFitted = F, plotCI = T)

Arguments

gamFit

fitted gam model as produced by mgcv::gam()

smooth.cov

(character) name of smooth term to be plotted

groupCovs

(character) name of group variable to plot by, if NULL (default) then there are no groups in plot

orderedAsFactor

if TRUE then the model is refitted with ordered variables as factors.

rawOrFitted

If FALSE (default) then only smooth terms are plotted; if rawOrFitted = "raw" then raw values are plotted against smooth; if rawOrFitted = "fitted" then fitted values are plotted against smooth

plotCI

if TRUE (default) upper and lower confidence intervals are added at 2 standard errors above and below the mean

Value

Returns a ggplot object that can be visualized using the print() function

See Also

Other Plotting: plotGAMM

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
data <- data.frame(x = rep(1:20, 2), group = rep(1:2, each = 20))
set.seed(1)
data$y <- (data$x^2)*data$group*3 + rnorm(40, sd = 200)
data$group <- ordered(data$group)

gam <- mgcv::gam(y ~ s(x) + group, data=data)

plot1 <- plotGAM(gamFit = gam, smooth.cov = "x", groupCovs = NULL,
                  rawOrFitted = "raw", plotCI=TRUE, orderedAsFactor = FALSE)
gam <- mgcv::gam(y ~ s(x) + group + s(x, by=group), data=data)
plot2 <- plotGAM(gamFit = gam, smooth.cov = "x", groupCovs = "group",
                             rawOrFitted = "raw", orderedAsFactor = FALSE)

neuroconductor/voxel documentation built on May 20, 2021, 9:39 p.m.