Introduction

This is sample report for a randomization test on the weighted mean tolerance values of lost taxa in Red Run. Taxa include all families, orders, and genera. However, Chironomidae and Oligochaeta were excluded due to taxonomic bias and high abundance.

library(readxl)
b1wtv <- read_excel("C:/Users/tiena/OneDrive - Towson University/Thesis stuff/Data Analysis/Part a (1987 vs 2009)/Lost and Gained/Randomization of weighted tolval/Data (no Chirae and Oligta).xlsx", 
                       sheet = "B1")

Defining a function to sample and take means

set.seed(1)
sample_stats <- function(df, n=23){
  df <- df[sample(1:nrow(df), n, replace=F),]
  mx1 <- sum(df$TV*df$Density)/sum(df$Density)
  return(c(mx1))
}

Run it once just to see output

(sample_stats(b1wtv))

Run it 10,000 times

results <- replicate(10000, sample_stats(b1wtv,n=23))

Plot the results and calculate p-value

## [1] 0.7287