[R] calculating time interval distributions

Bert Gunter gunter.berton at gene.com
Wed Nov 16 16:20:09 CET 2011


Your question seems rather poorly specified to me, and you may have to
clarify it further, but I'll make a stab at it.

IF one can assume that:

1. "a" must occur before "b", "b" before "c" etc.   AND
2. "sec" is always increasing

THEN

z <- tapply(sec, ind, FUN = min)

gives the first appearance sec value for each letter and

outer(z,z,"-")

gives the matrix of differences (in which the upper triangle is the
negative of the lower)

Is that what you wanted?

-- Bert

On Wed, Nov 16, 2011 at 6:00 AM, Grant Gillis <grant.j.gillis at gmail.com> wrote:
> Dear List,
>
> I have data on a approximately 100 individuals visiting a a central logging
> station over a 1000 times.  I would like to be able to calculate the
> distribution of inter-visit time intervals for all possible pairs am stuck
> on how to code for this.  Single pairs are not a problem but extending it
> has been difficult for me.  So for the toy data below I'd like to calculate
> for each 'a' how long until I see 'b' as well as for each 'b', how long
> until I see 'a' and so on for all possible pairs (2 triangle of a matrix?)
>
> Thanks for any help, hints, and suggestions.
>
> Grant
>
>
> toy data:
>
> ind <-  c('a', 'b', 'a', 'c', 'b', 'b', 'c', 'a', 'c')
>
>
> sec <- c(1, 3, 5, 6, 12, 22, 66, 85, 99)
>
> What I am looking for
>
> ab
> 2
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm



More information about the R-help mailing list