1
votes

I used inverse link functions,

ilink <- family(gam_model)$linkinv

for create time series interaction graph, and it works wonderful.

I replace my model to gamm model, for consider autocorrelation in my model. Is it possible to use inverse link function on gamm model? I tried

ilink <- family(gamm_model)$linkinv
ilink <- family(gamm_model$gam)$linkinv
ilink <- family(gamm_model$lme)$linkinv

But for all the options it show the errors:

Error in UseMethod("family") : no applicable method for 'family' applied to an object of class "c('gamm', 'list')"

Error in UseMethod("family") : no applicable method for 'family' applied to an object of class "gam"

Error in UseMethod("family") : no applicable method for 'family' applied to an object of class "lme"

The second option is surprising because it works on the origin gam model, calss "gam"

Thank you Dvora

1

1 Answers

0
votes

This is one of those unfortunate side effects of mgcv::gamm() being a bit of a kludge.

The $gam component does actually contain a $family component it's just that the $gam object is only of class "gam" whereas a mgcv::gam() model object also inherits from class "glm" and there is a family.glm method for that. I believe this is due to the $gam object not being a fully compliant "gam" object and hence not a full "glm" object, hence it not inheriting from "glm",. It could also just be an oversight; for a long time the object returned by mgcv::gamm() was simply of class "list"!

The easiest way to proceed would be to write your own family method for objects of class "gamm" (so you don't have to remember which component to extract from) and for class "gam":

family.gamm <- function(object, ...) {
    family(object$gam)
}

family.gam <- function(object, ...) {
    object$family
}

Given that the definition of family.glm matches exactly that of the .gam method above, having this hang around in your workspace isn't going to interfere with the rest of mgcv.

library("mgcv")
set.seed(1)
dat <- gamSim(1, n = 400, dist = "normal", scale = 2, verbose = FALSE)
m1 <- gam(y ~ s(x0) + s(x1) + s(x2) + s(x3), data = dat, method = "REML")
m2 <- gamm(y ~ s(x0) + s(x1) + s(x2) + s(x3), data = dat, method = "REML")

family(m1)
family(m2)

Producing

> family(m1)

Family: gaussian 
Link function: identity 

> family(m2)

Family: gaussian 
Link function: identity