ga_model: Fit a generalised additive model ('gam')

View source: R/ga_model.R

ga_modelR Documentation

Fit a generalised additive model (gam)

Description

One of two functions for fitting generalised additive models (gam) with the mgcv package. It will use the gam() function in mgcv for ANOVA designs with up to two categorical fixed factors (with two or more levels; Fixed_Factor), and exactly one factor is a continuous variable (e.g. time), which is called Smooth_Factor.

  1. ga_model

  2. ga_anova

A smooth function is fitted with factor-wise smooth basis function (⁠by = ⁠). A default value for number of nodes (the argument k in gam) may work, but a specific number can be provided using the Nodes argument. The model is fit using the REML method. When two categorical fixed factors are provided, an interaction term is included for main effects and smooth basis functions.

Usage

ga_model(
  data,
  Y_value,
  Fixed_Factor,
  Smooth_Factor,
  Random_Factor = NULL,
  Nodes = "NULL",
  ...
)

Arguments

data

a data frame where categorical independent variables are converted to factors using as.factor() first. The function will throw errors without this.

Y_value

name of column containing quantitative (dependent) variable, provided within "quotes".

Fixed_Factor

name(s) of categorical fixed factors (independent variables) provided as a vector if more than one or within "quotes". Convert to factors first with as.factor.

Smooth_Factor

the continuous variable to fit smoothly with a basis function, provided within "quotes" (only 1 Smooth_Factor allowed).

Random_Factor

name(s) of random factors to be provided in "quotes" (only 1 Random_Factor allowed). Convert to factor with as.factor first.

Nodes

number of nodes (the parameter k in gam).

...

any additional variables to pass on to gam or anova

Details

If a Random_Factor is also provided, it is fitted using bs = "re" smooth.

Value

This function gives a generalised additive model object of class "gam", "lm" and "glm".

Examples

#fit a model with zooplankton data
z1 <- ga_model(data = data_zooplankton,
Y_value = "log(density_adj)",
Fixed_Factor = "taxon",
Smooth_Factor = "day")


grafify documentation built on May 29, 2024, 3:49 a.m.

Related to ga_model in grafify...