# This program bootstraps the ratio of means for the # city data set in the `boot' library. library(boot) set.seed(12345) # Now we define the function which calculates the statistic # ie the ratio of means. The function has two inputs - the dataframe # and a vector of indices defining the bootstrap sample (generated automatically by # the `boot' command). The first command sets up the bootstrapped dataframe. The # second calculates and returns the ratio. city.fun<- function(data,i){ bsample<-data[i,] mean(bsample$x)/mean(bsample$u) } # Now we create bootstrap object using predefined boot command. city.boot<-boot(data=city, statistic=city.fun, R=250) # We can obtain information on the bootstrap object city.boot by typing: # # 1. `city.boot' which prints the original statistic, its estimated se and bias # 2. `plot(city.boot)' which gives summary plots # 3. `names(city.boot)' which lists components of boot. city.boot plot(city.boot) names(city.boot)