gratia

gratia: An R package for exploring generalized additive models - Published in JOSS (2024)

https://github.com/gavinsimpson/gratia

Science Score: 98.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 6 DOI reference(s) in README and JOSS metadata
  • Academic publication links
    Links to: joss.theoj.org
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
    Published in Journal of Open Source Software

Keywords

distributional-regression gam gamm generalized-additive-mixed-models generalized-additive-models ggplot2 glm lm mgcv penalized-spline r r-package random-effects smoothing splines

Scientific Fields

Engineering Computer Science - 40% confidence
Last synced: 4 months ago · JSON representation ·

Repository

ggplot-based graphics and useful functions for GAMs fitted using the mgcv package

Basic Info
Statistics
  • Stars: 228
  • Watchers: 10
  • Forks: 33
  • Open Issues: 81
  • Releases: 14
Topics
distributional-regression gam gamm generalized-additive-mixed-models generalized-additive-models ggplot2 glm lm mgcv penalized-spline r r-package random-effects smoothing splines
Created over 7 years ago · Last pushed 4 months ago
Metadata Files
Readme Changelog Contributing License Code of conduct Citation

README.Rmd

---
output: github_document
---



```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%",
  dev = "ragg_png",
  dpi = 96
)
options(tibble.print_min = 5, tibble.print_max = 5)
library("mgcv")
library("gratia")
```

# gratia


[![R build status](https://github.com/gavinsimpson/gratia/workflows/R-CMD-check/badge.svg)](https://github.com/gavinsimpson/gratia/actions)
[![codecov](https://codecov.io/gh/gavinsimpson/gratia/branch/main/graph/badge.svg?token=GG5NQfgRFu)](https://app.codecov.io/gh/gavinsimpson/gratia)
[![CRAN\_Status\_Badge](https://www.r-pkg.org/badges/version/gratia)](https://cran.r-project.org/package=gratia)
[![CRAN Downloads](https://cranlogs.r-pkg.org/badges/grand-total/gratia)](https://cran.r-project.org/package=gratia)
[![DOI](https://joss.theoj.org/papers/10.21105/joss.06962/status.svg)](https://doi.org/10.21105/joss.06962)
[![r-universe version](https://gavinsimpson.r-universe.dev/gratia/badges/version)](https://gavinsimpson.r-universe.dev/gratia)
[![r-universe status](https://gavinsimpson.r-universe.dev/gratia/badges/checks)](https://gavinsimpson.r-universe.dev/gratia)


## Overview

Working with GAMs within the 'tidyverse' can be tedious and even difficult
without a good understanding of GAMs themselves and how the model is returned
by 'mgcv' and what the model objects contain. 'gratia' is designed to help with
this.

'gratia' provides 'ggplot'-based graphics and utility functions for working with
generalized additive models (GAMs) fitted using the 'mgcv' package, via a
reimplementation of the `plot()` method for GAMs that 'mgcv' provides, as well
as 'tidyverse' compatible representations of estimated smooths.

## Citation

If you use *gratia* in your work, please cite the package using:

Simpson, G. L., (2024). gratia: An R package for exploring generalized additive
models. *Journal of Open Source Software*, **9**(104), 6962,


## Features

```{r draw-gam-figure, fig.height = 6, fig.width = 9, echo = FALSE, fig.show = "hide", message = FALSE}
df1 <- data_sim("eg1", n = 400, seed = 42)
m1 <- gam(y ~ s(x0) + s(x1) + s(x2) + s(x3), data = df1, method = "REML")
draw(m1, residuals = TRUE, rug = FALSE)
```

```{r draw-gam-figure-2d, fig.height = 6, fig.width = 9, echo = FALSE, fig.show = "hide", message = FALSE}
df2 <- data_sim("eg2", n = 1000, seed = 42)
m2 <- gam(y ~ s(x, z), data = df2, method = "REML")
draw(m2)
```

```{r appraise-figure, fig.height = 6, fig.width = 9, echo = FALSE, fig.show = "hide"}
appraise(m1)
```

The main features of *gratia* are currently

* A *ggplot2*-based replacement for `mgcv:::plot.gam()`: `draw.gam()`.

  For example, the classic four term additive example from Gu & Wahba:
	
  ![Estimated smooths from a GAM](man/figures/README-draw-gam-figure-1.png)

  Or for a bivariate smooth:
    
  ![Estimated smooths from a GAM](man/figures/README-draw-gam-figure-2d-1.png)

  Note that some specialist smoothers (`bs %in% c("mrf","sw", "sf")`) are not
  currently supported, but univariate, *factor* and *continuous* `by`-variable
  smooths, simple random effect smooths (`bs = 're'`), factor-smooth
  interaction smooths (`bs = "fs"`), constrained factor smooths (`bs = "sz"`),
  full soap film smooths (`bs = "so"`), and bivariate, trivariate, and
  quadvariate TPRS and tensor product smooths are supported,

* Estimation of derivatives of fitted smoothers: `derivatives()`,

* Estimation of point-wise across-the-function confidence intervals and
  simultaneous intervals for smooths: `confint.gam()`.

* Model diagnostics via `appraise()`

  ![Model diagnostics figure](man/figures/README-appraise-figure-1.png)

## Installing *gratia*

*gratia* is now available on CRAN, and can be installed with

```{r install, eval = FALSE}
install.packages("gratia")
```

however *gratia* is under active development and you may wish to install the
development version from github. The easiest way to do this is via the
`install_github()` function from package *remotes*. Make sure you have
*remotes* installed, then run

```{r install-github, eval = FALSE}
remotes::install_github("gavinsimpson/gratia")
```

to install the package. Alternatively, binary packages of the development
version are available from rOpenSci's R Universe service:

```{r install-r-universe, eval = FALSE}
# Install gratia in R
install.packages("gratia", repos = c(
  "https://gavinsimpson.r-universe.dev",
  "https://cloud.r-project.org"
))
```

## History

*gratia* grew out of an earlier package, *schoenberg*, itself a development of
the earlier package *tsgam*, which was originally intended to be used with GAMs
fitted to time series. As I was developing *tsgam* however it became clear that
the package could be used more generally and that the name "tsgam" was no longer
appropriate. To avoid breaking blog posts I had written using *tsgam* I decided
to copy the git repo and all the history to a new repo for the package under the
name *schoenberg*. At a later date someone released another package called
*schoenberg* to CRAN, so that scuppered that idea. Now I'm calling the package
*gratia*. Hopefully I won't have to change it again…

## Why *gratia*?

In naming his [*greta*](https://github.com/greta-dev/greta) package, Nick
Golding observed the recent phenomena of naming statistical modelling software,
such as Stan or Edward, after individuals that played a prominent role in the
development of the field. This lead Nick to name his Tensor Flow-based package
*greta* after [*Grete Hermann*](https://greta-stats.org/articles/webpages/why_greta.html).

In the same spirit, *gratia* is named in recognition of the contributions of
[Grace Wahba](https://en.wikipedia.org/wiki/Grace_Wahba), who did pioneering
work on the penalised spline models that are at the foundation of the way GAMs
are estimated in *mgcv*. I wanted to name the package *grace*, to explicitly
recognise Grace's contributions, but unfortunately there was already a package
named *Grace* on CRAN. So I looked elsewhere for inspiration.

The English word "grace" derives from the Latin *gratia*, meaning "favour, charm,
thanks" ([according to Merriam Webster](https://www.merriam-webster.com/dictionary/grace)).

The chair that Grace Wahba currently holds is named after 
[Isaac J Schoenberg](https://en.wikipedia.org/wiki/Isaac_Jacob_Schoenberg), a
former University Madison-Wisconsin Professor of Mathematics, who in a 1946
paper provided the first mathematical reference to "splines". (Hence the
previous name for the package.)

Owner

  • Name: Gavin Simpson
  • Login: gavinsimpson
  • Kind: user
  • Location: Denmark
  • Company: Aarhus University

JOSS Publication

gratia: An R package for exploring generalized additive models
Published
December 21, 2024
Volume 9, Issue 104, Page 6962
Authors
Gavin L. Simpson ORCID
Department of Animal and Veterinary Sciences, Aarhus University, Denmark
Editor
Oskar Laverny ORCID
Tags
splines generalized additive models posterior simulation

Citation (CITATION.cff)

cff-version: 1.2.0
message: 'To cite package "gratia" in publications use:'
type: software
license: MIT
title: 'gratia: Graceful ggplot-Based Graphics and Other Functions for GAMs
  Fitted Using mgcv'
version: 0.10.0
doi: 10.32614/CRAN.package.gratia
abstract: 'Graceful ggplot-based graphics and utility functions for working with
  generalized additive models (GAMs) fitted using the mgcv package. Provides a
  reimplementation of the plot() method for GAMs that mgcv provides, as well
  as tidyverse- compatible representations of estimated smooths.'
authors:
- family-names: Simpson
  given-names: Gavin L.
  email: ucfagls@gmail.com
  orcid: https://orcid.org/0000-0002-9084-8413
preferred-citation:
  type: manual
  title: 'gratia: Graceful ggplot-Based Graphics and Other Functions for GAMs
    Fitted Using mgcv'
  authors:
  - family-names: Simpson
    given-names: Gavin L.
    email: ucfagls@gmail.com
    orcid: https://orcid.org/0000-0002-9084-8413
  version: 0.10.0
  doi: 10.32614/CRAN.package.gratia
  abstract: 'Graceful ggplot-based graphics and utility functions for working
    with generalized additive models (GAMs) fitted using the mgcv package.
    Provides a reimplementation of the plot() method for GAMs that mgcv
    provides, as well as tidyverse-compatible representations of estimated
    smooths.'
  repository: https://CRAN.R-project.org/package=gratia
  repository-code: https://github.com/gavinsimpson/gratia
  url: https://gavinsimpson.github.io/gratia/
  date-released: '2024-12-20'
  contact:
  - family-names: Simpson
    given-names: Gavin L.
    email: ucfagls@gmail.com
    orcid: https://orcid.org/0000-0002-9084-8413
  keywords:
  - gam
  - generalized-additive-models
  - ggplot2
  - glm
  - lm
  - mgcv
  - r-package
  - random-effects
  - smoothing
  license: MIT
  year: '2024'
repository: https://CRAN.R-project.org/package=gratia
repository-code: https://github.com/gavinsimpson/gratia
url: https://gavinsimpson.github.io/gratia/
date-released: '2024-12-20'
contact:
- family-names: Simpson
  given-names: Gavin L.
  email: ucfagls@gmail.com
  orcid: https://orcid.org/0000-0002-9084-8413
keywords:
- gam
- generalized-additive-models
- ggplot2
- glm
- lm
- mgcv
- r-package
- random-effects
- smoothing

Papers & Mentions

Total mentions: 11

Hierarchical generalized additive models in ecology: an introduction with mgcv
Last synced: 2 months ago
The impact of PIT tags on the growth and survival of pythons is insignificant in randomised controlled trial
Last synced: 2 months ago
Corticosteroids and Regional Variations in Thickness of the Human Cerebral Cortex across the Lifespan
Last synced: 2 months ago
In the shadows of snow leopards and the Himalayas: density and habitat selection of blue sheep in Manang, Nepal
Last synced: 2 months ago
Long‐term changes in occurrence, relative abundance, and reproductive fitness of bat species in relation to arrival of White‐nose Syndrome in West Virginia, USA
Last synced: 2 months ago
River connectivity and climate behind the long‐term evolution of tropical American floodplain lakes
Last synced: 2 months ago
Trajectories of Mother-Infant Communication: An Experiential Measure of the Impacts of Early Life Adversity
Last synced: 2 months ago
Phosphorus Availability Promotes Bacterial DOC-Mineralization, but Not Cumulative CO2-Production
Last synced: 2 months ago
High-Resolution X-Ray Computed Tomography: A New Workflow for the Analysis of Xylogenesis and Intra-Seasonal Wood Biomass Production
Last synced: 2 months ago
Outbreaks of Vector-Borne and Zoonotic Diseases Are Associated With Changes in Forest Cover and Oil Palm Expansion at Global Scale
Last synced: 2 months ago
Agro-Environmental Determinants of Leptospirosis: A Retrospective Spatiotemporal Analysis (2004–2014) in Mahasarakham Province (Thailand)
Last synced: 2 months ago

GitHub Events

Total
  • Create event: 2
  • Release event: 2
  • Issues event: 54
  • Watch event: 21
  • Issue comment event: 81
  • Push event: 197
  • Fork event: 4
Last Year
  • Create event: 2
  • Release event: 2
  • Issues event: 54
  • Watch event: 21
  • Issue comment event: 81
  • Push event: 197
  • Fork event: 4

Committers

Last synced: 5 months ago

All Time
  • Total Commits: 2,742
  • Total Committers: 24
  • Avg Commits per committer: 114.25
  • Development Distribution Score (DDS): 0.013
Past Year
  • Commits: 236
  • Committers: 1
  • Avg Commits per committer: 236.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Gavin Simpson u****s@g****m 2,706
runner r****r@M****l 6
Henrik Singmann s****n@g****m 5
runner r****r@M****l 3
Lars Dalby l****s@b****k 3
David Lawrence Miller g****b@n****t 1
runner r****r@M****l 1
runner r****r@M****l 1
runner r****r@M****l 1
runner r****r@M****l 1
runner r****r@M****l 1
runner r****r@M****l 1
runner r****r@M****l 1
runner r****r@M****l 1
runner r****r@M****l 1
runner r****r@M****l 1
runner r****r@M****l 1
runner r****r@M****l 1
runner r****r@M****l 1
runner r****r@M****l 1
runner r****r@M****l 1
runner r****r@M****l 1
DavisVaughan d****s@r****m 1
John Muschelli m****2@g****m 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 4 months ago

All Time
  • Total issues: 221
  • Total pull requests: 2
  • Average time to close issues: 10 months
  • Average time to close pull requests: 17 days
  • Total issue authors: 67
  • Total pull request authors: 2
  • Average comments per issue: 1.55
  • Average comments per pull request: 1.5
  • Merged pull requests: 2
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 32
  • Pull requests: 0
  • Average time to close issues: 23 days
  • Average time to close pull requests: N/A
  • Issue authors: 12
  • Pull request authors: 0
  • Average comments per issue: 0.81
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • gavinsimpson (134)
  • StefanoMezzini (4)
  • jonathonmellor (4)
  • Aariq (3)
  • dill (3)
  • fhui28 (3)
  • nicholasjclark (3)
  • noamross (3)
  • wStockhausen (2)
  • Silviculturalist (2)
  • vankesteren (2)
  • GatesDupont (2)
  • Nataliannash (2)
  • cmagelssen (2)
  • raff-k (2)
Pull Request Authors
  • muschellij2 (1)
  • DavisVaughan (1)
  • dill (1)
Top Labels
Issue Labels
enhancement (67) bug (37) plotting (17) good first issue (9) consistency (7) not a bug (3) question (3) cran (2) documentation (2) can't reproduce (2) tests (1) published papers (1) help wanted (1) wontfix (1)
Pull Request Labels

Packages

  • Total packages: 2
  • Total downloads:
    • cran 4,603 last-month
  • Total dependent packages: 3
    (may contain duplicates)
  • Total dependent repositories: 10
    (may contain duplicates)
  • Total versions: 30
  • Total maintainers: 1
proxy.golang.org: github.com/gavinsimpson/gratia
  • Versions: 12
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent packages count: 5.5%
Average: 5.6%
Dependent repos count: 5.8%
Last synced: 4 months ago
cran.r-project.org: gratia

Graceful 'ggplot'-Based Graphics and Other Functions for GAMs Fitted Using 'mgcv'

  • Versions: 18
  • Dependent Packages: 3
  • Dependent Repositories: 10
  • Downloads: 4,603 Last month
Rankings
Stargazers count: 2.5%
Forks count: 3.5%
Average: 7.4%
Downloads: 8.1%
Dependent repos count: 9.2%
Dependent packages count: 13.6%
Maintainers (1)
Last synced: 4 months ago

Dependencies

.github/workflows/R-CMD-check.yaml actions
  • actions/checkout v3 composite
  • r-lib/actions/check-r-package v2 composite
  • r-lib/actions/setup-pandoc v2 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite
  • r-lib/actions/setup-tinytex v2 composite
.github/workflows/pkgdown.yaml actions
  • JamesIves/github-pages-deploy-action 4.1.4 composite
  • actions/checkout v2 composite
  • r-lib/actions/setup-pandoc v2 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite
.github/workflows/readme-renderer.yaml actions
  • actions/checkout v3 composite
  • r-lib/actions/setup-pandoc v2 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite
.github/workflows/test-coverage.yaml actions
  • actions/checkout v3 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite
DESCRIPTION cran
  • R >= 4.1.0 depends
  • cli * imports
  • dplyr >= 1.0.10 imports
  • ggplot2 * imports
  • grDevices * imports
  • grid * imports
  • lifecycle * imports
  • mgcv >= 1.8 imports
  • mvnfast * imports
  • nlme * imports
  • patchwork * imports
  • pillar * imports
  • purrr * imports
  • rlang * imports
  • stats * imports
  • stringr * imports
  • tibble >= 3.0.0 imports
  • tidyr * imports
  • tidyselect * imports
  • tools * imports
  • vctrs * imports
  • GJRM * suggests
  • MASS * suggests
  • datasets * suggests
  • forcats * suggests
  • gamm4 * suggests
  • knitr * suggests
  • lme4 * suggests
  • rmarkdown * suggests
  • scam * suggests
  • testthat * suggests
  • vdiffr * suggests
  • withr * suggests