daijiang / phyr

Functions for phylogenetic analyses
https://daijiang.github.io/phyr/
GNU General Public License v3.0
30 stars 10 forks source link

Three/Four level nested random effects #68

Open GitTFJ opened 3 years ago

GitTFJ commented 3 years ago

Is there a way to include multi-level nested random effects e.g. (in lme4 syntax) (1|time/species/site/region)?

rdinnager commented 3 years ago

I don't think the / syntax is supported in phyr (am I right on that @daijiang ?), but (1|time/species) is equivalent to (1|time) + (1|time:species). An interaction in the grouping term is also not supported by phyr I don't think (?), but you could easily construct a factor that is equivalent to time:species and use that as your grouping term, e.g (1|time) + (1|time_species), where time_species has a unique value for each combination of time and species. Likewise this could be done for each nesting level that you need, e.g. (1|time) + (1|time_species) + (1|time_species_site) + (1|time_species_site_region). In each case the variable has a single unique factor value for each combination of the grouping terms being nested. Here is a good blog post that shows three ways to code nested random effects (where the method I suggest, which should definitely work with phyr, is the third way: "implicit nesting"): https://www.muscardinus.be/2017/07/lme4-random-effects/

Hope that helps.