R code for small-town mayors

Here’s the R code I used for the post “Small-town mayors, internal searches, functional traits, and the estimation of extremes”.  Feel free to grab it and tinker.

 

# simulating extreme values
# Dec 11, 2016

setwd(“c:/data”)

DrawMean <-100
DrawSD <-50
RealizedMeanVector <- numeric(length=100)
RealizedMaxVector <- numeric(length=100)

DrawSizes <- c(10, 20, 30, 40, 50, 100, 150, 200, 300, 400, 500, 1000, 10000)

MeanEstimates <- numeric(length=13)
MaxEstimates <- numeric(length=13)
MeanSD <- numeric(length=13)
MaxSD <- numeric(length=13)

for (Draw in 1:13)
{
DrawSize <- DrawSizes[Draw]
for (j in 1:1000)
{
RandomSet <- rnorm(DrawSize, mean=DrawMean, sd = DrawSD)
RealizedMean <- mean(RandomSet)
RealizedMax <- max(RandomSet)
RealizedMeanVector[j] <- RealizedMean
RealizedMaxVector[j] <- RealizedMax
}
MeanEstimates[Draw] <- mean(RealizedMeanVector)
MeanSD[Draw] <- sd(RealizedMeanVector)
MaxEstimates[Draw] <- mean(RealizedMaxVector)
MaxSD[Draw] <-sd(RealizedMaxVector)
}

MeanEstimates
MeanSD
MaxEstimates
MaxSD

write (MeanEstimates, file = ‘meanestimatesfile.txt’)
write (MeanSD, file = ‘meansdfile.txt’)
write (MaxEstimates, file = ‘maxestimatesfile.txt’)
write (MaxSD, file = ‘MaxSDfile.txt’)