[R-sig-eco] relative habitat use in R
francois gillet
|r@nco|@@g|||et @end|ng |rom un|v-|comte@|r
Sun Feb 20 12:43:04 CET 2022
Dear Genoveva,
As 'relative habitat use' is the ratio of the average abundance of a given species in a given habitat to the average abundance of that species in all other habitats, you can apply it to density or frequency abundances, not only counts (but not to site profiles, i.e. relative abundances per site). Your code and your interpretation are correct.
To my knowledge, this indicator of habitat preferences has been applied in very few studies and only to birds so far. I suggest you to compare it with far more popular fidelity indices in community ecology, such as IndVal and phi, available in the indicspecies package (see references below). These indicators are perhaps better adapted to your study.
De Cáceres, M. and Legendre, P. 2009. Associations between species and groups of sites: indices and statistical inference. Ecology 90(12): 3566-3574.
Dufrêne, M. and P. Legendre. 1997. Species assemblages and indicator species: The need for a flexible asymetrical approach. Ecological Monographs 67:345-366.
Here is an example of such a comparison, in which I wrote a function to compute RHU for a set of species, based on you own example:
#######################################################
library(tidyverse)
# Data from Genoveva
speciesdata <- data.frame(
SampID = c(1:20),
biotope = factor(c( rep("A", 5), rep("B", 7), rep("C", 6), rep("B", 2))),
Species1 = c(0.2530517, 0.0000000, 0.0000000, 0.0000000, 0.0000000,
0.0000000, 0.0000000, 0.0000000, 0.0000000, 3.8468904,
1.0991115, 0.9617226, 0.0000000, 0.0000000, 0.0000000,
0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0000000)
)
# Add fictitious species
speciesdata <- speciesdata %>%
mutate(Species2 = 100 * Species1,
Species3 = round(Species2, 0),
Species4 = Species3 + 1)
# Function to compute RHU
rhu <- function(spe, hab, long = FALSE) {
# Computes relative habitat use of a set of species (Larsen et al. 2011)
# F. Gillet, 2022-02-20
# spe = a data frame of species abundances (sites x species)
# hab = a vector representing a partition of sites (factor of habitat classes)
# long = if TRUE, a long tibble instead of a data frame of species x habitat
if (!is.factor(hab)) {
hab <- factor(hab)
}
# nb of sites
P <- matrix(nrow(spe), nrow = length(lev), ncol = ncol(spe))
# habitat classes
lev <- levels(hab)
# sum of abundances per species and habitat
n_i <- spe %>% mutate(hab = hab) %>%
group_by(hab) %>% summarise_all(sum) %>%
select(-hab) %>% as.matrix
# sum of all abundances per habitat
N <- matrix(rep(colSums(n_i), each = length(lev)), ncol = ncol(spe))
# nb of sites per habitat
p_i <- matrix(rep(as.matrix(table(hab)), ncol(spe)), nrow = length(lev))
# compute RHU (data frame)
RHU <- (n_i / p_i) / ((N - n_i) / (P - p_i))
res <- t(RHU) %>% as.data.frame()
names(res) <- lev
# convert to a tibble (long format)
if (long) {
res <- RHU %>% as_tibble %>% mutate(Habitat = lev) %>%
pivot_longer(-Habitat, names_to = "Species", values_to = "RHU")
}
res
}
# Prepare the data
spe <- speciesdata %>% select(-1, -2) # species abundances
hab <- speciesdata$biotope # habitat classes
# Compute Larsen's relative habitat use
rhu(spe = spe, hab = hab) # data frame
rhu(spe = spe, hab = hab, long = TRUE) # long tibble
library(indicspecies)
# Compute Dufrêne and Legendre's IndVal (group-equalized)
strassoc(X = spe, cluster = hab, func = "IndVal.g")
# Compute point-biserial correlation (group-equalized)
strassoc(X = spe, cluster = hab, func = "r.g")
#######################################################
Best wishes,
François Gillet
----- Mail original -----
De: "Gonzalez-Mirelis, Genoveva" <genoveva.gonzalez-mirelis using hi.no>
À: "r-sig-ecology" <r-sig-ecology using r-project.org>
Envoyé: Vendredi 18 Février 2022 16:04:44
Objet: [R-sig-eco] relative habitat use in R
Dear list,
I am trying to calculate Relative Habitat Use as per this paper [https://doi.org/10.1016/j.ecolind.2021.108521], except that my species are sessile, marine invertebrates (including sponges, corals, etc.), and my habitats are rather biotopes. I guess my first question is whether it is legitimate to stretch the interpretation of RHU to this use case? I am trying to quantify the strength of the association of a bunch of species to each of my biotopes.
Another thing I am unsure about is what kind of effect I should expect from the fact that my abundance data are densities, rather than counts at each site?
Lastly, I generally wonder whether I have made any mistake in my calculations. My code is below. Many thanks in advance.
Genoveva
## code start
speciesdata <- data.frame(SampID = c(1:20), Species1 = c(0.2530517,
0.0000000,
0.0000000,
0.0000000,
0.0000000,
0.0000000,
0.0000000,
0.0000000,
0.0000000,
3.8468904,
1.0991115,
0.9617226,
0.0000000,
0.0000000,
0.0000000,
0.0000000,
0.0000000,
0.0000000,
0.0000000,
0.0000000),
biotope = factor(c(rep("A",5), rep("B",7), rep("C",6), rep("B",2))))
# for each species:
# rhu = (n[i]/p[i])/((N-n[i])/(P-p[i]))
# n[i] = no. of individuals in habitat[i]. Would have to use sum of density
# p[i] = no. of sites in habitat[i]
# N = total no. of individuals
# P = total no. of sites
# I still need to set a min acceptable n_i and p_i!!!
sp <- "Species1"
N <- speciesdata %>%
select(sp)%>%
sum # sum all densities
P <- dim(speciesdata)[1]
lev <- levels(speciesdata$biotope)
res <- setNames(data.frame(matrix(ncol = 1, nrow = length(lev))), sp) # empty data frame to store result
#for(n in 1:length(sp)){
for(i in 1:length(lev)){
n_i <- speciesdata %>%
filter(biotope==lev[i])%>%
select(sp)%>%
sum
p_i <- speciesdata %>%
filter(biotope==lev[i])%>%
dim(.)%>%
first
rhu = (n_i/p_i)/((N-n_i)/(P-p_i))
res[i,1]<-rhu
}
#}
res
# So I can conclude that Species1 is strongly associated to biotope B
## code end
[[alternative HTML version deleted]]
_______________________________________________
R-sig-ecology mailing list
R-sig-ecology using r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
More information about the R-sig-ecology
mailing list