Small data in ecology

TL;DR
#Simulate some data with known effect
# loop through 10000 simulations
library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.3     ✔ readr     2.1.4
✔ forcats   1.0.0     ✔ stringr   1.5.0
✔ ggplot2   3.4.3     ✔ tibble    3.2.1
✔ lubridate 1.9.3     ✔ tidyr     1.3.0
✔ purrr     1.0.2     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
ttest_sim<-function(nSim=1000, n=6, C_mean=12, T_mean=16, C_sd=2, T_sd=2){
out_frame<-rep(NA,nSim)

for (i in seq_along(out_frame)){
control=rnorm(n,C_mean, C_sd)
treatment=rnorm(n,T_mean, T_sd)
ttest<-t.test(control,treatment)
out_frame[i]<-ttest$p.value
}

data_out<-data.frame(nSim=1:nSim,pValue=out_frame)

data_out |> 
  ggplot(aes(pValue))+
  geom_histogram()+
  geom_vline(xintercept = 0.05, lty=2, colour="red")+
  ggthemes::theme_base()
  
}

ttest_sim(nSim=1000, n=6, C_mean=12, T_mean=14, C_sd=4, T_sd=4)
`stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

Acknowledgements