# This program bootstraps the median for the mouse data # control group using the `boot' command from the # library `boot' ie boot::boot. library(boot) #load library mouse.c<-c(52,104,146,10,50,31,40,27,46) # Control group data set # Here we define the function which calculates the statistic # ie the median. In the boot library the function must have two inputs - the original data # and a vector of indices defining the bootstrap sample (generated automatically by # the `boot' command). The first command generates the bootstrap sample. The # second calculates and returns the median. mouse.fun<- function(data,i){ d<-data[i] median(d) } # Now we generate the bootstrap results using the boot command # and store them in the bootstrap object `mouse.boot'. mouse.boot<-boot(data=mouse.c, statistic=mouse.fun, R=250) # Now we can obtain information from mouse.boot by typing: # # 1. `mouse.boot' which prints the original statistic, its estimated se and bias # 2. `plot(mouse.boot)' which gives summary plots # 3. `names(mouse.boot)' which lists components of boot. # 4. `boot.array(mouse.boot)' which shows us the resamples actually used as frequencies. # 5. `boot.array(mouse.boot,indices=T) showing resamples as indices.