Skip to content

Commit 82a560b

Browse files
Merge pull request #28 from QCBSRworkshops/gamms-book-en
Adding a brief explanation to GAMMs to the English version of the book
2 parents e021c47 + 60abb1a commit 82a560b

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

book-en/08-GAMMs.Rmd

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
# Quick intro to Generalized Additive Mixed Models (GAMMs)
1+
# Introduction to Generalized Additive Mixed Models (GAMMs)
22

33
When observations are not independent, GAMs can be used to either incorporate:
44

55
- a correlation structure to model autocorrelated residuals, such as:
66
- the autoregressive (AR) model
77
- the moving average model (MA); or,
88
- 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.
1111

1212
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.
1313

@@ -63,6 +63,24 @@ after controlling for the values of the time series at all shorter lags.
6363

6464
The ACF and pACF plots are thus used to identify the time steps are needed before observations are no longer autocorrelated.
6565

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+
6684
The ACF plot of our model residuals suggests a significant lag of 1, and perhaps
6785
a lag of 2. Therefore, a low-order AR model is likely needed.
6886

@@ -162,7 +180,6 @@ plot_smooth(gamm_intercept, view="x0", rm.ranef = FALSE,
162180
add = TRUE, col = 'turquoise')
163181
```
164182

165-
166183
### GAMM with a random slope
167184

168185
Next, we will run and plot a model with a random slope:

0 commit comments

Comments
 (0)