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

Introduction to mcfly package

mcfly package was designed to evaluate the influence of the adaptation rate of species niche positions along the macroevolutionary dynamics of a given lineage on niche-based species sorting accross sets of local species assemblages, and ultimately on biological diversity gradients across metacommunities. We will demonstrate in this vignette all the steps needed to carry on an analysis using the mcfly function. First of all, we need to install and read the mcfly package from github repository

library(devtools)
install_github("sokole/MCSim")
install_github("GabrielNakamura/mcfly")
library(mcfly)

Data: Furnariidae family

We will run all the analysis using occurrence data of avian species from Furnariidae family. This data is part of the mcfly package. To read it, type:

data("Furnariidae")

Furnariidae dataset comprises the occurence of 223 Furnariidae species distributed across the entire Neotropical region. The phylogenetic hypothesis used in this analysis was obtained from BirdTree and are presented in phylo Furnariidae data, also presented in mcfly package.

data("phylo_Furnariidae")

An environmental descriptor is also needed to run mcfly function. In this example we use a dataframe present in mcfly package that contains four environmental variables (mean anual temperature, temperature sazonality, mean anual precipitation and precipitation sazonality) and geographic coordinates of sites (latitude and longitude).

data("envir")

These three datasets comprise the basic information needed to perform the individual-based simulation model presented in mcfly function.

Data proccessing

Since large trees require great computational performance and given that the power of analysis is affected by the representativeness of species pool on phylogenetic hypothesis used, we splitted the phylogeny of Furnariidae species, and selected the subfamily Synallaxinae to perform the analysis, since it contains a reasonable number of species widely distributed across sites in the Neotropics.

sub.tree<- ape::subtrees(phylo_Furnariidae) #splitting internal nodes in the phylogeny
n.nodes<-length(sub.tree)
nspp.nodes<-matrix(NA,n.nodes,1)
for(i in 1:n.nodes){
  nspp.nodes[i,]<-sub.tree[[i]]$Ntip #number of species in each internal node
}

dim.comm.subset<-matrix(NA,nspp.nodes,2)
for(j in 1:n.nodes){
  sub.phy<-sub.tree[[j]]
  comm.sub.phy<-Furnariidae[,sub.phy$tip.label]
  zero.row<-which(rowSums(comm.sub.phy)==0)
  comm.subset<-comm.sub.phy[-zero.row,]
  dim.comm.subset[j,]<-dim(comm.subset) # number of sites showing occurrences of species belonging to each internal node
}

We chose Synallaxinae subfamily, that presented nine species distributed through 649 communities. Species occurrences were extracted from community data frame. We also filtered environmental variables and geographic coordinates of points to match the occurrences of Synallaxinae species in community data.

plot(sub.tree[[49]]) #Synallaxinae subfamily
sub.phy<- sub.tree[[49]]
comm.sub.phy<- Furnariidae[, sub.tree[[49]]$tip.label] #selecting only sites that present occurrences of species of Synallaxinae
zero.row<- which(rowSums(comm.sub.phy) == 0)
comm.subset<- comm.sub.phy[-zero.row, ] #community matrix with occurrences of Synalaxynae species
coords.subset<- as.matrix(envir[rownames(comm.subset), c(1,2)]) #extracting coordinates

Setting parameters to enter in mcfly function The parameters that need to be set in mcfly function are defined mainly by the features of species niche positions, which are defined based on a single environmental variable or a factor/principal component summarizing covariation among a number of environmental variables. In this example we decided to use latitude, assuming that this single variable represents a latent variable that summarizes the variation in a set of niche dimensions. The parameters that must be defined before running mcfly function are:



GabrielNakamura/mcfly documentation built on July 27, 2023, 12:45 p.m.