Skip to content

Commit

Permalink
few tweaks to fix typos; add a missing reference
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinsimpson committed Nov 21, 2024
1 parent e31b283 commit b590153
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 8 deletions.
6 changes: 3 additions & 3 deletions paper.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ The teaching of GAMs can benefit from visualisation of the spline basis function

# State of the field

Several R packages provide similar functionality to that of *gratia*. Notably, the *mgcViz* package [@Fasiolo2020-nz] provides sophisticated capabilities for plotting estimated smooths for models fitted by *mgcv* and *qgam* [@], and model diagnostics plots. A particular feature of *mgcViz* is that it was designed to be scalable, easily handling models fitted to data with millions of observations, a use case not currently well handled by *gratia*. *tidymv* [@tidymv-2023] and its successor, *tidygam* [@tidygam-2023], provide plots of estimated smooths and model predictions respectively, as well as differences of smooths, but the focus is on univariate smooths, in contrast to *gratia*'s ability to plot multivariate and specialist smooths (e.g. soap film smooths). Like *gratia*, the *itsadug* package [@itsadug-2022] is motivated to make working with estimated GAMs and related models easier. *itsadug* uses base graphics for plotting, but in place of partial effects plots, produces plots of adjusted predictions, and while useful for a broad range of models, is especially focused on GAMs fitted to longitudinal data with random effects.
Several R packages provide similar functionality to that of *gratia*. Notably, the *mgcViz* package [@Fasiolo2020-nz] provides sophisticated capabilities for plotting estimated smooths for models fitted by *mgcv* and *qgam* [@Fasiolo2020-pr], and model diagnostics plots. A particular feature of *mgcViz* is that it was designed to be scalable, easily handling models fitted to data with millions of observations, a use case not currently well handled by *gratia*. *tidymv* [@tidymv-2023] and its successor, *tidygam* [@tidygam-2023], provide plots of estimated smooths and model predictions respectively, as well as differences of smooths, but the focus is on univariate smooths, in contrast to *gratia*'s ability to plot multivariate and specialist smooths (e.g. soap film smooths). Like *gratia*, the *itsadug* package [@itsadug-2022] is motivated to make working with estimated GAMs and related models easier. *itsadug* uses base graphics for plotting, but in place of partial effects plots, produces plots of adjusted predictions, and while useful for a broad range of models, is especially focused on GAMs fitted to longitudinal data with random effects.

Areas where *gratia* stands out from these other packages are i) the consistent functionality for range of posterior simulations (*mgcViz* has some support for simulating new response values) as illustrated below, ii) support for computing derivatives of smooths, partial derivatives, and derivatives on the response scale (i.e. conditional derivatives), iii) tools for learning or teaching how GAMs work, iv) the range of utility functions that make working with GAMs easier, and v) the simple and consistent *tidy* interface to all functionality.
Areas where *gratia* stands out from these other packages are i) the consistent functionality for a range of posterior simulations (*mgcViz* has some support for simulating new response values) as illustrated below, ii) support for computing derivatives of smooths, partial derivatives, and derivatives on the response scale (i.e. conditional derivatives), iii) tools for learning or teaching how GAMs work, iv) the range of utility functions that make working with GAMs easier, and v) the simple and consistent *tidy* interface to all functionality.

# Example usage

Expand Down Expand Up @@ -188,7 +188,7 @@ appraise(m2)
crs <- "+proj=ortho +lat_0=20 +lon_0=-40"
draw(m2, crs = crs, default_crs = 4326, dist = 0.05, rug = FALSE)
```
The plots produced by `draw()` from a fitted model are known as *partial effect plots* (Figure \ref{fig:m2-draw}), which show the component contributions, on the link scale, of each model term to the linear predictor. The y axis on these plots is typically centred around 0 due to most smooths having a sum-to-zero identifiability constraint applied to them. This constraint is what allows the model to include multiple smooths and remain identifiable. These plots allow you to read off the contributions of each smooth to the fitted response (on the link scale); they show link-scale *predictions* of the response for each smooth, conditional upon all other terms in the model, including any parametric effects and the intercept, having zero contribution. In the parlance of the *marginaleffects* package [@Arel-BundockGreiferHeiss:2024], these plots show *adjusted predictions*, just where the adjustment includes setting the contribution of *all* other model terms to the predicted value to zero. For *partial derivatives* (what *marginaleffects* would call a *marginal effect* or slope), *gratia* provides the `derivatives()`.
The plots produced by `draw()` from a fitted model are known as *partial effect plots* (Figure \ref{fig:m2-draw}), which show the component contributions, on the link scale, of each model term to the linear predictor. The y axis on these plots is typically centred around 0 due to most smooths having a sum-to-zero identifiability constraint applied to them. This constraint is what allows the model to include multiple smooths and remain identifiable. These plots allow you to read off the contributions of each smooth to the fitted response (on the link scale); they show link-scale *predictions* of the response for each smooth, conditional upon all other terms in the model, including any parametric effects and the intercept, having zero contribution. In the parlance of the *marginaleffects* package [@Arel-BundockGreiferHeiss:2024], these plots show *adjusted predictions*, just where the adjustment includes setting the contribution of *all* other model terms to the predicted value to zero. For *partial derivatives* (what *marginaleffects* would call a *marginal effect* or slope), *gratia* provides `derivatives()`.

Here, we see a specialised plot drawn for spline-on-the-sphere smooths $f(\mathtt{lat}_i,\mathtt{lon}_i)$ (Figure \ref{fig:m2-draw}, left-hand column), which uses `ggplot2::coord_sf()` and functionality from the *sf* package [@Pebesma2018-ws; @Pebesma2023-fe] to visualise the smooth via an orthographic projection.

Expand Down
14 changes: 13 additions & 1 deletion paper.bib
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ @ARTICLE{Miller2019-nf
author = "Miller, David L",
journal = "arXiv [stat.ME]",
month = feb,
year = 2019,
year = 2021,
archivePrefix = "arXiv",
primaryClass = "stat.ME",
eprint = "1902.01330"
Expand Down Expand Up @@ -399,3 +399,15 @@ @ARTICLE{Fasiolo2020-nz
doi = "10.1080/10618600.2019.1629942",
issn = "1061-8600"
}
@ARTICLE{Fasiolo2020-pr,
title = "Fast Calibrated Additive Quantile Regression",
author = "Fasiolo, Matteo and Wood, Simon N and Zaffran, Margaux and
Nedellec, Raphaël and Goude, Yannig",
journal = "Journal of the American Statistical Association",
publisher = "Taylor \& Francis",
pages = "1--11",
month = feb,
year = 2020,
doi = "10.1080/01621459.2020.1725521",
issn = "0162-1459"
}
9 changes: 5 additions & 4 deletions paper.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ The teaching of GAMs can benefit from visualisation of the spline basis function

# State of the field

Several R packages provide similar functionality to that of *gratia*. Notably, the *mgcViz* package [@Fasiolo2020-nz] provides sophisticated capabilities for plotting estimated smooths for models fitted by *mgcv* and *qgam* [@], and model diagnostics plots. A particular feature of *mgcViz* is that it was designed to be scalable, easily handling models fitted to data with millions of observations, a use case not currently well handled by *gratia*. *tidymv* [@tidymv-2023] and its successor, *tidygam* [@tidygam-2023], provide plots of estimated smooths and model predictions respectively, as well as differences of smooths, but the focus is on univariate smooths, in contrast to *gratia*'s ability to plot multivariate and specialist smooths (e.g. soap film smooths). Like *gratia*, the *itsadug* package [@itsadug-2022] is motivated to make working with estimated GAMs and related models easier. *itsadug* uses base graphics for plotting, but in place of partial effects plots, produces plots of adjusted predictions, and while useful for a broad range of models, is especially focused on GAMs fitted to longitudinal data with random effects.
Several R packages provide similar functionality to that of *gratia*. Notably, the *mgcViz* package [@Fasiolo2020-nz] provides sophisticated capabilities for plotting estimated smooths for models fitted by *mgcv* and *qgam* [@Fasiolo2020-pr], and model diagnostics plots. A particular feature of *mgcViz* is that it was designed to be scalable, easily handling models fitted to data with millions of observations, a use case not currently well handled by *gratia*. *tidymv* [@tidymv-2023] and its successor, *tidygam* [@tidygam-2023], provide plots of estimated smooths and model predictions respectively, as well as differences of smooths, but the focus is on univariate smooths, in contrast to *gratia*'s ability to plot multivariate and specialist smooths (e.g. soap film smooths). Like *gratia*, the *itsadug* package [@itsadug-2022] is motivated to make working with estimated GAMs and related models easier. *itsadug* uses base graphics for plotting, but in place of partial effects plots, produces plots of adjusted predictions, and while useful for a broad range of models, is especially focused on GAMs fitted to longitudinal data with random effects.

Areas where *gratia* stands out from these other packages are i) the consistent functionality for range of posterior simulations (*mgcViz* has some support for simulating new response values) as illustrated below, ii) support for computing derivatives of smooths, partial derivatives, and derivatives on the response scale (i.e. conditional derivatives), iii) tools for learning or teaching how GAMs work, iv) the range of utility functions that make working with GAMs easier, and v) the simple and consistent *tidy* interface to all functionality.
Areas where *gratia* stands out from these other packages are i) the consistent functionality for a range of posterior simulations (*mgcViz* has some support for simulating new response values) as illustrated below, ii) support for computing derivatives of smooths, partial derivatives, and derivatives on the response scale (i.e. conditional derivatives), iii) tools for learning or teaching how GAMs work, iv) the range of utility functions that make working with GAMs easier, and v) the simple and consistent *tidy* interface to all functionality.

# Example usage

Expand Down Expand Up @@ -129,7 +129,8 @@ m2 <- gam(
~ s(lat, lon, bs = "sos", m = -1, k = 100) + # power
s(jul.day, bs = "cr", k = 20) + s(bath, k = 10),
~ s(lat, lon, bs = "sos", m = -1, k = 100) + # scale
s(jul.day, bs = "cr", k = 20) + s(bath, k = 10)),
s(jul.day, bs = "cr", k = 20) + s(bath, k = 10)
),
data = chl, method = "REML", control = ctrl, family = twlss()
)
```
Expand All @@ -145,7 +146,7 @@ This model has much better model diagnostics although some large residuals remai
crs <- "+proj=ortho +lat_0=20 +lon_0=-40"
draw(m2, crs = crs, default_crs = 4326, dist = 0.05, rug = FALSE)
```
The plots produced by `draw()` from a fitted model are known as *partial effect plots* (Figure \ref{fig:m2-draw}), which show the component contributions, on the link scale, of each model term to the linear predictor. The y axis on these plots is typically centred around 0 due to most smooths having a sum-to-zero identifiability constraint applied to them. This constraint is what allows the model to include multiple smooths and remain identifiable. These plots allow you to read off the contributions of each smooth to the fitted response (on the link scale); they show link-scale *predictions* of the response for each smooth, conditional upon all other terms in the model, including any parametric effects and the intercept, having zero contribution. In the parlance of the *marginaleffects* package [@Arel-BundockGreiferHeiss:2024], these plots show *adjusted predictions*, just where the adjustment includes setting the contribution of *all* other model terms to the predicted value to zero. For *partial derivatives* (what *marginaleffects* would call a *marginal effect* or slope), *gratia* provides the `derivatives()`.
The plots produced by `draw()` from a fitted model are known as *partial effect plots* (Figure \ref{fig:m2-draw}), which show the component contributions, on the link scale, of each model term to the linear predictor. The y axis on these plots is typically centred around 0 due to most smooths having a sum-to-zero identifiability constraint applied to them. This constraint is what allows the model to include multiple smooths and remain identifiable. These plots allow you to read off the contributions of each smooth to the fitted response (on the link scale); they show link-scale *predictions* of the response for each smooth, conditional upon all other terms in the model, including any parametric effects and the intercept, having zero contribution. In the parlance of the *marginaleffects* package [@Arel-BundockGreiferHeiss:2024], these plots show *adjusted predictions*, just where the adjustment includes setting the contribution of *all* other model terms to the predicted value to zero. For *partial derivatives* (what *marginaleffects* would call a *marginal effect* or slope), *gratia* provides `derivatives()`.

Here, we see a specialised plot drawn for spline-on-the-sphere smooths $f(\mathtt{lat}_i,\mathtt{lon}_i)$ (Figure \ref{fig:m2-draw}, left-hand column), which uses `ggplot2::coord_sf()` and functionality from the *sf* package [@Pebesma2018-ws; @Pebesma2023-fe] to visualise the smooth via an orthographic projection.

Expand Down
Binary file modified paper_files/figure-latex/m1-appraise-1.pdf
Binary file not shown.
Binary file modified paper_files/figure-latex/m2-appraise-1.pdf
Binary file not shown.
Binary file modified paper_files/figure-latex/m2-draw-1.pdf
Binary file not shown.
Binary file not shown.

0 comments on commit b590153

Please sign in to comment.