This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
plot.iNEXT <- function (x, type = 1, se = TRUE, show.legend = TRUE, show.main = TRUE, | |
col = NULL, xlab = "", ylab = "", ...) | |
{ | |
if (class(x) != "iNEXT") | |
stop("invalid object class") | |
TYPE <- c(1, 2, 3) | |
SPLIT <- c("none", "order", "site", "both") | |
if (is.na(pmatch(type, TYPE)) | pmatch(type, TYPE) == -1) | |
stop("invalid plot type") | |
type <- pmatch(type, 1:3) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Species SPAD502 SPAD502plus | |
Psychotria rubra 50.4 49 | |
Psychotria rubra 46.8 49.5 | |
Psychotria rubra 54.9 56.6 | |
Solanum diphyllum 65.6 63.6 | |
Litsea sp. 45.6 42.7 | |
Mallotus paniculatus 51.6 52.4 | |
Machilus zuihoensis 43.8 44.1 | |
Machilus zuihoensis 46.8 47.6 | |
Ficus ampelas 54.9 56.9 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
species WSG_obs WSG_data source | |
1 Acacia 0.539 0.9 a | |
2 Adansonia 0.21 0.5 b | |
3 Albizia 0.581 0.69 a | |
4 Azadirachta 0.521 0.7 a | |
5 Bauhinia 0.469 0.619 c | |
6 Bombax 0.335 0.27 d | |
7 Bridelia 0.557 0.62 e | |
8 Butea 0.377 0.465 c | |
9 Cassia 0.665 0.746 c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Mia Momberg - reanalysis of JEcol dataset | |
# importing libraries | |
library (readxl) | |
library (tidyverse) | |
library (modEvA) | |
library (car) | |
# importing data from Dryad repository | |
url <- 'https://datadryad.org/stash/downloads/file_stream/573456' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Pseudoreplication issue | |
# 1600 quadrats sampled in 8 grids (each grid 200 quadrats) | |
# what happens if we consider quadrats as independent units? | |
DEP <- rnorm (1600) | |
EXP <- rnorm (1600) | |
GRID <- rep (1:8, each = 200) | |
boxplot (DEP ~ GRID) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Diversity along elevation gradient - pseudoreplication issue | |
# Elevation 200-1000 m asl, five elevation zones | |
# Richness (number of species) between 1-100 species | |
seed <- 56654 | |
par (mfrow = c(2,2)) | |
# Scenario 1: 5 replicate at each zone, each replicate at different mountain (random diversity) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Euclidean vs Hellinger vs Bray-Curtis distances and double zero problem | |
library (vegan) | |
library (pals) | |
vltava.spe <- read.delim ('https://raw.githubusercontent.com/zdealveindy/anadat-r/master/data/vltava-spe.txt', row.names = 1) | |
prop_dz <- function (com) | |
(nrow (com)-designdist (x = com, method = "A+B-J", terms = "binary"))/nrow (com) # calculates proportion of double zeros | |
D_eucl <- dist (vltava.spe, method = 'euclidean') | |
D_hell <- dist (decostand (vltava.spe, method = 'hell'), method = 'euclidean') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Hellinger distance | |
library (vegan) | |
png (width = 6, height = 6, units = 'in', res = 300) | |
par (mar = c(5,5,2,2)) | |
plot (0:1, 0:1, xlab = list ('Species 1', cex = 1.5), ylab = list ('Species 2', cex = 1.5), axes = F, xlim = c(0, 1.3), ylim = c(0,1.3), type = 'n') | |
par (xpd = NA) | |
arrows (x0 = 0, x1 = 1.3, y0 = 0, y1 = 0) | |
arrows (x0 = 0, x1 = 0, y0 = 0, y1 = 1.3) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Individual examples | |
# 1) Both w1 and w2 similarly related to y | |
set.seed (1234) | |
# Generate two random variables N(0,1) | |
x1 <- rnorm (100, 0, 1) | |
x2 <- rnorm (100, 0, 1) | |
X <- cbind (x1, x2) | |
# Generate correlation matrix to make variables correlated at r = 0.8 | |
R <- matrix (c(sqrt (.8), sqrt (.2), sqrt (0.2), sqrt (.8)), ncol = 2) | |
W <- X%*%R |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scale_override <- function(which, scale) { | |
if(!is.numeric(which) || (length(which) != 1) || (which %% 1 != 0)) { | |
stop("which must be an integer of length 1") | |
} | |
if(is.null(scale$aesthetics) || !any(c("x", "y") %in% scale$aesthetics)) { | |
stop("scale must be an x or y position scale") | |
} | |
structure(list(which = which, scale = scale), class = "scale_override") |