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.
ga_model
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.
ga_model(
data,
Y_value,
Fixed_Factor,
Smooth_Factor,
Random_Factor = NULL,
Nodes = "NULL",
...
)a data frame where categorical independent variables are converted to factors using as.factor() first. The function will throw errors without this.
name of column containing quantitative (dependent) variable, provided within "quotes".
name(s) of categorical fixed factors (independent variables) provided within quotes (e.g., "A") or as a vector if more than one (e.g., c("A", "B"). Convert to factors first with as.factor.
the continuous variable to fit smoothly with a basis function, provided within "quotes" (only 1 Smooth_Factor allowed).
name(s) of random factors to be provided in "quotes" (only 1 Random_Factor allowed). Convert to factor with as.factor first.
number of nodes (the parameter k in gam).
any additional variables to pass on to gam or anova
This function gives a generalised additive model object of class "gam", "lm" and "glm".
If a Random_Factor is also provided, it is fitted using bs = "re" smooth.
#fit a model with zooplankton data
z1 <- ga_model(data = data_zooplankton,
Y_value = "log(density_adj)",
Fixed_Factor = "taxon",
Smooth_Factor = "day")