Skip to content

Instantly share code, notes, and snippets.

@explodecomputer
Last active August 29, 2015 14:21
Show Gist options
  • Save explodecomputer/69e7caed8f7b6cf9b23b to your computer and use it in GitHub Desktop.
Save explodecomputer/69e7caed8f7b6cf9b23b to your computer and use it in GitHub Desktop.
Calculate mean squared error
calculate_mean_squared_error <- function(dati, samplesize, numberofbootstraps)
{
squared_error <- array(0, numberofbootstraps)
mean_dati <- mean(dati)
for(i in 1:numberofbootstraps)
{
squared_error[i] <- (mean_dati - mean(sample(dati, samplesize)))^2
}
return(mean(squared_error))
}
dati <- rnorm(800)
samplesizes <- seq(10, 800, by=10)
mean_squared_error <- array(0, length(samplesizes))
for(i in 1:length(samplesizes))
{
cat(i, "\n")
mean_squared_error[i] <- calculate_mean_squared_error(dati, samplesizes[i], 100)
}
plot(mean_squared_error ~ samplesizes)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment