Dear R users,

Would you plz tell me how to avoid this "for" loop blow??

I think there might be a better way to reduce running time.

----------------------------------------------------------------------------------------------
## y1 and y2 are n*1 vectors

        for (k in 1:n){
                ymax <- max( y1[k], y2[k] )
               
                i <- 0:ymax

                sums<- -lgamma(y1[k]-i+1)-lgamma(i+1)-lgamma(y2[k]-i+1)

                maxsums <- max(sums)

                sums <- sums - maxsums

                lsum <- log( sum(exp(sums)) ) + maxsums

                logbp[k] <- y1[k]  + y2[k]  + lsum
        }

------------------------------------------------------------------------------------

Any suggestion will be greatly appreciated.

Regards,

Kathryn Lord 

--
View this message in context: 
http://r.789695.n4.nabble.com/efficient-way-to-reduce-running-time-tp3711985p3711985.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help@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.

Reply via email to