[R] how to create a 95 percent confidence interval using the diference of the mean using Bootstrap

Rui Barradas ruipbarradas at sapo.pt
Thu Nov 15 23:48:16 CET 2012


Hello,

Try the following.

?boot::boot
x <- scan(text="
  4 69 87 35 39 79 31 79 65 95 68 62 70 80 84 79 66 75 59 77 36 86 39
85 74 72 69 85 85 72")

y <- scan(text="
62 80 82 83  0 81 28 69 48 90 63 77  0 55 83 85 54 72 58 68 88 83 78
30 58 45 78 64 87 65")

diffmeans <- function(x, i) mean(x[i, 1] - x[i, 2])

res <- boot::boot(cbind(x, y), diffmeans, R = 1000)
quantile(res$t, probs = c(0.025, 0.975))  # CI
res$t0  # estimate

Hope this helps,

Rui Barradas

Em 15-11-2012 19:52, Tania Patiño escreveu:
> Hello all, could you please tell me how to create a 95 percent confidence
> interval using R, if I have the next data:
>
>> blue
>   [1]  4 69 87 35 39 79 31 79 65 95 68 62 70 80 84 79 66 75 59 77 36 86 39
> 85 74
> [26] 72 69 85 85 72
>
>> red
>   [1] 62 80 82 83  0 81 28 69 48 90 63 77  0 55 83 85 54 72 58 68 88 83 78
> 30 58
> [26] 45 78 64 87 65
>
> Build a confidence interval of 95 % for the difference of the medias using
> BOOTSTRAP.
>
> Thank you,
>
> Fjaril
>
> 	[[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.




More information about the R-help mailing list