Resources

 

R-Script

Brandl & Bellwood 2014, Journal of Animal Ecology: Individual-based analyses of niche overlap

###This code implements individual-based analyses of niche overlap
###contact me if you find any bugs or have troubles

###load packages
library(vegan)
library(geometry)
library(ape)
library(cluster)
library(rcdd)

###function CHVintersect is required -- load from http://villeger.sebastien.free.fr/R%20scripts/CHVintersect.r

###load data
mydata <- read.csv(file = file.choose())

###check data types
str(mydata)
rownames$mydata <- mydata[1]
mydata1 <- mydata[-1]

###compute Gower's distance matrix from raw data fo each individual
D <- daisy(mydata1, metric= "gower")

###perform PCoA from Gower's distance matrix with Cailliez correction to avoid negative eigenvalues
P <- pcoa(D, correction = "cailliez")

###look at P
biplot(P)

###create vector with species names called "sp.list" -- species need to match names in data
sp.list <- c("sp1", "sp2", "sp3", "etc")

###extract coordinates of all individuals in as many dimensions as wanted, here in 4 dimensions
coord <- as.matrix(P$vectors)
coord <- coord[,1:4]


###perform volume calculations using loop
###create empty vectors to store results
nbrep <- 999
holder <- rep(NA, )
volumes <- array(NA, dim = c(nbrep, length(sp.list)))
colnames(volumes) <- sp.list
meanvols <- as.data.frame(colMeans(volumes))
totd <- as.matrix(coord[,1:4])
vol_totd <- convhulln(totd, "FA")$vol


###loop for calculating species volumes with subsampling -- here, the number of individuals to use as a
###subsample is set to 10 to avoid full sampling of Ttrit. Number of bootstrapping iterations set to 999.

for (i in 1:length(sp.list))
{
  for (j in 1:nbrep)
  {
    print(j)
    sp_i <- as.matrix(coord[grep(sp.list[i], rownames(coord)),1:4])
    sp_ii <- sp_i[sample(1:nrow(sp_i), 10, replace = F),]
    
    holder <- convhulln(sp_ii, "FA")$vol
    volumes[j,i] <- holder
  }
}

###results
colMeans(volumes)
meanvols <- as.data.frame(colMeans(volumes))
meanvols
relvols <- meanvols/vol_totd
relvols

 


###calculate overlaps
###vector to store result
holder<-rep(NA)
overlap<-rep(NA)
overlap.results <- array(NA, dim=c(length(sp.list),length(sp.list)))

colnames(overlap.results) <- sp.list
rownames(overlap.results) <- sp.list

for (l in 1:length(sp.list))
{
  for (m in l:length(sp.list))
  {
    

    print(l)
    sp_l <- as.matrix(coord[grep(sp.list[l], rownames(coord)),1:4])
    sp_m <- as.matrix(coord[grep(sp.list[m], rownames(coord)),1:4])
    sp_ll <- sp_l[sample(1:nrow(sp_l), 10, replace = F),]
    sp_mm <- sp_m[sample(1:nrow(sp_mm), 10, replace = F),]
    holder<-CHVintersect(sp_ll, sp_mm)$vol
    overlap <- (1-(holder[3]/(holder[1]+holder[2])))

    overlap.results[m,l] <- overlap
    
    
  }
}

# end of k
final.overlap <- as.data.frame(overlap.results)


Press

Several news outlets have picked up on my latest paper, demonstrating the potential for coordinated vigilance in coral reef fishes. See below for a selection.

NY Times: One fish stands watch while another eats.
Sueddeutsche Zeitung: Helferfish
Phys.org: I've got your back

 

I wrote an article for The Conversation, talking about the importance of protecting functional diversity.