I’m wondering if this is an X-Y problem. (A request to do X when the real 
problem should be doing Y. ) You haven’t explained the goals in natural or 
mathematical language which is leaving me to wonder why you are doing either 
sampling or replication (much less doing both within each iteration in the the 
function given to boot. )

— 
David

Sent from my iPhone

> On Dec 19, 2021, at 3:50 AM, varin sacha via R-help <r-help@r-project.org> 
> wrote:
> 
> Dear R-experts,
> 
> Here below my R code working but really really slowly ! I need 2 hours with 
> my computer to finally get an answer ! Is there a way to improve my R code to 
> speed it up ? At least to win 1 hour ;=)
> 
> Many thanks
> 
> ########################################################
> library(boot)
> 
> s<- sample(178:798, 100000, replace=TRUE)
> mean(s)
> 
> N <- 1000
> out <- replicate(N, {
> a<- sample(s,size=5)
> mean(a)
> dat<-data.frame(a)
> 
> med<-function(d,i) {
> temp<-d[i,]
> f<-mean(temp)
> g<-var(replicate(50,mean(sample(temp,replace=T))))
> return(c(f,g))
> 
> }
> 
>   boot.out <- boot(data = dat, statistic = med, R = 10000)
>   boot.ci(boot.out, type = "stud")$stud[, 4:5]
> })
> mean(out[1,] < mean(s) & mean(s) < out[2,]) 
> ########################################################
> 
> ______________________________________________
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

Reply via email to