plot.gamtree: Plotting method for GAM trees

Description Usage Arguments Warning Examples

View source: R/gamtree.R

Description

Takes a fitted GAM tree and plots the smooth functions fitted in each of the terminal nodes of the tree.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
## S3 method for class 'gamtree'
plot(
  x,
  which = "both",
  which_terms = "both",
  residuals = TRUE,
  dim = NULL,
  ylim = "firstnode",
  treeplot_ctrl = list(),
  gamplot_ctrl = list(),
  ...
)

Arguments

x

object of class gamtree.

which

character. The default ("both") plots the tree structure, followed by the model fitted in the terminal nodes. Alternatively, "tree" will plot the tree structure, and "terms" will plot the smooth (and parametric) terms from the terminal-node-specific and global model. Note that the fitted curves in the tree do not convey a conditional function of the predictor on the $x$-axis (as plotted when "terms" is specified). They are a function of the predictor on the $x$-axis, as well as all other predictors in the model and could thus be referred to as 'marginal' fitted curves.

which_terms

character; "local", "global" or "both". Only used when argument which equal "global" or "both". Specifies whether the local and/or global (smooth) terms should be plotted.

residuals

Only used when which_terms = local. Should residuals be plotted in the node-specific plots?

dim

numeric vector of length two. Specifies how many rows and columns of plots should be fit on a single page. NULL (the default) has the routine leave all settings as they are. Using par(mfrow = c( , )) before plotting then provides control over the plot dimensions (and number of pages).

ylim

"firstplot" (default), NULL, or a numeric vector of length 2. Only used for plotting the terminal-node models (not the tree). Specifies how the limits of the y-axes of the terminal node plots should be chosen. The default ("firstnode") uses the observations in the first node to determine the limits of the y-axes for all plots. Alternatively, NULL will determine the limits of the y-axes separately for each plot. Alternatively, a numeric vector of length two may be specified, specifying the lower and upper limits of the y-axes.

treeplot_ctrl

list of (named) arguments to be passed to plot.party.

gamplot_ctrl

list of (named) arguments to be passed to plot.gam. Note that not all arguments of plot.gam are supported. .

...

further arguments, currently not used.

Warning

The plotted terms by default also represent confidence bands. These should be taken with a big grain of salt, because they do NOT account for the searching of the tree structure; they assume the tree structure was known in advance. They should be interpreted as overly optimistic and with caution.

Examples

1
2
3
4
5
6
7
8
gt1 <- gamtree(Pn ~ s(PAR, k = 5L) | Species, data = eco, 
               cluster = eco$specimen) 
plot(gt1, which = "tree") # default is which = 'both'
plot(gt1, which = "terms", gamplot_ctrl = list(shade = TRUE)) 
gt2 <- gamtree(Pn ~ s(PAR, k = 5L) | s(cluster_id, bs = "re") + noise | Species, 
              data = eco, cluster = eco$specimen) 
plot(gt2, which = "tree") # default is which = 'both'
plot(gt2, which = "terms", gamplot_ctrl = list(shade = TRUE))

marjoleinF/gamtree documentation built on Sept. 17, 2021, 5:46 a.m.