Hi:

Does this work?

df <- data.frame(x = rnorm(49, mean = 1), y = rnorm(49, mean = 2))

# Generate matrix of bootstrap indices
idx <- matrix(sample(1:nrow(df), 50 * nrow(df), replace = TRUE),
          nrow = nrow(df))
dim(idx)
# [1] 49 50

# Generate the corresponding x, y, bootstrap samples by using
# matrix indexing by mapping the x and y values to the indices in
# the idx matrix
xboot <- matrix(df$x[idx], nrow = nrow(df))
yboot <- matrix(df$y[idx], nrow = nrow(df))

# Find respective x, y means from bootstrap samples
xmean.boot <- colMeans(xboot)
ymean.boot <- colMeans(yboot)

# Take the ratio of the means
xyratio.boot <- ymean.boot/xmean.boot

# Now, get bootstrap samples of paired differences
diffboot <- yboot - xboot

# Mean differences
diffmean.boot <- colMeans(diffboot)

The distribution of the ratio of means is right skewed, whereas the
distribution of the
mean differences looks approximately normal (as one would expect).

Look ma, no [explicit] loops :)  More seriously, behold and appreciate the
power of R's (and S's)
indexing capabilities.

HTH,
Dennis

On Wed, Jan 6, 2010 at 9:42 AM, luciferyan <anniehyhung@googlemail.com>wrote:

>
> I have a similar question.
> I want to generate list of 50 bootstrap samples,
> it can be done by:
>
>
> lapply(1:50,function(i){data[sample(nrow(data),size=nrow(data),replace=TRUE),]})
>
> >From these  bootstrap samples, I want to work out the Bootstrap estimates,
> which is E[y]/E[x].
> How can I do it?
>
> '>> data<-data.frame(x=rnorm(49), y=rnorm(49))
> >>
> t(sapply(1:50,function(i){colMeans(data[sample(nrow(data),size=nrow(data),replace=TRUE),])}))'
> These codes will generate mean of column x and mean of column y.
> Is y the corresponding of x? because x and y are pair data.
>
> Thank you.
> --
> View this message in context:
> http://n4.nabble.com/bootstrap-help-tp949807p1008227.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

	[[alternative HTML version deleted]]

