Hi Erika,
the bootstrap is more of a tool to assess variability and create
confidence intervals, and people like me prefer permutation tests for
testing hypotheses, perhaps something like this:
###############################################
sample1 <- rnorm(20)
sample2 <- rnorm(20)
n.perms <- 1000
xx <- rep(NA, n.perms)
for ( ii in 1:n.perms ) {
sample.perm <- sample(c(sample1,sample2),replace=FALSE)
xx[ii] <-
mean(sample.perm[1:length(sample1)])-mean(sample.perm[(length(sample1)+1):length(sample.perm)])
}
cat("p =",1-ecdf(xx)(mean(sample1)-mean(sample2)),"\n")
###############################################
Nevertheless, you can do significance testing with the bootstrap. Create
a confidence interval for your difference in sampled means using
quantile(x,probs=c(0.025,0.975)) and check whether your observed
difference lies outside it. Or directly use the ecdf(). The bootstrap
has low power for very small samples, but n=20 per group should be quite
enough here.
Readable introductions are:
Good, P. I. Permutation, Parametric, and Bootstrap Tests of Hypotheses.
Springer, 2005
Good, P. I. Resampling Methods. Birkh?user, 2006
HTH,
Stephan
Erika Ahl schrieb:> Dear List Members,
>
> I have two small samples (n=20), the distributions are highly skewed. Does
> it make any sense to do a boostrap test to check for difference in means?
> And if so, could this be done like this:
>
> x <- numeric(10000)
>
> for(i in 1:10000) {
>
> x[i] <- mean(sample(sample1,replace=TRUE)) -
> mean(sample(sample2,replace=TRUE))
>
> }
>
> (mean(sample1)-mean(sample2))/sd(x)
>
> Regards,
>
> Erika
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at 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.
>