# [R] bootstrapping vectors of unequal length

From: Matt Oliver <matt.j.oliver_at_gmail.com>
Date: Sat 21 May 2005 - 05:46:56 EST

I have a vector of n and a vector of n-1 and I want to use boot() to bootstrap the ratio of their respective medians. I want to eventually use boot.ci() to generate confidence intervals. Because the vectors are not equal in length, I tried a few things, but have yet to be successful.

Try 1:

> x <- runif(20)
>
> y <- c(runif(19), NA)
>
> median(x)

 0.522284
>
> median(y[1:19])

 0.488046
>
> median(x)/median((y)[1:19])

 1.070153
>
> t <- as.data.frame(cbind(x, y))
>
> ratio <- function(t, i) median(t\$x[i])/median((t\$y[1:19])[i])
>
> boot(t, ratio, R = 1000)

ORDINARY NONPARAMETRIC BOOTSTRAP Call:
boot(data = t, statistic = ratio, R = 1000)

Bootstrap Statistics :

I thought this might be successful because median(x)/median((y)[1:19]) gives a result, and not an NA.

I also tried to use a regular list (even though boot() technically doesn't accept them) so I didn't have to use NA.

Try 2:

> x <- runif(20)
>
> y <- runif(19)
>
> median(x)

 0.732906
>
> median(y)

 0.5596225
>
> median(x)/median(y)

 1.309644
>
> t <- list(x = x, y = y)
>
> ratio <- function(t, i) median(t\$x[i])/median(t\$y[i])
>
> boot(t, ratio, R = 1000)

ORDINARY NONPARAMETRIC BOOTSTRAP Call:
boot(data = t, statistic = ratio, R = 1000)

Bootstrap Statistics :

At first glance this seemed to work, but median(x)/median(y) is not equal to the "original" in the Bootstrap Statistics (which is a bit odd to me, but it may be because boot() doesn't accept this kind of list.)

Is there a way to do this type of bootstrap with the boot() function?