# Frequency of an event at a given time, from a list of times of occurrence

I have data in the following format: [$t_1, t_2, t_3, \dots, t_n$] - which is a list of times at which an event has occurred during a day

They are in minutes within 24 hours and limited by $t_{\text min} == 0, t_\text{max} == 1440$.

What I would like to obtain is a (smooth, if possible) function that takes a given time and returns the frequency of that event, sampled at the given time.

For example, if I have the following list (values represented as HH:MM for simplicity): [05:20, 06:00, 07:40, 08:20, 09:00, 09:10, 09:20, 09:30, 09:40, 09:50, 10:00 (...)]

if I sample my function at t=06:10 I'd like to obtain the frequency of around f(t)=1/40 [1/min] and if I sample at t= 09:45, f(t)=1/10 [1/min] and at t= 09:00, f(t)= something in between (?)

I was wondering what functions should I look at to be able to fit to my data to obtain the desired result.

• I don't think it's a matter of fitting functions unless there is a really simple dependence on time of day that can be modelled as sines and cosines. Rather, density estimation is the name of the game. There's a twist: if you regard times after midnight as following times before midnight, you'll want to ensure that the estimation wraps around. Most programs will require that you work in minutes, not hours and minutes. Jan 23, 2018 at 16:39

I decided to use a weighted average of the time differences between occurrences. The weight is the distance (in time) from the sampled point.

• Do you mean the weight is the inverse of time from the sampled point? Jan 24, 2018 at 18:05
• No, the distance between the point of sampling and a given occurrence. I give detail ed explanation in this paper link.springer.com/chapter/10.1007%2F978-3-030-03424-5_18 but it's basically so that the closer a given occurence is (in time), the more relevant it is for the frequency sampled at a given point Jan 9, 2019 at 15:57
• Looks like it's just a a moving average with exponential weight function. Seems reasonable. Jan 9, 2019 at 16:23

Use a boxcar filter. The problem with survival methods is that they estimate hazards which have to be transformed to risks and, at times, rely on parametric assumptions. Since you have no censoring in these data, the mean is an unbiased estimator of the counting process. The boxcar filter provides a nonparametric moving average of the frequency of events at each time and is a nice descriptive statistic.

An example of my superinefficient approach:

data(cancer)
window <- 10
time <- sort(unique(cancer$time)) freqs <- colSums(abs(outer(time, time, -)) < window) val <- data.frame(n=freqs, t=time, t0=pmax(time - window/2, 0), t1=time+window/2) val$t1 <- pmin(val$t1, c(val$t[-1], Inf))
plot(val$t1, val$n, type='s', xlab='time', ylab='Number of events in 10 day window')


• "Box-Car" better as "boxcar" to reduce the risk of someone attributing yet another thing to George E.P. Box and/or inventing a mythical collaborator Car. (According to legend, "B. Chir" has multiple publications in various data bases given the number of surgeons who put their degrees after their names.) Jan 24, 2018 at 17:59