# S speedup in R

**Bill Simpson
**
wsimpson@uwinnipeg.ca

*Tue, 7 Jul 1998 16:17:51 -0500 (CDT)*

Venables and Ripley describe a speedup where you take a structure like
x<-NULL
for(i in sequence)
y<-c(y,function(x,i))
and convert it to one like
x<-numeric(its length)
for(i in sequence)
y[i]<-function(x,i)
I tried this speedup on some simple examples and it made them twice as
fast.
But now I am hitting a snag with some real code.
This original version works:
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 <- NULL
for(tt in tau)
{
point.counter <- 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 <- c(cif.numerator,point.counter)
}
cif.numerator/(n * h)
}
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)
}
I can't see why this isn't working. Is this hitting a peculiarity of
R? Thanks very much for any help.
Bill Simpson
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._