From bates@stat.wisc.edu  Tue Jul  7 22:49:46 1998
From: bates@stat.wisc.edu (Douglas Bates)
Date: 07 Jul 1998 16:49:46 -0500
Subject: S speedup in R
In-Reply-To: Bill Simpson's message of Tue, 7 Jul 1998 16:17:51 -0500 (CDT)
References: <Pine.OSF.3.95.980707160152.21173A-100000@io.uwinnipeg.ca>
Message-ID: <6r67h9nxfp.fsf@verdi.stat.wisc.edu>

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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


S speedup in R
Douglas Bates