Generalized Additive Mixed Model (GAMM)


·         The basic

·         Random effect

·         Within group correlation structure

·         Smoothing terms

·         Smoothing plot

·         Distribution and link function

·         Sample input window

·         Sample output and Explanation

·         More sample input (with random slope and smoothing term)



The Basic


GAMM (generalized additive mixed model) is the extension of GAM (generalized additive model), which not only includes smooth terms but also includes random effects in the classical sense of linear regression.


A key feature of the GAMM is that additive nonparametric functions are used to model covariate effects and random effects are used to model correlation between observations.  GAMM encompasses various study designs, such as clustered, hierarchical and spatial designs.


For example, for longitudinal study which follows up a cohort of newborn baby for height and weight development, the random effects can be a random intercept and/or random slope, and the age-weight relationship could be modeled with nonparametric spline smoothing.


For details about GAMM, refer to this paper “Inference in generalized additive mixed models by using smoothing splines” (Author: Xinhong Lin)

For details about Linear Mixed Model, refer to “Linear Mixed Models” (author: John Fox)


Random effect:


The random effect could be random intercept and/or random slope.  In the above example, random intercept allows each baby starting point of weight is different (random for each baby), random slope allows each baby weight by age slope (weight increase per age) is random for each baby.


Within group correlation structure


Available standard correlation structure:


autoregressive process of order 1.


autoregressive moving average process, with arbitrary orders for the autoregressive and moving average components.


continuous autoregressive process (AR(1) process for a continuous time covariate).


compound symmetry structure corresponding to a constant correlation.


exponential spatial correlation.


Gaussian spatial correlation.


linear spatial correlation.


Rational quadratics spatial correlation.


spherical spatial correlation.


general correlation matrix, with no additional structure.

Users may define their own correlation structure by click the label, and then specifying relative parameter in popup dialogue. A sample input dialogue is as:



Smoothing terms:


The smoothing terms are the variables that would be modeled with nonparametric spline smoothing.  If the variable is assigned as random effect, it could not be assigned as smoothing terms.  Smoothing terms could not be random effect too.


By default, cubic regression spline (br=’cr’) is applied as the penalized smoothing basis.


Different smoothing curve could be allowed for different strata of the population.  For example, you want to allow different smoothing curve for male and female while estimates for all other variables are same for male and female, set the “Smoothing conditioned on factors” to SEX.


“Smoothing conditioned on factors” allows is different from stratified analysis. Stratified analysis not only gives different smoother of AGE for WEIGHT but also gives different regression coefficient for other variables.

Smoothing plot

Scatter plots can be computed showing the smoothed predictor variable values plotted against the partial residuals, i.e., the residuals after removing the effect of all other predictor variables.  Below is a sample smoothing plot:

Distributions and Link Functions

Like GLM, Generalized Additive Mixed Model allows you to choose from a wide variety of distributions for the dependent variable, and link functions for the effects of the predictor variables on the dependent variable

Following is a table of commonly used link functions and their inverses.



Link Function

Mean Function





















\mu=\frac{\exp{(\mathbf{X}\boldsymbol{\beta})}}{1 + \exp{(\mathbf{X}\boldsymbol{\beta})}} = \frac{1}{1 + \exp{(-\mathbf{X}\boldsymbol{\beta})}}\,\!



If the dependent is a continuous variable, normal distribution and identity link function are usually the default; if it is a dichotomous variable, binomial distribution and logit link function are usually the default. 



Below is the sample input window



In above example, random intercept was assigned, agemos (age in months) was smoothed conditioned on SEX (separate smoothing curve for male and female) .


Below is the sample output and explanation of the above model:


Generalized Mixed Addititive Model



(1)     First, output of the model formula and parametric coefficients (for fixed and linear terms) and its p values


 Summary of GAM


Family: gaussian

Link function: identity



WEIGHT ~ s(AGEMOS, bs = "cr", by = factor(SEX)) + factor(PARITY2) +



Parametric coefficients:

                  Estimate Std. Error t value Pr(>|t|)   

(Intercept)       5.941171   0.072936  81.458   <2e-16 ***

factor(PARITY2)1  0.008531   0.044905   0.190    0.849   

factor(PARITY2)2 -0.020789   0.054526  -0.381    0.703   

INF_RACE2         0.051658   0.042804   1.207    0.228   

SEX              -0.386571   0.040039  -9.655   <2e-16 ***


Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1


(2)     Next, output of smoothing terms.  In this example, 2 smoothing terms, one for male (SEX=1) and one for female (SEX=2).  Estimate degree of freedom (EDF) for male is 4.905, for female 4.243.  Both p value is <2e-16.


Approximate significance of smooth terms:

                         edf Ref.df    F p-value   

s(AGEMOS):factor(SEX)1 4.905  4.905 5435  <2e-16 ***

s(AGEMOS):factor(SEX)2 4.243  4.243 4720  <2e-16 ***


Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1


R-sq.(adj) =  0.872  Scale est. = 0.14801   n = 2832


(3)     Next, output of linear mixed effect (LME).  In this example random intercept for male and female and its correlation matrix.


 Summary of LME

Linear mixed-effects model fit by maximum likelihood

 Data: strip.offset(mf)

       AIC      BIC    logLik

  4074.657 4146.042 -2025.329


Random effects:

 Formula: ~Xr.1 - 1 | g.1

 Structure: pdIdnot

            Xr.11     Xr.12     Xr.13     Xr.14     Xr.15     Xr.16     Xr.17

StdDev: 0.3369206 0.3369206 0.3369206 0.3369206 0.3369206 0.3369206 0.3369206


StdDev: 0.3369206


 Formula: ~Xr.2 - 1 | g.2 %in% g.1

 Structure: pdIdnot

            Xr.21     Xr.22     Xr.23     Xr.24     Xr.25     Xr.26     Xr.27

StdDev: 0.2266326 0.2266326 0.2266326 0.2266326 0.2266326 0.2266326 0.2266326


StdDev: 0.2266326


 Formula: ~1 | ID %in% g.2 %in% g.1

        (Intercept)  Residual

StdDev:   0.4902025 0.3847172


Correlation Structure: Compound symmetry

 Formula: ~1 | g.1/g.2/ID

 Parameter estimate(s):




(4)     Next, output of fixed effect.  (the prefix “X” represent fixed, “Xs()” represents the fixed smoothing effect)


Fixed effects: y ~ X - 1

                               Value  Std.Error   DF    t-value p-value

X(Intercept)                5.941171 0.07296164 2096   81.42870  0.0000

Xfactor(PARITY2)1           0.008531 0.04492125  729    0.18992  0.8494

Xfactor(PARITY2)2          -0.020789 0.05454485  729   -0.38113  0.7032

XINF_RACE2                  0.051658 0.04281895  729    1.20642  0.2280

XSEX                       -0.386571 0.04005326  729   -9.65141  0.0000

Xs(AGEMOS):factor(SEX)1Fx1 -5.710157 0.04450825 2096 -128.29434  0.0000

Xs(AGEMOS):factor(SEX)2Fx1 -5.063991 0.04227907 2096 -119.77537  0.0000


                           X(Int) X(PARITY2)1 X(PARITY2)2 XINF_R XSEX 

Xfactor(PARITY2)1          -0.283                                     

Xfactor(PARITY2)2          -0.274  0.432                              

XINF_RACE2                 -0.404  0.016       0.073                  

XSEX                       -0.794 -0.056      -0.025      -0.012      

Xs(AGEMOS):factor(SEX)1Fx1 -0.026 -0.004      -0.004       0.002  0.025

Xs(AGEMOS):factor(SEX)2Fx1  0.010  0.003      -0.002       0.008 -0.024







Xs(AGEMOS):factor(SEX)2Fx1  0.000         


Standardized Within-Group Residuals:

         Min           Q1          Med           Q3          Max

-4.413512686 -0.507894256 -0.006303053  0.503583189  4.208595069


Number of Observations: 2832

Number of Groups:

                 g.1         g.2 %in% g.1 ID %in% g.2 %in% g.1

                   1                    1                  734



Besides the model output, Empower will also output following plots:


(1)   Smoothing plot for male and female.

(2)   The difference of smoothes compare male versus female.



(3)   Residual versus fitted plot



More sample input window


Below is sample input window showing a random slope and a smoothing term in the model