gamV: Fit a GAM model and get a gamViz object

View source: R/gamV.R

bamVR Documentation

Fit a GAM model and get a gamViz object

Description

These are wrapper that fits a GAM model using mgcv::gam or mgcv::bam and converts it to a gamViz object using the getViz function. It is essentially a shortcut.

Usage

bamV(
  formula,
  family = gaussian(),
  data = list(),
  method = "fREML",
  aGam = list(),
  aViz = list()
)

gamV(
  formula,
  family = gaussian(),
  data = list(),
  method = "REML",
  aGam = list(),
  aViz = list()
)

Arguments

formula, family, data, method

same arguments as in mgcv::gam or mgcv::bam.

aGam

list of further arguments to be passed to mgcv::gam or mgcv::bam.

aViz

list of arguments to be passed to getViz.

Value

An object of class "gamViz" which can, for instance, be plotted using plot.gamViz.

Examples

##### gam example
# Simulate data
library(mgcViz)
set.seed(2) ## simulate some data...
dat <- gamSim(1,n=1000,dist="normal",scale=2)

# Fit GAM and get gamViz object
b <- gamV(y~s(x0)+s(x1, x2)+s(x3), data = dat, 
          aGam = list(scale = 2), aViz = list("nsim" = 20))

# This is equivalent to doing
# 1. Fit GAM
# b <- gam(y~s(x0)+s(x1, x2)+s(x3), data=dat, method="REML", scale = 2)
# 2. Convert to gamViz object
# b <- getViz(b, nsim = 20)

# Either way, we plot first and third effects by doing
print(plot(b, select = c(1, 3)), pages = 1)

##### bam example
# Simulate data
library(mgcViz)
set.seed(2) ## simulate some data...
dat <- gamSim(1,n=2000,dist="normal",scale=2)

# Fit using bam() and get gamViz object
b <- bamV(y~s(x0)+s(x1, x2)+s(x3), data = dat, 
          aGam = list(discrete = TRUE), aViz = list("nsim" = 0))
          
# Either way, we plot first and third effects by doing
print(plot(b, select = c(2)), pages = 1)

mgcViz documentation built on Oct. 6, 2023, 5:09 p.m.

Related to gamV in mgcViz...