[R] efficient way to reduce running time
Kathie
kathryn.lord2000 at gmail.com
Tue Aug 2 13:05:59 CEST 2011
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.
More information about the R-help
mailing list