Skip to content

Research at St Andrews

Hierarchical generalized additive models in ecology: an introduction with mgcv

Research output: Contribution to journalArticle


Open Access permissions



Eric J. Pedersen, David L. Miller, Gavin L. Simpson, Noam Ross

School/Research organisations


In this paper, we discuss an extension to two popular approaches to modeling complex structures in ecological data: the generalized additive model (GAM) and the hierarchical model (HGLM). The hierarchical GAM (HGAM), allows modeling of nonlinear functional relationships between covariates and outcomes where the shape of the function itself varies between different grouping levels. We describe the theoretical connection between HGAMs, HGLMs, and GAMs, explain how to model different assumptions about the degree of intergroup variability in functional response, and show how HGAMs can be readily fitted using existing GAM software, the mgcv package in R. We also discuss computational and statistical issues with fitting these models, and demonstrate how to fit HGAMs on example data. All code and data used to generate this paper are available at:


Original languageEnglish
Article numbere6876
Number of pages42
Publication statusPublished - 27 May 2019

    Research areas

  • Generalized additive models, Hierarchical models, Time series, Functional regression, Smoothing, Regression, Community ecology, Tutorial, Nonlinear estimation

Discover related content
Find related publications, people, projects and more using interactive charts.

View graph of relations

Related by author

  1. Density and distribution of western chimpanzees around a bauxite deposit in the Boé Sector, Guinea-Bissau

    Dias, F., Wenceslau, J., Marques, T. A. & Miller, D. L., 13 Sep 2019, In : American Journal of Primatology. Early View, e23047.

    Research output: Contribution to journalComment/debate

  2. From here and now to there and then: practical recommendations for extrapolating cetacean density surface models to novel conditions

    Bouchet, P. J-F., Miller, D. L., Roberts, J., Mannocci, L., Harris, C. M. & Thomas, L., 4 Sep 2019, University of St Andrews. 59 p. (CREEM Technical Report; no. 2019-1)

    Research output: Book/ReportOther report

  3. Distance sampling in R

    Miller, D. L., Rexstad, E., Thomas, L., Marshall, L. & Laake, J. L., 9 May 2019, In : Journal of Statistical Software. 89, 1, 28 p.

    Research output: Contribution to journalArticle

  4. Distance sampling

    Buckland, S. T., Miller, D. L. & Rexstad, E., 2019, Quantitative Analyses in Wildlife Science. Brennan, L., Marcot, B. & Tri, A. (eds.). Johns Hopkins University Press, p. 97-112

    Research output: Chapter in Book/Report/Conference proceedingChapter

Related by journal

  1. PeerJ (Journal)

    David Ellard Keith Ferrier (Member of editorial board)
    2017 → …

    Activity: Publication peer-review and editorial work typesEditor of research journal

  2. PeerJ (Journal)

    Gozde Ozakinci (Editor)

    Activity: Publication peer-review and editorial work typesEditor of research journal

  3. PeerJ (Journal)

    Ildiko Maureen Lara Somorjai (Reviewer)
    2015 → …

    Activity: Publication peer-review and editorial work typesPeer review of manuscripts

  4. PeerJ (Journal)

    Maria Dornelas (Member of editorial board)
    2014 → …

    Activity: Publication peer-review and editorial work typesEditor of research journal

Related by journal

  1. Metabarcoding reveals a high diversity of woody host-associated Phytophthora spp. in soils at public gardens and amenity woodlands in Britain

    Riddell, C. E., Frederickson-Matika, D., Armstrong, A. C., Elliot, M., Forster, J., Hedley, P. E., Morris, J., Thorpe, P., Cooke, D. EL., Pritchard, L., Sharp, P. M. & Green, S., 16 May 2019, In : PeerJ. 7, e6931.

    Research output: Contribution to journalArticle

  2. The newly described Araguaian river dolphins, Inia araguaiaensis (Cetartiodactyla, Iniidae), produce a diverse repertoire of acoustic signals

    Melo-Santos, G., Figueiredo Rodrigues, A. L., Tardin, R. H., Maciel, I. D. S., Marmontel, M., da Silva, M. L. & May-Collado, L. J., 19 Apr 2019, In : PeerJ. 7, 20 p., e6670.

    Research output: Contribution to journalArticle

  3. A short, robust brain activation control task optimised for pharmacological fMRI studies

    Harvey, J-L., Demetriou, L., McGonigle, J. & Wall, M. B., 11 Sep 2018, In : PeerJ. 6, 18 p., e5540.

    Research output: Contribution to journalArticle

  4. Chimpanzees (Pan troglodytes) display limited behavioural flexibility when faced with a changing foraging task requiring tool use

    Harrison, R. A. & Whiten, A., 19 Feb 2018, In : PeerJ. 6, 28 p., e4366.

    Research output: Contribution to journalArticle

ID: 259182806