gammV: Fit a GAMM or GAMM4 model and get a gamViz object

View source: R/gammV.R

gamm4VR Documentation

Fit a GAMM or GAMM4 model and get a gamViz object

Description

These are wrappers that fit GAM models using mgcv::gamm or gamm4::gamm4 and convert them to a gamViz object using the getViz function. It is essentially a shortcut.

Usage

gamm4V(
  formula,
  random = NULL,
  family = gaussian(),
  data = list(),
  REML = TRUE,
  aGam = list(),
  aViz = list(),
  keepGAMObj = FALSE
)

gammV(
  formula,
  random = NULL,
  family = gaussian(),
  data = list(),
  method = "REML",
  aGam = list(),
  aViz = list(),
  keepGAMObj = FALSE
)

Arguments

formula, random, family, data

same arguments as in mgcv::gamm or gamm4::gamm4.

REML

same as in gamm4::gamm4

aGam

list of further arguments to be passed to mgcv::gamm or gamm4::gamm4.

aViz

list of arguments to be passed to getViz.

keepGAMObj

if TRUE a copy of the gamViz Object is kept under $gam to assure compatibility with mgcv::gamm and gamm4::gamm4. Defaults to FALSE.

method

same as in mgcv::gamm

Details

WARNING: Model comparisons (e.g. with anova) should only be done using the mixed model part as described in gamm4::gamm4. For mgcv::gamm please refer to the original help file.

Value

An object of class "gamViz" which can, for instance, be plotted using plot.gamViz. Also the object has the following additional elements:

  • lme mixed model as in mgcv::gamm

  • mer mixed model as in gamm4::gamm4

  • gam a copy of the gamViz Object if setting keepGAMObj = TRUE.

Examples

##### gam example
library(mgcViz)
# Simulate data
dat <- gamSim(1,n=400,scale=2) ## simulate 4 term additive truth
## Now add 20 level random effect `fac'...
dat$fac <- fac <- as.factor(sample(1:20,400,replace=TRUE))
dat$y <- dat$y + model.matrix(~fac-1) %*% rnorm(20) * 0.5

br <- gammV(y~s(x0)+x1+s(x2), data=dat,random=list(fac=~1))
summary(br)
plot(br)

summary(br$lme)

## Not run: 
## gamm4::gamm4 example
br4 <- gamm4V(y~s(x0)+x1+s(x2),data=dat,random=~(1|fac))
summary(br4)
plot(br4)

summary(br4$mer)

## End(Not run)


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

Related to gammV in mgcViz...