-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
136 lines (109 loc) · 4.96 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{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"
)
```
<img src="man/figures/logo.png" height="139" alt="coevolve Logo"/>[<img src="https://raw.githubusercontent.com/stan-dev/logos/master/logo_tm.png" align="right" height="139" alt="Stan Logo"/>](https://mc-stan.org/)
# coevolve
<!-- badges: start -->
[![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)
<!-- badges: end -->
## Overview
The **coevolve** package allows the user to fit Bayesian dynamic coevolutionary
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,
iter_sampling = 500,
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 schocastic 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}
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