# Impact of Sample Size on Precision

Prelims

## Loading required package: permute
## Loading required package: lattice
## This is vegan 2.4-0
• Every tree of every species in a 50 hectare plot on Barro Colorado Island in the Panama Canal is permanently marked.
• Since a complete census has been done we know the real density of trees per hectare is 429.14 (21457 trees / 50 ha)
• The 50 ha plot is divided into 50 1 ha plot
• We could estimate the density per ha using a sample of these plots
• I randomly chose 5 plots and calcualted the mean and 95% confidence interval
• I also randomly chose 10 plots and calcualted the mean and 95% CI.
• I also generated a biased sample. Let’s say I was doing research on a rare tree Tetrathylacium johansenii. It only occurs in 5 plots on the in the 50 ha plot. I happen to have the data from those plots hand so I use them to calcualte the density of all trees (not just T. johansenii) per hectare.
• The results are below. Note the impact of sample size on the size of the error bars and therefore the precisions of the estimate.
size1 <- 5
size2 <- 20

#sample(1:50, size = size1,replace = F)
i1 <- c( 1,27,31,35,46)

#sample(1:50, size = size2,replace = F)

i2 <- c(46,11,43,48,7,
18,19,38,23,16,2,
15,34,32,8,3,5,29,
44,6)

#Species of interest
i.TEJO <- which(BCI[,"Tetrathylacium.johansenii"] > 0)

#Set up data
dat <- c(apply(BCI[i1,],1,sum),
apply(BCI[i2,],1,sum),
apply(BCI[i.TEJO,],1, sum),
sum(apply(BCI[,],1,sum))/50)

reps <- c(rep(paste("Rand",size1,sep="-"), size1),
rep(paste("Rand",size2,sep="-"), size2),
rep(paste("Bias",length(i.TEJO),sep = "-"),
length(i.TEJO)), "Real")

#function to plot confidence itnerval
ci <- function(x) c(mean(x, na.rm = T)-2*se(x), mean(x, na.rm = T)+2*se(x))

#Make plot
lineplot.CI(x.factor = reps,
response = dat,
lty = 0,
lwd = 3,
xlab = "",
ylab = "",
fun = function(x) mean(x, na.rm=TRUE),
ci.fun= ci,
col = 1:4,
cex = 3,
ylim = c(350,550))

legend("topleft", legend = c("Biased, n = 5",
"Random, n  = 20",
"Random, n = 5",
"Real value"),
col = 1:4,ncol = 2, fill = 1:4)
mtext(text = "Sample Size", side = 1,line = 2.25,cex = 2)
mtext(text = "Trees per ha", side = 2,line = 2.2,cex = 2)
mtext(text = "Tree denisty on Barro Colorado Island, Panama", side = 3,line = 1.2)