# Logistic regression with binary inputs

Is logistic regression an appropriate classifier when the input data are binary? Say we are conducting an experiment where the subject is presented with blue and green circles of varying shades, and asked to pick the blue one in each trial. We have 10 controls and 10 cases who are presumed to be blue-green color blind. Each subject is presented with 30 trials.We record the data in a matrix like this:

[[1 1 0 1 0 0 1 1 0 1 1 0 1 1 0 0 1 1 1 1 1 1 0 1 1 1 1 1 1 1]
[1 1 1 1 0 1 1 0 0 0 1 0 1 0 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1]
[1 1 0 0 1 1 1 1 1 1 0 1 1 0 1 0 0 1 1 1 1 1 1 0 1 1 1 1 0 1]
[1 1 0 1 1 0 1 1 0 0 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1]
[1 0 1 1 1 0 1 0 1 1 1 1 1 1 0 1 0 1 1 1 1 1 1 1 1 1 1 0 1 1]
[1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1]
[1 1 1 0 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1]
[1 1 1 1 1 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]
[1 1 1 0 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]
[0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0]
[0 0 0 0 0 1 0 1 1 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 1 0 0 1 0 1]
[0 0 0 0 0 0 0 1 1 0 0 0 1 0 1 0 0 0 0 1 0 1 0 0 0 0 0 1 0 1]
[1 0 1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 1 0 1 0 1 0 0 1 0 0 0 0 1]
[0 1 0 1 0 0 0 0 1 1 0 0 1 1 0 0 0 0 0 1 0 0 1 1 1 0 0 0 1 1]
[0 0 1 0 0 0 1 1 0 1 1 0 1 1 0 0 0 0 0 1 0 0 1 1 0 1 0 0 1 0]
[0 0 1 0 1 1 1 0 0 0 1 0 1 1 1 1 1 0 0 0 1 1 1 0 1 1 0 0 0 1]
[0 1 0 0 1 1 1 1 0 1 0 1 0 1 1 0 0 0 0 1 1 1 1 0 1 0 0 1 1 1]
[0 0 1 0 1 0 1 0 0 1 1 1 1 1 1 1 0 1 1 0 0 1 1 1 1 1 0 0 1 1]
[1 1 1 1 1 1 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1]]


The first 10 rows record the data for the controls, the last 10 are for the cases. From these data we can calculate mean and standard deviation of the success rate for each subject, and we can calculate the effect size between the two groups. Given that we have a "large" effect size, we would expect to see high specificity and sensitivity in a binary classifier for "color blind" vs "not color blind."

Is logistic regression an appropriate classifier in this case? What should the exogenous variables be? Should I use the mean of the 1's and 0's for each subject? Should I use all 30 "features" as my exogenous variables?

If the input data are in random order, i.e., exogenous variables are not actually tied to a "feature" per se they are just a sequence of trials, can I still treat the trials as features and expect the logit to minimize the trial(s) that are less informative?

In this answer it seems that a Chi-square test may be an alternative to logit, but it's not clear how that would work.

I have implemented this classifier in Python using both statsmodel and sklearn. The statsmodel library is unable to converge when I use all 30 features, presumably because issues arise from multicollinearity.

Edit: I wrote a naive Bayesian classifier based on this procedure, and it works quite well. It gives 75% classification accuracy, which is about what I expected based on the 1.4 effect size between my two groups. Is this the best approach, or at least a reasonable one?

• (1) binary inputs aren't an issue with any glm including logistic regression (2) the issue is non-independence of observations (iid) (3) do you really have 30 features or just 1? (seems like 1 to me) – charles Mar 21 '14 at 22:52