[R] about library(boot)

John Fox jfox at mcmaster.ca
Wed Feb 16 23:07:23 CET 2005


Dear Francisca,

On Wed, 16 Feb 2005 11:28:24 -0500
 "Francisca xuan" <fxx103 at hotmail.com> wrote:
> Dear Sir/Madam:
> 
> I try to use the library boot to bootstrap the median of a data set.
> Can anybody tell me why this doesn't work? Thanks.
> 
> library(boot)
> x=rnorm(100)
> boot(x,median,999)
> 
> I know I can write a simple code for bootstrapping myself. but I am
> so curious to know why the above code does not work.

Take a closer look at ?boot: The function that computes the statistic
that you're bootstrapping (in a simple situation like this) should take
two arguments -- the data and an index vector. Thus,

boot.median <- function(x, i) median(x[i])
result <- boot(x, boot.median, 999)

I hope this helps,
 John




More information about the R-help mailing list