Assets

Download Data

A zip file with the data sets required for the R sessions can be downloaded here.

Alternatively, you load the data in your working directory by running following code in your R session:

download.file(
    url = "https://kamapu.gitlab.io/multivar/data/course-data.zip",
    destfile = "course-data.zip", method = "curl")
unzip("course-data.zip", overwrite = TRUE)
unlink("course-data.zip")

Required Packages

To install required packages and their dependencies, you need to carry out following code:

# update installed packages
update.packages(ask = FALSE)

# List of required CRAN-packages
pkgs <- c(
        "ade4",
        "devtools",
        "ggplot2",
        "GGally",
        "readODS",
        "tidyr",
        "vegan",
        "viridis")

# Installed Packages only if not yet done
inst_pkgs <- rownames(installed.packages())
install.packages(pkgs = pkgs[!pkgs %in% inst_pkgs])

# Packages from github
library(devtools)
install_github("ropensci/taxlist")
install_github("kamapu/vegtable")

Snippet for Last Session

Copy and paste this script to start the last session.

# Load packages
library(vegan)
library(vegtable)

# Load data
lalashan <- readRDS("lalashan.rds")

# Calculate frequencies
spp_freq <- aggregate(plot_id ~ taxon_code,
          FUN = function(x) length(unique(x)),
          data = lalashan$obs)
spp_freq <- spp_freq[order(spp_freq$plot_id, decreasing = TRUE), ]
head(spp_freq)
summary(as.factor(spp_freq$plot_id))

sel_spp <- with(spp_freq, taxon_code[plot_id > 1])

# Transform abundance values
hist(lalashan$obs$abund)
hist(log(lalashan$obs$abund + 1))

lalashan$obs$abund_log <- log(lalashan$obs$abund + 1)

# Delete rare species and do cross table
cross_table <- crosstable(abund_log ~ taxon_code + plot_id,
          FUN = mean,
          data = subset(lalashan$obs, taxon_code %in% sel_spp),
          na_to_zero = TRUE,
          as_matrix = TRUE)