Best way to test for co-occurrence of measures I have some data with temporal measures over time. I'd like to test whether two binary variables co-occur more often than chance would predict, and I'm wondering the best (simple) way to do that.
The data looks something like
Time   UID    Variable1    Variable2
1      1      1            0
2      1      1            1
...
1      2      0            0
2      2      0            1
...

I'm wondering what the best way is to control for the fact that these are repeated measures within the same individuals.
I started with just a chi-squared test of the counts of when the variables co-occurred.
 A: I would suggest that you use resampling. Consider the hypothesis that for a given subject the values of $ {\tt Variable1} $ and ${\tt Variable2}$ are realizations of two independent random variables. A test statistic for this is the number of observations where the variables have the same value. Both large and small values are critical for the hypothesis using this statistic.
Now one can use resampling with replacement to estimate the distribution of the statistic under the hypothesis. Of course, we will have to take into account that we are dealing with repeated measures. Say we have $n$ subjects and $m$ observations for each subject. We can now resample (with replacement) from the $n$ vectors of ${\tt Variable2}$ values and make a new data set combining the original ${\tt Variable1}$ and the resampled ${\tt Variable2}$. Thus, we are combining subjects with new sets of ${\tt Variable 2}$ values, calculating the test statistic and thereby simulating the distribution of the test statistic under the hypothesis. By not breaking up ${\tt Variable2}$ values of each subject we acknowledge that there might be some structure corresponding to the repeated measuring. For instance, we could speculate if some individuals get a lot of 1's at every time point.
We can now calculate the test statistic of the original data and get a p-value by comparing this number to the estimated distribution. Remember that both small and large values are critical.
Of course, there's no guarantee that this method will be very efficient. I did a (very) small simulation study in which it fared fairly well. You can play around with it yourself. Naturally, if one wants to study the method by simulation it is necessary to make some assumptions in order to generate new data for which you know whether or not the hypothesis is true.
A: You could use conditional logistic regression.  That would answer if, within each subject, on average, if Variable1 is associated with Variable2.  This will only work if you have enough subjects who have concordant Variable1 and Variable2 measurements.  In R,
 library(survival)
 clogit(Variable1 ~ Variable2 + strata(UID))

Note that this only accounts for the correlation within subjects, not the correlation between time points, within subjects.  I think you're going to be stuck using a mixed model if you need to model the correlation across time, within subject.
