Skip to content

Instantly share code, notes, and snippets.

View zdealveindy's full-sized avatar

David Zelený zdealveindy

View GitHub Profile
T1_1 T1_2 T1_3 T1_4 T1_5 T1_6 T2_1 T2_2 T2_3 T2_4 T2_5 T2_6 T2_7 T2_8 T2_9 T2_10 T2_11 T2_12 T2_13
S01 99 100 100 98 100 100 100 100 100 100 93 100 100 100 100 99 100 97 100
S02 100 100 100 99 100 100 100 100 100 100 100 100 100 100 99 100 100 100 27
S03 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 0
S04 100 100 100 99 100 100 100 100 99 92 100 96 100 100 100 100 100 100 0
S05 100 100 100 98 100 100 100 96 97 93 100 100 98 98 100 90 100 98 0
S06 100 100 100 100 100 100 100 99 99 99 100 97 100 100 99 80 98 96 0
S07 100 100 100 100 100 100 100 100 100 100 100 98 100 100 100 0 100 100 38
S08 100 100 100 98 100 100 99 100 100 57 100 100 100 100 100 62 100 97 0
S09 100 100 99 0 100 100 100 100 100 100 100 100 100 100 100 100 100 100 12
CK_1 CK_2 CK_3 CK_4 CK_5 CK_6 DA_1 DA_2 DA_3 DA_4 DA_5 DA_6 DA_7 DA_8 DA_9 DA_10 DA_11 DA_12 DA_13
b09b01019 99 100 100 98 100 100 100 100 100 100 93 100 100 100 100 99 100 97 100
b07605051 100 100 100 99 100 100 100 100 100 100 100 100 100 100 99 100 100 100 27
b07208023 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 0
b06608068 100 100 100 99 100 100 100 100 99 92 100 96 100 100 100 100 100 100 0
b07b01004 100 100 100 98 100 100 100 96 97 93 100 100 98 98 100 90 100 98 0
b09b01023 100 100 100 100 100 100 100 99 99 99 100 97 100 100 99 80 98 96 0
b09b01013 100 100 100 100 100 100 100 100 100 100 100 98 100 100 100 0 100 100 38
b09b01007 100 100 100 98 100 100 99 100 100 57 100 100 100 100 100 62 100 97 0
b08b01012 100 100 99 0 100 100 100 100 100 100 100 100 100 100 100 100 100 100 12
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")
@zdealveindy
zdealveindy / multi.reg.r
Created April 25, 2022 01:05
multi_reg
# 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
# 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)
# 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')
# 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)
# 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)
# 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'
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