talking R

October 28th, 2007

Based on this post in Andrew Gelman’s blog, which I read religiously, I wrote a little R template for the bootstrap procedure. Well, the template is simple, but the cool thing is that it tells you when it is finished, so you can stop going back and forth to the R window to check whether it’s done. This one is fast, but for a long, slow procedure, that’s pretty cool. Alas, only works on a Mac (and perhaps Linux?).

x <- rnorm(100,3,2)

bs <- NULL
for (i in 1:1000)
{
bs.sample <- sample(x, length(x), replace=T)
bs[i] <- mean(bs.sample)
}
system(sprintf("say The bootstrap has finished. The result is a mean of %4.2f, with standard error %4.2f. You can access the result with the b s variable.", mean(bs), sd(bs)))

Entry Filed under: programming, R, statistics

Leave a Comment

You must be logged in to post a comment.

Trackback this post  |  Subscribe to the comments via RSS Feed


Calendar

October 2007
M T W T F S S
« Sep   Nov »
1234567
891011121314
15161718192021
22232425262728
293031  

Most Recent Posts