knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  eval = FALSE
)

Incorporating correlations

Phylogenetic 'factor analysis'

$$\text{trait}{i,j} = \text{root}_j + \sum_k\beta{j, k}\mu_{i, k}$$ $$\mu_{i, k} \sim \text{Pflow}\left(\phi_k^2\right)$$ where $j$ is refers to the $j$th trait dimension, and $k$ refers to the $k$th latent trait dimension.


Essentially this is dimension reduction, but where the latent space is constrained to be consistent with a model of evolutionary change on a phylogeny. The code for that model would look like this:

mod_mult <- fibre(Beak.Length_Culmen_tr + Beak.Length_Nares_tr + Beak.Width_tr + Beak.Depth_tr ~ bre_brownian(phlo, latent = 2), 
                  data = avonet_beaks,
                  engine_options = list(verbose = TRUE))
ls()

This model is not fully implemented, but should be available as a new feature in the package shortly.

Let's try a few interesting variations on the basic model

A tale of two phylogenies

The model is:

$$\text{trait}{i,j} = \mu_i + \mu_j + \mu{i}^\text{int} \mu_{j}^\text{int}$$ $$\mu_i \sim \text{Pflow}i\left(\phi_i^2\right); \mu_j \sim \text{Pflow}_j\left(\phi_j^2\right)$$ $$\mu_i^\text{int} \sim \text{Pflow}_i\left(\phi\text{int}^2\right); \mu_j^\text{int} \sim \text{Pflow}j\left(\phi\text{int}^2\right)$$


$$\mu_i^\text{int} \sim \text{Pflow}i\left(\phi\text{int}^2\right); \mu_j^\text{int} \sim \text{Pflow}j\left(\phi\text{int}^2\right)$$

then:

$$\mu_\text{int} = \mu_{i}^\text{int} \mu_{j}^\text{int} \sim \text{Pflow}\text{i}\otimes\text{Pflow}\text{j}\left(\phi_\text{int}^2\right)$$ - which means that the interaction can be modeled with a single parameter that is distributed according to a phylogenetic flow model that is the Kronecker product of the two interacting phylogenetic flows.

A Tale of Two Phylogenies

mod_int <- fibre(EFFECTSIZE1 ~ bre_brownian(plant_phlo) + bre_brownian(fungus_phlo) + 
                   bre_brownian(plant_phlo * fungus_phlo) +
                   re(PlantSpecies2018) +
                   re(FungalGenus2018) +
                   bre_brownian(fungus_phlo * pf_as_pfc(PlantSpecies2018)) +
                   bre_brownian(plant_phlo * pf_as_pfc(FungalGenus2018)),
                 data = plant_fungus %>%
                   filter(plant_is_tip & fungus_is_tip),
                 engine_options = list(verbose = TRUE))

mod_int
ls()

A tale of two phylogenies

mod_int <- readr::read_rds("extdata/mod_int.rds")

mod_int
ls()


rdinnager/fibre documentation built on Dec. 14, 2024, 10:33 a.m.