# Phylogenetic models with multiple group-level effects

**URL:** <https://discourse.mc-stan.org/t/phylogenetic-models-with-multiple-group-level-effects/23328>\
**Category:** brms\
**Created:** [July 5, 2021, 1:53pm UTC](https://discourse.mc-stan.org/t/phylogenetic-models-with-multiple-group-level-effects/23328 "2021-07-05T13:53:40Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ptibarra](https://avatars.discourse-cdn.com/v4/letter/p/ad7895/32.png) [@ptibarra](https://discourse.mc-stan.org/u/ptibarra)\
**Post date:** [July 5, 2021, 1:53pm UTC](https://discourse.mc-stan.org/t/phylogenetic-models-with-multiple-group-level-effects/23328/1 "2021-07-05T13:53:40Z")

</div>

We want to model sulphur accumulation in leaves in 80 species growing in  
gypsum soils as result of 4 factors:

-Soil as PC1 of a PCA with soil features  
-MAT (Mean Annual Temperature)  
-MAP (Mean Annual Precipitation)  
-phylogeny (we have a tree)

we have repeated measurements for each species (different individuals)  
and that information should be included.

Thanks

Pablo

---

<div class="post-metadata">

**Author:** ![jsocolar](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jsocolar/32/2486_2.png) [@jsocolar](https://discourse.mc-stan.org/u/jsocolar)\
**Post date:** [July 5, 2021, 3:09pm UTC](https://discourse.mc-stan.org/t/phylogenetic-models-with-multiple-group-level-effects/23328/2 "2021-07-05T15:09:03Z")

</div>

Hi Pablo, welcome to discourse! Are you asking how to specify an appropriate model in Stan? If so, it would be helpful to know:

- I assume because of the tag that you intend to do this in brms?
- whether you wish to model relationships as linear or as something more flexible
- what distribution you wish to use for the response variable (Gaussian? something else?)
- what you have tried so far

---

<div class="post-metadata">

**Author:** ![ptibarra](https://avatars.discourse-cdn.com/v4/letter/p/ad7895/32.png) [@ptibarra](https://discourse.mc-stan.org/u/ptibarra)\
**Post date:** [July 7, 2021, 3:08pm UTC](https://discourse.mc-stan.org/t/phylogenetic-models-with-multiple-group-level-effects/23328/3 "2021-07-07T15:08:40Z")

</div>

Hi Jacob!

First of all, I realized that I omitted a 5th and more relevant factor, the gypsum affinity of the plant, which indeed is the factor explaining more variance in the elemental accumulation in the leaves. So we are interested in including in the model:

-Affinity to gypsum (categoric)  
-Soil as PC1 of a PCA with soil features  
-MAT (Mean Annual Temperature)  
-MAP (Mean Annual Precipitation)  
-phylogeny (we have a tree)

And answering your questions:

1.-Yes, we have read about brms, but never used Stan before

2.-We go for linear models for the moment

1. We need Gamma distribution, since our data are chemical concentrations with variance of data increasing with means. The distribution of our data is hence skewed, with most data concentrated around zero values but a long tail towards increased scores.

4.- We discarded GLS and PhyloANOVA since they do not allow including intraspecific variability (different reps per species). We have used GLMMs (TMB) with phylogenetic effects included as random terms where “Species” is nested within “Family”. Family explains circa 40% of variation and affinity to gypsum around 10%. The other variables are less explicative.

However, we have received the recommendation to include the whole phylogeny in our model using a covariance matrix. For that reason we got interested in brms as a feasible approach. However, we are fearing our models may be too complicated, since they include 5 factors.

---

<div class="post-metadata">

**Author:** ![Ax3man](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/ax3man/32/11894_2.png) [@Ax3man](https://discourse.mc-stan.org/u/Ax3man)\
**Post date:** [July 7, 2021, 7:26pm UTC](https://discourse.mc-stan.org/t/phylogenetic-models-with-multiple-group-level-effects/23328/4 "2021-07-07T19:26:25Z")

</div>

The vignette should get you started: [Estimating Phylogenetic Multilevel Models with brms](https://cran.r-project.org/web/packages/brms/vignettes/brms_phylogenetics.html)

---

<div class="post-metadata">

**Author:** ![ptibarra](https://avatars.discourse-cdn.com/v4/letter/p/ad7895/32.png) [@ptibarra](https://discourse.mc-stan.org/u/ptibarra)\
**Post date:** [July 9, 2021, 7:46am UTC](https://discourse.mc-stan.org/t/phylogenetic-models-with-multiple-group-level-effects/23328/5 "2021-07-09T07:46:39Z")

</div>

Thanks Wouter,

In fact that has been our starting point, but we feel our data are more complex than the situation explained in the vignette. Concretely they may fix to the very last point, and not developed:

## Phylogenetic models with multiple group-level effects

That is why we are searching for help. We wonder whether our analysis is really feasible with brms or not.

Pablo

---

<div class="post-metadata">

**Author:** ![jsocolar](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jsocolar/32/2486_2.png) [@jsocolar](https://discourse.mc-stan.org/u/jsocolar)\
**Post date:** [July 12, 2021, 2:11am UTC](https://discourse.mc-stan.org/t/phylogenetic-models-with-multiple-group-level-effects/23328/6 "2021-07-12T02:11:16Z")

</div>

I still don’t quite understand what the question is. What are you having trouble doing? What have you tried in brms so far?

---

<div class="post-metadata">

**Author:** ![Ax3man](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/ax3man/32/11894_2.png) [@Ax3man](https://discourse.mc-stan.org/u/Ax3man)\
**Post date:** [July 15, 2021, 12:43am UTC](https://discourse.mc-stan.org/t/phylogenetic-models-with-multiple-group-level-effects/23328/7 "2021-07-15T00:43:01Z")

</div>

I believe the part about “Phylogenetic models with multiple group-level effects” refers to models that don’t just model the phylogeny as a single effect but also allow other parameters to vary with phylogeny, so `(1 + x | gr(phylo, cov = A)) ` type models instead of `(1 | gr(phylo, cov = A))`. As far as I know, that’s not very commonly done in “run-of-the-mill” comparative analysis.

It sounds like you want something along the lines of this:

```
m <- brm(
    accumulation ~ 1 + soil + MAT + MAP + gypsum_affinity + 
      (1 | gr(phylo, cov = A)) + (1 | species) ,
   data = your_data, family = 'gamma'
)

```

Where `A` is obtained with `ape::vcv.phylo(phylo)`. This satisfies the recommendation you got to include the whole phylogeny.

If this is not what you want, or if it doesn’t work, try to be specific about what your question is.
