# S speedup in R

**Douglas Bates
**
bates@stat.wisc.edu

*07 Jul 1998 16:49:46 -0500*

Bill Simpson <wsimpson@uwinnipeg.ca> writes:
...
>* But the sped-up version just returns a vector of zeros:
*>*
*>* cif<-function(x, y, tau, h=tau[2]-tau[1])
*>* {
*>* # conditional cross-intensity function for two point process realizations.
*>* # estimated at tau.
*>* # x and y are vectors of event times (sorting is not necessary).
*>* # tau is the lag (or vector of lags)
*>* # h is binwidth.
*>* # see Brillinger, Bryant, & Segundo (1976) eq 13, mhatAB(u)
*>* n <- length(x)
*>* cif.numerator <- numeric(length(tau))
*>* for(tt in tau)
*>* {
*>* cif.numerator[tt] <- sum(round(rank(c(x + tt + h/2, y))[1:n], 0) -
*>* round(rank(c(x + tt - h/2, y))[1:n], 0))
*>* }
*>* cif.numerator/(n * h)
*>* }
*
You are using tt for an index in addition to being the value of an
element of the tau vector. Unless tau always happens to be
1:length(tau) that won't work.
You probably want to change the "for" statement to
for (tt in seq( along = tau ) )
{
cif.numerator[tt] <- sum(round(rank(c(x + tau[tt] + h/2, y))[1:n], 0) -
round(rank(c(x + tau[tt] - h/2, y))[1:n], 0))
}
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._