I am analysing a weather data for a computer science course using hadoop.I am taking away all the weather related issues out of the analysing and just looking strictly at it in the eyes of statistics.

Lets say there are 2 events, 1 occurs 250 times in the year, and the other event occurs 50 times in a year. The second event occurs every single day the first event occurred. Can I say that there is a relationship between the two events? I am not sure if it is safe to say there is a good chance there is a relationship between the data because this could just be a coincidence. For example if the event A occurred 25 times a year and event B occurred 15 times again event B occurring every time event A occurred I would be more confident to say there is a relationship between the two events because there is less of a chance it is a coincidence due the the number of times event A occurred. To rephrase, lets say event A occurred 365 times in the year and event B occurred 10 times in the year, event B would occur every single time event A occurred, but this is just because event A occurred every day so there is no relationship. Is there some sort of standard to say that when two events have a statistically high probability of having a relationship of some sort?

he dataset will check for relationships in the short term and longterm (check to see if there is a relationship recently say in the last 3 months, 1 year, but also longer 4 years, 8 years, 10 years). I know for 10+ years, I can probably rely that if events occurred always together there is probably a good chance of a relationship because of the vast time, but for shorter ranges, is there some sort of method?

Hope this makes sense.


In respect of a single day, day $i$, consider the four compound events:

1) A occurred and B occurred.
2) A occurred and B did not.
3) A didn't occur and B did.
4) Neither A nor B occurred.

For each day, one of those four situations occurs.

Knowledge of all four can be used to decide whether the occurrence of A and B are dependent (either positively related or negatively).

To clarify notation, let $X_i=1$ if $A$ occurs on day $i$ and $=0$ otherwise. Let $Y_i=1$ if $B$ occurs on day $i$ and $=0$ otherwise.

If we further assume that there's independence across days -- that $P(X_i=1|X_j=1)=P(X_i|X_j=0)$ for all $j\neq i$, and similarly for conditioning on $Y_j$ and for conditioning on combinations of $X_j$ and $Y_k$.$^\dagger$

In that case we can use a test for independence. The most commonly used one is the chi-squared test, though I mention some other possibilities later.

Let $Z_{lm}(i)=1$ if $X_i=l$ and $Y_i=m$ for $l=(0,1)$ and $m=(0,1)$.

That is, let $Z_{00}(i)=1$ if $X_i=0$ and $Y_i=0$, and so on.

Further, let $O(l,m) = \sum_i Z_{lm}(i)$, so that the $O$ values represent the counts of how often each combination of A or not-A co-occurs with B or not-B

Then construct a contingency table:

               (not-B)    (B)
                 Y=0      Y=1     
(not-A) X=0     O(0,0)  O(0,1)
  (A)   X=1     O(1,0)  O(1,1)

Then this data is in suitable form for a chi-square, or a G-test or a Fisher-Irwin test (of which the chi-square is the best-known). An alternative would be a two-sample proportions test (say as a Z-test).

$\dagger$ [This may be too strong an assumption, in which case some alternative analysis that deal with the time dependence needs to be used]

1 occurs 250 times in the year, and the other event occurs 50 times in a year. The second event occurs every single day the first event occurred. Can I say that there is a relationship between the two events?

Let's cast this in the above framework. Given a 365 day year, it's possible to work out every combination from that information (it takes a little thinking but you can get there):

                (not-B)   (B)       Tot
                 Y=0      Y=1     
(not-A) X=0      115        0       115
  (A)   X=1      200       50       250

Tot.             315       50       365

This yields a chi-square of around 25.0 or 26.7 depending on whether a continuity correction is applied, which (unless you had chosen an incredibly small significance level to start with) would lead to rejection of the null of no association between occurrence of A and occurrence of B.

In cases where your expected values in some cell or cells may be small (on the order of 1 or 2, say), Yates' continuity correction can help somewhat with improving the chi-square approximation.

[In your example where A and B only occur 15 times together and A only occurs 25 times, the expecteds might be a bit too small to apply the chi-square approximation.]


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.