How to determine if the occurrence of two events is temporally connected?

I'm working on a dataset where I have dates as the main unit of analysis. I'm trying to see if two events are related; that is, if the first event happens, will the second event happen within a month of the first event?

I have the dates for both, but I'm kind of at a loss for how to proceed. I thought I should be using logistic regression because the variables (outcomes) are binary: either the second event happened within a month of the first event, or it didn't. Should I? How do I make this month-long envelope after the first event? Am I totally on the wrong track?

• This is not a specific programming question. If you need help choosing an appropriate statistical method for your specific data and hypothesis, consider posting to Cross Validated instead. If this is in fact a coding question,include a reproducible example with sample input and desired output. Commented Feb 23, 2015 at 19:08
• Actually sounds more like survival analysis. It takes timing into account.
– DWin
Commented Feb 23, 2015 at 19:19
• Have you looked at the distribution (histogram, density plot) of the length of time between event A and event B? Commented Feb 23, 2015 at 22:47

I don't think logistic regression is a good option for you as you have described your study question. You state that your substantive question is:

if the first event happens, will the second event happen within a month of the first event.

The probability of the second event happening within a month of the first event can certainly be calculated, and you could run a binomial test, but what is the appropriate probability for your null hypothesis? You could divide the total number of second events by the total number of months in your observation period, but that still leaves something to be desired. Moreover, you are throwing a lot of information away by doing this. (For example, what about second events that occur 32 days after the first event?)

I think you would be better off using a survival analysis based approach. You could count the number of days from a given first event until a second event (or the end of your study period). Then you could get a survival curve, and perhaps a median survival with a confidence interval. It strikes me as likely to be a lot more useful to know if the median duration is close enough for your purposes.

I think logistic regression is a reasonable approach to answer your question, assuming that a binary question of "did/didn't the event happen within one month" is the right way to think about it. If there are more complicated temporal dynamics involved, then some sort of survival analysis probably more appropriate.

But there's value in simplicity, and results of the approach you describe will be easy to communicate to a non-technical audience. To do the logistic regression you're talking about, your outcome will be a simple yes/no, and each date will have an associated "precipitating event occurred" value that is also yes/no. So for example

d3 = data.frame(EventOccurred = rep(c(1,0,1),50),
OccurredLastMonth = rep(c(1,0,0),50))