Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR R

how to bootstrap in r

# Import libaries
library(boot)

# Create sample dataframe
set.seed(1)
x <- rnorm(1000, sd=10)
y <- rnorm(1000, sd=1)
df <- data.frame(x,y)

# Create function to pass to boot()
calc_mean = function(data, index){
  mean_x <- mean(df$x[index]) 
  return(mean_x)
}

boot(df$x, calc_mean, R=1000)
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #bootstrap
ADD COMMENT
Topic
Name
2+5 =