2
$\begingroup$

I have built two gams in mgcv. wt3 runs fine but wt4 struggles to run (I have terminated it every time due to taking too long to run).

I suspect that wt4 does not run because it does not make sense to include a factor-smooth interaction (s(age.x, scale_id, bs = 'fs', k = 4)) that creates a separate smooth for each individual (scale_id) through time (age.x), and then additionally include a random intercept for individuals (s(scale_id, bs = "re")). However, I would like some confirmation that my thought process is correct (or not).

So my question is: does it make sense/is it possible to include a factor-smooth interaction that creates separate smooths for each individual through time, and then also include a random intercept or random slope for individuals?

wt3 <- gam(weight_t ~ 
             tagged +
             sex + 
             s(age.x, scale_id, bs = 'fs', k = 4),
           data = long, 
           method = "REML")    
 

wt4 <- gam(weight_t ~ 
             tagged +
             sex + 
             s(age.x, scale_id, bs = 'fs', k = 4) + 
             s(scale_id, bs = "re"), 
           data = long, 
           method = "REML")
```
$\endgroup$

1 Answer 1

1
$\begingroup$

You can do this, and it shouldn't matter too much as the fs basis is fully penalized; if the intercepts in the fs basis aren't needed then they should get penalized to ~0.

If you have a large number of levels in the scale_id factor, then it could well be that you are just hitting the main drawback of using the penalty-matrix version of a random effect; namely that it is not as efficient as dedicated GLMM software that can take account of the sparse nature of the random effects.

You should turn on tracing via the gam.control() function passed to the control argument of gam() to monitor what is going on during fitting. If there is a problem you might be able to diagnose it from the trace output, but usually when I've had issues with a model converging, I've hit the preset iteration limits and received a convergence warning from mgcv, which makes me think you're just hitting a computational bottleneck by adding in another set of random effect terms.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.