coevolve

coevolve R package for Bayesian generalized dynamic phylogenetic models using Stan

https://github.com/scottclaessens/coevolve

Science Score: 49.0%

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

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 4 DOI reference(s) in README
  • Academic publication links
    Links to: nature.com
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (22.5%) to scientific vocabulary

Keywords

bayesian-statistics coevolve evolution r-package stan statistical-models
Last synced: 6 months ago · JSON representation

Repository

coevolve R package for Bayesian generalized dynamic phylogenetic models using Stan

Basic Info
Statistics
  • Stars: 7
  • Watchers: 3
  • Forks: 0
  • Open Issues: 6
  • Releases: 1
Topics
bayesian-statistics coevolve evolution r-package stan statistical-models
Created over 2 years ago · Last pushed 7 months ago
Metadata Files
Readme Changelog Contributing License Code of conduct Codemeta

README.Rmd

---
output: github_document
---



```{r, include = FALSE}
options(width = 120)
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  dev = "png",
  dpi = 150,
  fig.asp = 0.8,
  fig.width = 5,
  out.width = "60%",
  fig.align = "center"
)
```

coevolve Logo[Stan Logo](https://mc-stan.org/)

# coevolve


  [![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)
  [![R-CMD-check](https://github.com/ScottClaessens/coevolve/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/ScottClaessens/coevolve/actions/workflows/R-CMD-check.yaml)
  [![Codecov test coverage](https://codecov.io/gh/ScottClaessens/coevolve/graph/badge.svg)](https://app.codecov.io/gh/ScottClaessens/coevolve)
  [![lint](https://github.com/ScottClaessens/coevolve/actions/workflows/lint.yaml/badge.svg)](https://github.com/ScottClaessens/coevolve/actions?query=workflow%3Alint)


```{r srr-tags, eval = FALSE, echo = FALSE}
#' srr_standards_in_readme
#'
#' @srrstats {G1.0} This README contains references to primary literature
#' @srrstats {G1.2} This README contains a repo status badge highlighting the 
#'   current state of development. We have also added a lifecycle statement to 
#'   .github/CONTRIBUTING.md.
#' @srrstats {BS1.2, BS1.2a} This README contains an example of specifying prior
#'   distributions
#' @srrstats {BS1.4, BS4.3} This README contains a model summary output with 
#'   Rhat and effective sample size statistics for checking convergence
```

## Overview

The **coevolve** package allows the user to fit Bayesian generalized dynamic
phylogenetic models in Stan. These models can be used to estimate how variables 
have coevolved over evolutionary time and to assess causal directionality
(X → Y vs. Y → X) and contingencies (X, then Y) in evolution.

While existing methods only allow pairs of binary traits to coevolve
(e.g., [BayesTraits](https://www.evolution.reading.ac.uk/BayesTraitsV4.1.2/BayesTraitsV4.1.2.html)),
the **coevolve** package allows users to include multiple traits of different
data types, including binary, ordinal, count, and continuous traits.

## Installation

To use the **coevolve** package, you must first install the `cmdstanr` package
(see full installation instructions here: https://mc-stan.org/cmdstanr/).

```{r install_cmdstanr, eval = FALSE}
install.packages("cmdstanr", repos = c("https://mc-stan.org/r-packages/", getOption("repos")))
```

You can then install the development version of **coevolve** with:

```{r install_coevolve, eval = FALSE}
# install.packages("devtools")
devtools::install_github("ScottClaessens/coevolve")
```

## How to use coevolve

```{r load-package}
library(coevolve)
```

As an example, we analyse the coevolution of political and religious authority
in 97 Austronesian societies. These data were compiled and analysed in [Sheehan
et al. (2023)](https://www.nature.com/articles/s41562-022-01471-y). Both 
variables are four-level ordinal variables reflecting increasing levels of
authority. We use a phylogeny of Austronesian languages to assess patterns of 
coevolution.

```{r authority-fit}
fit <-
  coev_fit(
    data = authority$data,
    variables = list(
      political_authority = "ordered_logistic",
      religious_authority = "ordered_logistic"
    ),
    id = "language",
    tree = authority$phylogeny,
    # manually set prior
    prior = list(A_offdiag = "normal(0, 2)"),
    # arguments for cmdstanr
    parallel_chains = 4,
    refresh = 0,
    seed = 1
  )
```

The results can be investigated using:

```{r authority-summary}
summary(fit)
```

The summary provides general information about the model and details on the 
posterior draws for the model parameters. In particular, the output shows the 
autoregressive selection effects (i.e., the effect of a variable on itself in 
the future), the cross selection effects (i.e., the effect of a variable on 
another variable in the future), the amount of drift, continuous time intercept 
parameters for the stochastic differential equation, and cutpoints for the 
ordinal variables.

While this summary output is useful as a first glance, it is difficult to
interpret these parameters directly to infer directions of coevolution. Another
approach is to "intervene" in the system. We can hold variables of interest at
their average values and then increase one variable by a standardised amount to
see how this affects the optimal trait value for another variable.

The `coev_plot_delta_theta()` function allows us to visualise $\Delta\theta_{z}$
for all variable pairs in the model. $\Delta\theta_{z}$ is defined as the change
in the optimal trait value of one variable which results from a one median
absolute deviation increase in another variable.

```{r authority-delta-theta, fig.height=5, fig.width=5}
#| fig.alt: >
#|   Plot showing the posterior distributions of delta theta for both
#|   directions of coevolution between political and religious authority. The
#|   bulk of the posterior densities are greater than zero.
coev_plot_delta_theta(fit)
```

This plot suggests that both variables influence one another in their 
coevolution. A standardised increase in political authority results in an 
increase in the optimal trait value for religious authority, and vice versa.
In other words, these two variables reciprocally coevolve over evolutionary
time.

## Citing coevolve

When using the **coevolve** package, please cite the following papers:

- Ringen, E., Martin, J. S., & Jaeggi, A. (2021). Novel phylogenetic methods 
  reveal that resource-use intensification drives the evolution of "complex" 
  societies. _EcoEvoRXiv_. https://doi.org/10.32942/osf.io/wfp95
- Sheehan, O., Watts, J., Gray, R. D., Bulbulia, J., Claessens, S., Ringen, 
  E. J., & Atkinson, Q. D. (2023). Coevolution of religious and political 
  authority in Austronesian societies. _Nature Human Behaviour_, _7_(1), 38-45. 
  https://doi.org/10.1038/s41562-022-01471-y

Owner

  • Name: Scott Claessens
  • Login: ScottClaessens
  • Kind: user
  • Location: Auckland, New Zealand
  • Company: University of Auckland

Postdoctoral Research Fellow at the University of Auckland

CodeMeta (codemeta.json)

{
  "@context": "https://doi.org/10.5063/schema/codemeta-2.0",
  "@type": "SoftwareSourceCode",
  "identifier": "coevolve",
  "description": "Fit Bayesian generalized dynamic phylogenetic models using 'Stan'. The package allows an abritrary number of variables with different response distributions to coevolve on a phylogenetic tree via an Ornstein-Uhlenbeck evolutionary process, allowing users to assess directionality between coevolving variables.",
  "name": "coevolve: Fit Bayesian Generalized Dynamic Phylogenetic Models using 'Stan'",
  "relatedLink": "https://scottclaessens.github.io/coevolve/",
  "codeRepository": "https://github.com/ScottClaessens/coevolve",
  "issueTracker": "https://github.com/ScottClaessens/coevolve/issues",
  "license": "file LICENSE",
  "version": "0.1.0",
  "programmingLanguage": {
    "@type": "ComputerLanguage",
    "name": "R",
    "url": "https://r-project.org"
  },
  "runtimePlatform": "R version 4.4.2 (2024-10-31 ucrt)",
  "author": [
    {
      "@type": "Person",
      "givenName": "Scott",
      "familyName": "Claessens",
      "email": "scott.claessens@gmail.com",
      "@id": "https://orcid.org/0000-0002-3562-6981"
    },
    {
      "@type": "Person",
      "givenName": "Erik",
      "familyName": "Ringen",
      "email": "erikjacob.ringen@uzh.ch"
    }
  ],
  "maintainer": [
    {
      "@type": "Person",
      "givenName": "Scott",
      "familyName": "Claessens",
      "email": "scott.claessens@gmail.com",
      "@id": "https://orcid.org/0000-0002-3562-6981"
    }
  ],
  "softwareSuggestions": [
    {
      "@type": "SoftwareApplication",
      "identifier": "knitr",
      "name": "knitr",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=knitr"
    },
    {
      "@type": "SoftwareApplication",
      "identifier": "rmarkdown",
      "name": "rmarkdown",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=rmarkdown"
    },
    {
      "@type": "SoftwareApplication",
      "identifier": "testthat",
      "name": "testthat",
      "version": ">= 3.0.0",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=testthat"
    },
    {
      "@type": "SoftwareApplication",
      "identifier": "tibble",
      "name": "tibble",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=tibble"
    },
    {
      "@type": "SoftwareApplication",
      "identifier": "withr",
      "name": "withr",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=withr"
    }
  ],
  "softwareRequirements": {
    "1": {
      "@type": "SoftwareApplication",
      "identifier": "ape",
      "name": "ape",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=ape"
    },
    "2": {
      "@type": "SoftwareApplication",
      "identifier": "bayesplot",
      "name": "bayesplot",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=bayesplot"
    },
    "3": {
      "@type": "SoftwareApplication",
      "identifier": "cmdstanr",
      "name": "cmdstanr"
    },
    "4": {
      "@type": "SoftwareApplication",
      "identifier": "colorspace",
      "name": "colorspace",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=colorspace"
    },
    "5": {
      "@type": "SoftwareApplication",
      "identifier": "dplyr",
      "name": "dplyr",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=dplyr"
    },
    "6": {
      "@type": "SoftwareApplication",
      "identifier": "ggplot2",
      "name": "ggplot2",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=ggplot2"
    },
    "7": {
      "@type": "SoftwareApplication",
      "identifier": "Matrix",
      "name": "Matrix",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=Matrix"
    },
    "8": {
      "@type": "SoftwareApplication",
      "identifier": "methods",
      "name": "methods"
    },
    "9": {
      "@type": "SoftwareApplication",
      "identifier": "patchwork",
      "name": "patchwork",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=patchwork"
    },
    "10": {
      "@type": "SoftwareApplication",
      "identifier": "phangorn",
      "name": "phangorn",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=phangorn"
    },
    "11": {
      "@type": "SoftwareApplication",
      "identifier": "phaseR",
      "name": "phaseR",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=phaseR"
    },
    "12": {
      "@type": "SoftwareApplication",
      "identifier": "phytools",
      "name": "phytools",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=phytools"
    },
    "13": {
      "@type": "SoftwareApplication",
      "identifier": "posterior",
      "name": "posterior",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=posterior"
    },
    "14": {
      "@type": "SoftwareApplication",
      "identifier": "purrr",
      "name": "purrr",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=purrr"
    },
    "15": {
      "@type": "SoftwareApplication",
      "identifier": "readr",
      "name": "readr",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=readr"
    },
    "16": {
      "@type": "SoftwareApplication",
      "identifier": "rlang",
      "name": "rlang",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=rlang"
    },
    "17": {
      "@type": "SoftwareApplication",
      "identifier": "stats",
      "name": "stats"
    },
    "18": {
      "@type": "SoftwareApplication",
      "identifier": "stringr",
      "name": "stringr",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=stringr"
    },
    "19": {
      "@type": "SoftwareApplication",
      "identifier": "tidyr",
      "name": "tidyr",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=tidyr"
    },
    "20": {
      "@type": "SoftwareApplication",
      "identifier": "R",
      "name": "R",
      "version": ">= 3.5.0"
    },
    "SystemRequirements": null
  },
  "fileSize": "2563.849KB",
  "releaseNotes": "https://github.com/ScottClaessens/coevolve/blob/master/NEWS.md",
  "readme": "https://github.com/ScottClaessens/coevolve/blob/main/README.md",
  "contIntegration": "https://github.com/ScottClaessens/coevolve/actions/workflows/R-CMD-check.yaml",
  "developmentStatus": "https://www.repostatus.org/#active",
  "keywords": [
    "bayesian-statistics",
    "evolution",
    "r-package",
    "stan",
    "statistical-models",
    "coevolve"
  ]
}

GitHub Events

Total
  • Create event: 14
  • Release event: 1
  • Issues event: 31
  • Delete event: 14
  • Issue comment event: 139
  • Push event: 86
  • Pull request review event: 1
  • Pull request event: 11
Last Year
  • Create event: 14
  • Release event: 1
  • Issues event: 31
  • Delete event: 14
  • Issue comment event: 139
  • Push event: 86
  • Pull request review event: 1
  • Pull request event: 11

Dependencies

DESCRIPTION cran
  • R >= 3.5.0 depends
  • ape * imports
  • cmdstanr * imports
  • colorspace * imports
  • dplyr * imports
  • ggdist * imports
  • ggplot2 * imports
  • methods * imports
  • phangorn * imports
  • phaseR * imports
  • readr * imports
  • rlang * imports
  • stringr * imports
  • tidybayes * imports
  • tidyr * imports
  • tidyselect * imports
  • knitr * suggests
  • rmarkdown * suggests
  • testthat >= 3.0.0 suggests
  • withr * suggests