knitr::opts_chunk$set(echo = FALSE) library(DiagrammeR) library(knitr) library(kableExtra) library(FD) library(vegan) library(ltm) library(edcpR) library(tidyverse)
Case studies:
Common beech (Fagus sylvatica) is increasing in ForĂȘt de Compiegne (N. France) and we want to know if it has an effect on the forest understory species. We have sampled the understory in 26 forest plots. Some plots with, other without Fagus in the overstory.
Research question: Does Fagus sylvatica (common beech) have an effect on the understory cover in temperate forests?
Use the Compiegne datasets. The Understory cover is the sum of all species individuals:
library(edcpR) data(Compiegne_env, Compiegne_sp, package = "edcpR")
Understory_cover <- rowSums(Compiegne_sp[2:dim(Compiegne_sp)[2]]) Compiegne <- data.frame(plot = Compiegne_env$plot, Fagus = Compiegne_env$Fagus, Understory_cover = Understory_cover) head(Compiegne)
Point-biserial correlation coefficient (rp)
X = Compiegne$Understory_cover Y = Compiegne$Fagus n <- length(Y) a = sqrt((sum(Y)*(n-sum(Y)))/(n^2)) sn <- sqrt((1/(n))*sum((X- mean(X))^2)) rpb = a*(mean(X[Y==1])-mean(X[Y==0]))/sn rpb # very weak correlation t <- rpb*sqrt((n-2)/(1-rpb^2)) pt(t, n-2) # Not significant
cor.test(Compiegne$Fagus, Compiegne$Understory_cover) biserial.cor(Compiegne$Understory_cover, Compiegne$Fagus, level = 2)
We want to study the relationship between different soil variables to gain more insight in soil processes in Finnish marshes.
Research question: Is there a relationship between soil Ca content and soil pH?
Use the varechem dataset:
library(vegan) data(varechem, package = "vegan")
par(mfrow = c(2,2)) hist(varechem$Ca, prob=TRUE, xlab="Ca",main="Histogram of Calcium") m<-mean(varechem$Ca) std<-sqrt(var(varechem$Ca)) curve(dnorm(x, mean=m, sd=std),col="darkblue", lwd=2, add=TRUE, yaxt="n") hist(varechem$pH , prob=TRUE, xlab="pH",main="Histogram of pH") m<-mean(varechem$pH) std<-sqrt(var(varechem$pH)) curve(dnorm(x, mean=m, sd=std),col="darkblue", lwd=2, add=TRUE, yaxt="n") qqnorm(varechem$Ca, main="Normal Q-Q of Calcium") qqnorm(log(varechem$pH), main="Normal Q-Q of pH")
lmMod <- lm(Ca ~ pH, data=varechem) par(mfrow = c(2,2)) plot(lmMod)
n <- length(varechem$Ca) di <- rank(varechem$Ca, ties.method = "average") - rank(varechem$pH, ties.method = "average") rs <- 1 - (6*sum(di^2))/(n*(n^2-1)) # r-squared rs # Weak correlation t <- rs*sqrt((n-2)/(1-rs^2)) # Test statistic pt(t, n-2) # not significant
cor.test(varechem$Ca, varechem$pH, method = "spearman")
You can use the pearson correlation if:
Using the dune_spec dataset:
Research question: Is the species composition of a haypasture dune grassland closer to a hayfield dune grassland or to pasture dune grassland?
data(dune_spec, package = "edcpR")
vegdist(dune_spec[,-1],method = "bray")
Using the varechem dataset:
Research question: How do the soil conditions compare between the plots?
rm("varechem")
data(varechem, package = "vegan")
# Baresoil, is not a soil condition, so it can just be deleted from the data frame varechem <- varechem %>% select(-Baresoil) head(varechem) # Standardize variables varechem_scale <- as.data.frame(scale(varechem))
# Euclidian distance euclidean <- vegdist(varechem_scale, method = "euclidean") euclidean <- scores(euclidean) # Some possible conclusions... which(euclidean == min(euclidean[euclidean > 0]), arr.ind=TRUE) which(euclidean == max(euclidean), arr.ind=TRUE)
NO Assignment this week.
Next session assignment on this and the next exercise session.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.