I have a data set in which the response variable ("Binary_Response") is binary.

The explanatory variables I am hoping to include with my model are categorical and also binary ("Stimulus_Order" & "Stimulus_Type").

I have made repeated measurements of individuals' sequential responses to two stimuli (A, B) five times each (AAAAABBBBB or BBBBBAAAAA). Sometimes I presented A first; sometimes B first ("Stimulus_Order"=1 if first). Their likelihood to produce a "1" in the response variable typically decays with time, but individuals vary in the rate of decay and some may rarely exhibit the opposite pattern.

'data.frame':   310 obs. of  6 variables:
$ Individual           : int  1 1 1 1 1 1 1 1 1 1 ...                   
$ Stimulus_Number      : int  1 2 3 4 5 6 7 8 9 10 ...
$ Stimulus_Order       : Factor w/ 2 levels "1","2": 1 1 1 1 1 2 2 2 2 2 ...
$ Stimulus_Type        : Factor w/ 2 levels "A","B": 1 1 1 1 1 2 2 2 2 2 ...
$ Binary_Response      : Factor w/ 2 levels "0","1": 2 2 1 1 1 2 2 2 1 1 ...
$ Stim_Order_Type_Combo: Factor w/ 4 levels "A1","A2","B1",..: 1 1 1 1 1 4 4 4 4 4 ...

My questions are:

  1. Is binary logistic regression suitable for determining whether and how strongly "Stimulus_Order" or "Stimulus_Type" are affecting "Binary_Response"?
  2. If so, how do you encode the repeated measures aspect of this problem into the model to ensure the model doesn't treat each data point as independent?

Ultimately, I'd like to show that the presentation order of the stimuli didn't influence the "Binary_Response" for both stimuli. Based on that (if true) I'd like to lump the data and ignore "Stimuli_Order". Then I'd like to show that "Stimuli_Type"=A had a higher probability of exhibiting "Binary_Response"=1 and that it also maintained a higher probability throughout sequential trials (lower decay rate). If there is a method that can do that in one step, that'd be great. I've only just entered the world of these crazy general/ized linear models.

Any answers or suitable references/examples would be much appreciated. Maybe suitable references more so, as I've got a lot to learn! I haven't found any examples of glm's dealing with binary response and explanatory variables with repeated measures.

Data are provided here. "Stimulus_Order" and "Binary_Response" should be factors.

  • $\begingroup$ If you want to examine the decay within a run of either 5 As or 5 Bs in a row, it might be better to recode your "Stimulus_Number" slightly, so that the range 1...5 represents the order within a particular run of As or Bs regardless of whether the As or Bs were presented first. Since you also have your "Stimulus_Order" factor, you don't lose any information but that will allow a straightforward interpretation of changes in response with Stimulus_Number within a set of As or Bs. $\endgroup$
    – EdM
    Jun 10, 2015 at 14:41
  • 1
    $\begingroup$ This page has examples of repeated-measures/mixed-effects situations with binary outcomes. $\endgroup$
    – EdM
    Jun 10, 2015 at 15:02

1 Answer 1


One option is using crossed random effects for a logistic GLMM. Basically you set up random effects for your repeated measures (here Individual and Stimulus_Number), effectively expanding the data frame by observations by each. I have linked a very readable paper (Baayen et al., 2008) below on what a crossed effects design looks like, authored by a researcher who does a lot of linguistic research and another who created the lme4 package in R. It would of course be very helpful to read more about GLMMs if you don't already know much about them, and I have cited another excellent paper that gives a brief summary of them (Harrison et al., 2018). Further reading would be essential as it is a complicated topic.


Baayen et al., 2008

Harrison et al., 2018


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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