# Binary Logistic Regression with both dependent and independent variables

I have a dataset that has a binary dependent variable (choose 1=yes, 2=no) and the reasons given to choose each product. Independent variables include color (1=yes, 2=no), flavor (1=yes, 2=no), etc.

Here is a simplified example. I actually have 10 independent variables and n=500.

color flavor choose
1     0      1
1     1      1
1     0      0


Is it possible to run a binary logistic regression on this dataset? I want to report betas but if possible would like to run Relative Importance of Regressors (R relaimpo package). Any considerations I should have? Is this possible? Should I code the dataset differently?

Thanks!

• If you are interested in any relationship between these variables, a chi-square test would answer this question. It didn't seem clear by your question whether or not you had a clear response variable. What would your outcome variable be for a logistic regression? In other words, if you wanna run a regression, what predictors do you theorize affecting what outcome variable? Commented Jan 3, 2023 at 18:02
• choose is the outcome variable either they choose or not the product, and I'm interested ideally on the relative importance of the independent variables Commented Jan 3, 2023 at 18:07
• Ah sorry I see now you already mentioned that as a dependent variable. Commented Jan 3, 2023 at 18:09
• – Dave
Commented Jan 3, 2023 at 19:08
• Thanks for pointing that out. Commented Jan 4, 2023 at 1:09

Modeling a binary outcome with binary predictors is fairly standard in logistic regression. Here I have tried to simulate the data you refer to in R and fit it to a logistic regression.

#### Create Fake Data ####
set.seed(123)
choose <- rbinom(n=500,size=1,prob=.5)
color <- rbinom(n=500,size=1,prob=.5)
flavor <- rbinom(n=500,size=1,prob=.5)
df <- data.frame(choose,color,flavor)

#### Fit Data ####
fit <- glm(
choose ~ color + flavor,
data = df,
family = binomial
)


If you run summary(fit), you get this readout, which shows you a good amount of information about your model, including the coefficients (which include log odds of each predictor), deviance, AIC, and other info. We can see color has a positive association with the outcome whereas flavor has a negative association:

Call:
glm(formula = choose ~ color + flavor, family = binomial, data = df)

Deviance Residuals:
Min      1Q  Median      3Q     Max
-1.145  -1.131  -1.108   1.224   1.248

Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -0.13261    0.15695  -0.845    0.398
color        0.05582    0.17933   0.311    0.756
flavor      -0.03287    0.17924  -0.183    0.854

(Dispersion parameter for binomial family taken to be 1)

Null deviance: 691.35  on 499  degrees of freedom
Residual deviance: 691.22  on 497  degrees of freedom
AIC: 697.22

Number of Fisher Scoring iterations: 3


Probably one of the more important things to obtain is the exponentiated coefficients, which provides odds ratios which may be more useful for interpretation.

exp(coef(fit))


This gives us the following readout:

(Intercept)       color      flavor
0.8758064   1.0574089   0.9676636


We can see that color = 1 (whatever that may be, we can call it "red" here) is 1.05 times likely to choose yes (this depends on what your reference value is, here I just say it means yes). Flavor = 1 (perhaps "spicy") slightly decreases the odds of choosing yes.

If you are not experienced on logistic regression or using it within R, a great book on this subject is Practical Guide to Logistic Regression by Joseph Hilbe.