I'm trying to use hierarchical general additive models in mgcv using the Gaussian location-scale model family. However, this family of functions throws a cryptic error when trying to fit.
Followed the guidance on HGAMs from a recent paper (https://peerj.com/articles/6876/) along with the guidance from the notes in the lmvar package write-up (https://cran.r-project.org/web/packages/lmvar/vignettes/Intro.html).
library(mgcv); library(datasets)
# Using the CO2 dataset for illustration
data <- datasets::CO2
# Changing the 'Plant' factor from ordered to unordered
data$Plant <- factor(data$Plant, ordered = FALSE)
# This model fits with no errors
CO2_modG_1 <- gam(log(uptake) ~ s(log(conc), k = 5, bs = 'tp') + s(Plant, k = 12, bs = 're'), data = data, method = 'REML', family = 'gaussian')
# This model fails with error
CO2_modG_2 <- gam(log(uptake) ~ s(log(conc), k = 5, bs = 'tp') + s(Plant, k = 12, bs = 're'), data = data, method = 'REML', family = gaulss())
This returns the error message:
Error in while (sqrt(mean(dlb/(dlb + lami * dS * rm)) * mean(dlb)/mean(dlb + :
missing value where TRUE/FALSE needed