Do you use Gam or mgcv for random effects?

Do you use Gam or mgcv for random effects?

If all you need are simple random effects like this and you are familiar with GAMs and mgcv then it might be simpler all round to just use the random effect spline basis with gam () rather than having to deal with the weird output of the hybrid that is a GAMM model fitted via gamm ().

How are log likelihood and penalty related in mgcv?

The log-likelihood of the model is a measure of the fit (or lack there of), while the penalty helps us avoid fitting overly complex smooths. In the sorts of models that can be fitted in mgcv, the penalty is a function of the model coefficients, β, and a penalty matrix 1, which we write as S. The penalty then is β T S β.

How are random effects added to a GAM?

Two methods of adding random effects to a GAM give very different results. Why is this and which one should be used? A particular section of the mgcv documentation gives multiple methods of incorporating random effects into a generalized additive model.

What’s the difference between GAM and fitted for M1?

This is what fitted.gam will be doing for m1 because it represents the random effect as a spline “fixed” effect. In the case of the gamm model, fitted.gam is returning fitted values for the “fixed” effect part of the model, which would explain the difference.

How to add random effects to generalized additive model?

A particular section of the mgcv documentation gives multiple methods of incorporating random effects into a generalized additive model. Two methods are 1) to add a smooth term in the class labels using bs=”re” in gam; 2) Use the function gamm, which includes similar facilities to lme, combined with the existing functions for gam.

What kind of smooths are used in mgcv?

The sorts of smooths we fit in mgcv are (typically) penalized smooths; we choose to use some number of basis functions k, which sets an upper limit on the complexity — wiggliness — of the smooth, and then we estimate parameters for the model by maximizing a penalized log-likelihood.