Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Distributions of body mass noodling for sDevTraits
# Rough-and-ready body-mass/species-number estimation in mammals and birds
# Will Pearse - 2021-09-19
##########################
# Load data ##############
##########################
library(caper)
library(ape)
library(Pareto)
##########################
# Load data ##############
##########################
# Get body masses
m.traits <- read.delim("https://figshare.com/ndownloader/files/5631084")
m.traits <- setNames(m.traits$BodyMass.Value, tolower(gsub(" ", "_", m.traits$Scientific)))
m.traits <- m.traits[!duplicated(names(m.traits)) & !is.na(m.traits)] # Hackety hack don't call back
b.traits <- read.delim("https://figshare.com/ndownloader/files/5631081")
b.traits <- setNames(b.traits$BodyMass.Value, tolower(gsub(" ", "_", b.traits$Scientific)))
b.traits <- b.traits[!duplicated(names(b.traits)) & !is.na(b.traits)] # Hackety hack don't call back
# Get phylogenies
b.tree <- read.tree("~/Dropbox/Common/bird_tree.tre")
b.tree$tip.label <- tolower(b.tree$tip.label)
m.tree <- read.tree("~/Dropbox/Common/faurby_mammals.tre")
m.tree$tip.label <- tolower(m.tree$tip.label)
# Make comparative objects (and match, poorly)
mammals <- comparative.data(m.tree, data.frame(mass=m.traits,species=names(m.traits)), species)
birds <- comparative.data(b.tree, data.frame(mass=b.traits,species=names(b.traits)), species)
##########################
# Fit some curves ########
##########################
# Pareto
Pareto_ML_Estimator_Alpha(log10(m.traits), .001)
Pareto_ML_Estimator_Alpha(log10(b.traits), .001)
Pareto_ML_Estimator_Alpha(log10(c(m.traits,b.traits)), .001)
# ... I am a little surprised at how consistent these alpha values are
# given I would naively have thought birds and mammals were quite
# different
# ... Note that messing around with the threshold does affect the estimate
# ... I think we want to log for this, but I could be wrong
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment