[R] Irregular time series
Peter Dalgaard BSA
p.dalgaard at biostat.ku.dk
Tue Jan 28 12:26:03 CET 2003
Damon Wischik <djw1005 at cam.ac.uk> writes:
>
> My dataset represents a point arrival process, not a sample of a
> continuous process; I want to turn the continuous-time point arrival
> process into a discrete-time point arrival process. I am looking for a
> function which has the same effect as, but is faster than, this:
>
> > its.to.ts <- function(times,values,delta=1) {
> > m <- min(times)
> > M <- max(times)
> > mm <- delta*floor(m/delta)
> > MM <- delta*ceiling(M/delta)
> > cuts <- seq(from=mm,to=MM,by=delta)
> > nullvals <- rep(0,length(cuts)-1)
> > nulltimes <- cuts[-1]-delta/2
> > time.factor <- cut(c(times,nulltimes),cuts,labels=FALSE)
> > dd <- aggregate(c(values,nullvals),by=list(time=time.factor),sum)
> > ts(data=dd$x,start=mm,deltat=delta)
> > }
Hmmm. I'm not going to dig into your code just now, but suppose you used
something like
diff(approx(times,cumsum(values),xout=cuts, method="constant"))
There are probably some end effects that you need to consider more
carefully.
--
O__ ---- Peter Dalgaard Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics 2200 Cph. N
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
More information about the R-help
mailing list