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

ga_anova(
  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

Value

ANOVA table of class "anova" and "data.frame".

Details

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.

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

Examples

#with zooplankton data
ga_anova(data = data_zooplankton,
Y_value = "log(density_adj)",
Fixed_Factor = "taxon",
Smooth_Factor = "day")
#> 
#> Family: gaussian 
#> Link function: identity 
#> 
#> Formula:
#> log(density_adj) ~ taxon + s(day, by = taxon)
#> 
#> Parametric Terms:
#>       df     F  p-value
#> taxon  3 23.97 4.97e-15
#> 
#> Approximate significance of smooth terms:
#>                                 edf Ref.df      F  p-value
#> s(day):taxonCalanoid copepods 7.828  8.643 28.267  < 2e-16
#> s(day):taxonD. thomasi        6.989  8.057 42.695  < 2e-16
#> s(day):taxonK. cochlearis     5.349  6.470  5.739 5.76e-06
#> s(day):taxonL. siciloides     3.076  3.825  5.322 0.000466