Re: [R] Speed up code with for() loop

From: hck <>
Date: Fri, 29 Apr 2011 13:20:15 -0700 (PDT)

Barth sent me a very good code and I modified it a bit. Have a look:

Error<-rnorm(10000000, mean=0, sd=0.05)

DCF_korrigiert<-(1/(exp(1/(exp(0.5*(-estimate)^2/(0.05^2))*sqrt(2*pi/(0.05^2 ))*(1-pnorm(0,((-estimate)/(0.05^2)),sqrt(1/(0.05^2))))))-1)) DCF_verzerrt<-(1/(exp(estimate)-1))

S <- 10000000                                   # total sample size
D <- 10000                                      # number of subsamples
Subset <- 10000                                  # number in each subsample
Select <- matrix(sample(S,D*Subset,replace=TRUE),nrow=Subset,ncol=D)

DCF_korrigiert_select <- matrix(DCF_korrigiert[Select],nrow=Subset,ncol=D) Delta_ln <-(log(colMeans(DCF_korrigiert_select, na.rm=T)/(1/0.10)))

The only problem I discovered is that R cannot handle more than 2.147.483.647 integers, thus the cells in the matrix are bounded by this condition. (R shows the max by typing: .Machine$integer.max). And if you want to safe the workspace, the file with 10.000 times 10.000 becomes round 2 GB. Compared to the original of "just" 300 MB.

So I cannot perform my previous bootstrap with 1.000.000 times 100.000. But nevertheless 10.000 times 10.000 seems to be sufficiently; I have to say its amazing, how fast the idea works.

Has anybody a suggestion how to make it work for the 1.000.000 times 100.000 bootstrap???

View this message in context:
Sent from the R help mailing list archive at

______________________________________________ mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.
Received on Fri 29 Apr 2011 - 20:26:10 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 29 Apr 2011 - 20:30:38 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive