[Dimension Reduction + MOSAIC]

http://mosaicdatabase.web.ox.ac.uk

14 March 2022

Vignette #4 - Dimension Reduction + MOSAIC

MOSAIC was built for integrated analyses across trait fields. Whether the data are continuous (e.g., biomass) or categorical (e.g., dispersal class), MOSAIC allows researchers to explore these dimensions to identify the primary axes of variation across functional traits. Here, we will use a Multiple Factor Analysis (MFA) to explore the primary axes of variation between: biomass, dispersal capacity, growth determination, habitat type and mating system.

Note: These traits are picked solely to illustrate the analysis method that can be scaled for other traits in MOSAIC, demographic rates in COMADRE, COMPADRE and PADRINO and climate data from ERA5-Land.

library(devtools)
library(tidyverse) 
library(FactoMineR) # Required for MFA.
library(factoextra) # Required for visualizing MFA.

Accessing MOSAIC

Download MOSAIC from the mosaic portal. For more information on the basics of downloading MOSAIC and navigating the data structure, see: Vignette #1:

remotes::install_github("mosaicdatabase/Rmosaic")
library(Rmosaic)
mosaic <- mos_fetch("v1.0.0")
## 
## Phylogenetic tree with 1359 tips and 1358 internal nodes.
## 
## Tip labels:
##   Oxalis_acetosella, Rourea_induta, Euphorbia_telephioides, Euphorbia_fontqueriana, Triadica_sebifera, Actinostemon_concolor, ...
## Node labels:
##   Node1, Node2, Node3, Node4, Node5, Node6, ...
## 
## Rooted; includes branch lengths.

Generate dataframe for analysis

# Create a dataframe storing the values of the traits of interest.

mosaic_dataframe <- data.frame(mosaic@taxaMetadat, 
                               Biomass = as.numeric(mosaic@biomass@value),
                               Growth_Determination = as.factor(mosaic@growthdet@value),
                               Mating_System = as.factor(mosaic@matsyst@value),
                               Dispersal_Capacity = as.factor(mosaic@dispcap@value),
                               Habitat_Type = as.factor(mosaic@aquadep@value))

# Create a dataframe that only contains data for MFA.
# This step makes all dimension reduction functions easier.

mosaic_dataframe_subset <-  mosaic_dataframe[,c(8:12)] %>% 
  drop_na() %>% 
  filter(Growth_Determination != "NDY") %>%
  filter(Mating_System != "NDY") %>%
  filter(Dispersal_Capacity != "NDY") %>%
  filter(Habitat_Type != "NDY")

Perform MFA

# Run the multiple factor analysis using the MFA() function from FactoMineR.

mfa_mosaic <- MFA(mosaic_dataframe_subset, group = c(1, 1, 1, 1, 1), 
    type = c("s", rep("n", 4)),
    name.group=c("Biomass","Growth_Determination","Mating_System","Dispersal_Capacity", "Habitat_Type"),
    graph = FALSE)

# Note: Changing the graph argument to TRUE will return some diagnostic graphs of the MFA.

Explore the MFA

In this hypothetical example, we are interested in what traits covary with the primary axes of variation in the MFA (i.e., Dim1 and Dim2). To visualize these relationships, we can use the in-built fviz functions in the factoextra package to illustrate (1) position of individuals, (2) average effect of trait level (i.e. monogamous) on individual position within the 2 dimensions and (3) average effect of trait type (i.e. mating system).

fviz_mfa_ind(mfa_mosaic, 
             repel = TRUE,
             col.ind = "dark blue")

fviz_mfa_axes(mfa_mosaic, 
              repel = TRUE)

fviz_hmfa_var(mfa_mosaic, 
              repel = TRUE,
              choice = "group",
              col.var = "dark blue")