|
1 | | -# Quick intro to Generalized Additive Mixed Models (GAMMs) |
| 1 | +# Introduction to Generalized Additive Mixed Models (GAMMs) |
2 | 2 |
|
3 | 3 | When observations are not independent, GAMs can be used to either incorporate: |
4 | 4 |
|
5 | 5 | - a correlation structure to model autocorrelated residuals, such as: |
6 | 6 | - the autoregressive (AR) model |
7 | 7 | - the moving average model (MA); or, |
8 | 8 | - a combination of both models (ARMA). |
9 | | -- random effects that model independence among observations from the |
10 | | - same site. |
| 9 | +- random effects that model independence among observations from the |
| 10 | + same site using GAMMs. |
11 | 11 |
|
12 | 12 | That is, in addition to changing the basis as with the `nottem` example, we can also add complexity to the model by incorporating an autocorrelation structure or mixed effects using the `gamm()` function in the `mgcv` package. Although we will not be using it here, the [`gamm4`](https://cran.r-project.org/web/packages/gamm4/gamm4.pdf) package can also be used to estimate GAMMs in R. |
13 | 13 |
|
@@ -63,6 +63,24 @@ after controlling for the values of the time series at all shorter lags. |
63 | 63 |
|
64 | 64 | The ACF and pACF plots are thus used to identify the time steps are needed before observations are no longer autocorrelated. |
65 | 65 |
|
| 66 | +## Generalized additive mixed effect models (GAMMs) in a nutshell |
| 67 | + |
| 68 | +Generalized additive mixed effect models (GAMMs) are a type of statistical model that combines the flexibility of generalized additive models (GAMs) with the ability to account for random effects in mixed-effect models. |
| 69 | + |
| 70 | +Like GAMs, GAMMs allow for non-linear relationships between predictors and the response variable by fitting smooth functions to each predictor. However, GAMMs also allow for the inclusion of random effects, which capture the variability of observations within groups or clusters. |
| 71 | + |
| 72 | +A generalized additive mixed effects model (GAMM) can be written as: |
| 73 | + |
| 74 | +$$Y_i = f_1(X_{1,i}) + f_2(X_{2,i}) + \ldots + f_p(X_{p,i}) + Z_i b + \epsilon_i$$ |
| 75 | + |
| 76 | +In this formula, $Y_i$ represents the response variable for the $i$th observation, and $X_{1,i}$ to $X_{p,i}$ represent the values of the $p$ predictor variables for that observation. The functions $f_1$ to $f_p$ represent the relationships between each predictor variable and the response variable. |
| 77 | + |
| 78 | +The term $Z_i b$ represents the random effects in the model. $Z_i$ is a matrix that specifies the random effects design for the $i$th observation, and $b$ is a vector of random effects coefficients. |
| 79 | + |
| 80 | +Finally, $\epsilon_i$ represents the error term for the $i$th observation. |
| 81 | + |
| 82 | +### Application |
| 83 | + |
66 | 84 | The ACF plot of our model residuals suggests a significant lag of 1, and perhaps |
67 | 85 | a lag of 2. Therefore, a low-order AR model is likely needed. |
68 | 86 |
|
@@ -162,7 +180,6 @@ plot_smooth(gamm_intercept, view="x0", rm.ranef = FALSE, |
162 | 180 | add = TRUE, col = 'turquoise') |
163 | 181 | ``` |
164 | 182 |
|
165 | | - |
166 | 183 | ### GAMM with a random slope |
167 | 184 |
|
168 | 185 | Next, we will run and plot a model with a random slope: |
|
0 commit comments