This vignette gives a short example of how PPA can be applied to binary data sets using
phylopath. A longer example with more explanation of the code can be found in the other vignette, “intro to phylopath”.
There has been some discussion concerning how to best perform logistic regression with phylogenetic correction. I take no position on this matter. This package uses
phylolm::phyloglm, written by Lam Si Tung Ho, Robert Lachlan, Rachel Feldman and Cécile Ané.
phylopath’s accuracy is directly dependent on the accuracy of that function, and if you don’t trust
phyloglm you should not trust binary models used in
If you have useful opinions or information on this point, feel free to contact me.
This recreates the analysis from the following paper:
Dey CJ, O’Connor CM, Wilkinson H, Shultz S, Balshine S & Fitzpatrick JL. 2017. Direct benefits and evolutionary transitions to complex societies. Nature Ecology & Evolution. 0137.
This is, to my knowledge, the first study to employ PPA on binary traits.
The study investigates the evolution of cooperative breeding in cichlids. In short (my summary), there has been intense debate about what factors drive species towards evolving systems of cooperative breeding. Many have argued (and provided evidence in birds and mammals) that cooperative breeding chiefly evolves from monogamous mating systems because helpers can gain indirect fitness benefits through kin selection. However, a non-exclusive alternative hypothesis is that direct benefits due to ecological factors may be important and provide direct benefits. Therefore, both hypotheses should be considered at the same time.
The data is included in this paper as
It contains five variables:
Under the indirect fitness hypothesis, monogamy is expected to be a major driver of cooperative breeding, while group living, biparental care and diet type may be important contributors towards a direct benefits scenario.
Following the paper in question, we define 12 putative causal models.
library(phylopath) models <- define_model_set( A = c(C~M+D), B = c(C~D), C = c(C~D, P~M), D = c(C~D, M~P, G~P), E = c(C~D, P~M, G~P), F = c(C~D, P~M+G), G = c(C~D, M~P, P~G), H = c(C~D, M~P), I = c(C~D, M~M, G~P), J = c(M~P, G~D), K = c(P~M, G~D), L = c(C~M+D, P~M+G), .common = c(C~P+G) ) plot_model_set(models, algorithm = 'kk')
Now that we have our models, data and a tree, we can compare the models using
## 15 rows were dropped because they contained NA values.
## Pruned tree to drop species not included in dat.
## A phylogenetic path analysis, on the variables: ## Continuous: ## Binary: G P D M C ## ## Evaluated for these models: A B C D E F G H I J K L ## ## Containing 67 phylogenetic regressions, of which 22 unique
Note that two messages are printed. This is because there are missing values in our data set that are first being removed. Also, since the tree includes species for which data is missing, the tree had to be pruned. This is done automatically with a message to the user. You should check whether the amount of data removed is correct.
phylo_path notes that indeed all variables are binary.
## model k q C p CICc delta_CICc l w ## 1 F 5 10 7.949 0.634 33.065 0.000 1.000 0.511 ## 2 L 4 11 6.661 0.574 34.947 1.882 0.390 0.200 ## 3 G 5 10 10.938 0.362 36.055 2.990 0.224 0.115 ## 4 E 5 10 11.630 0.311 36.747 3.682 0.159 0.081 ## 5 D 5 10 11.734 0.303 36.850 3.785 0.151 0.077 ## 6 C 6 9 18.907 0.091 40.997 7.932 0.019 0.010 ## 7 H 6 9 20.527 0.058 42.618 9.553 0.008 0.004 ## 8 I 6 9 23.599 0.023 45.690 12.625 0.002 0.001 ## 9 K 6 9 25.331 0.013 47.422 14.357 0.001 0.000 ## 10 J 6 9 25.819 0.011 47.910 14.845 0.001 0.000 ## 11 B 7 8 28.776 0.011 47.976 14.911 0.001 0.000 ## 12 A 6 9 27.488 0.007 49.579 16.514 0.000 0.000
We see that model F is the best supported model. This model notably does not include a link between monogamy and cooperative breeding, giving support to the direct benefits hypothesis.
Model L, the second best model, is exactly the same as
Now that we have selected F as our best model, we still have three factors that affect cooperative breeding: diet, social grouping and parental care. Which one is more important? For this we can fit the model and look at magnitude of the coefficients. In this case, since we want to use the best model we use the function
best(). One can use
choice() to choose any arbitrary model, or
average() to average over several models.
To see the individual coefficients and their standard errors, simply print
## $coef ## G M P D C ## G 0 0 2.244975 0 4.499944 ## M 0 0 2.879175 0 0.000000 ## P 0 0 0.000000 0 3.415387 ## D 0 0 0.000000 0 3.415661 ## C 0 0 0.000000 0 0.000000 ## ## $se ## G M P D C ## G 0 0 0.8132303 0 1.202999 ## M 0 0 0.8602750 0 0.000000 ## P 0 0 0.0000000 0 1.351865 ## D 0 0 0.0000000 0 1.380511 ## C 0 0 0.0000000 0 0.000000 ## ## attr(,"class") ##  "fitted_DAG"
Or plot those:
But we can also plot the final model:
It appears that social grouping is a slightly more important than diet and biparental care.