I have some toy data for an experiment where subjects are shown pictures A,B and C and then they are given a choice between choice A or choice B. I am interested in determining the effect of the pictures on the response.
I am running a logistic regression to see how the pictures increase or decrease the liklihood of choose A or B. Here choosing A is coded 1 and choosing B is coded 0.
Here is some toy data for 100 subjects and the output of the logistic regression:
> set.seed(666)
> choice = sample(c(1,0),100, TRUE)
> sex = sample(c("M","F"),100,TRUE)
> picture = sample(c("A","B","C"),100,TRUE)
> data = data.frame(choice = choice, sex = sex, picture = picture)
> s=summary(glm(data = data, choice ~ factor(sex) + factor(picture), family = binomial(link = logit) ))
> s
Call:
glm(formula = choice ~ factor(sex) + factor(picture), family = binomial(link = logit),
data = data)
Deviance Residuals:
Min 1Q Median 3Q Max
-1.2957 -1.1216 -0.8907 1.1685 1.4943
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 0.1200 0.4133 0.290 0.7716
factor(sex)M 0.1539 0.4186 0.368 0.7132
factor(picture)B -0.2527 0.5191 -0.487 0.6264
factor(picture)C -0.8399 0.4962 -1.693 0.0905 .
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
(Dispersion parameter for binomial family taken to be 1)
Null deviance: 137.63 on 99 degrees of freedom
Residual deviance: 134.51 on 96 degrees of freedom
AIC: 142.51
Number of Fisher Scoring iterations: 4
> c = coef(s)
> log_odds_ratio = c[,c("Estimate")] # log odds ratio
> log_odds_ratio
(Intercept) factor(sex)M factor(picture)B factor(picture)C
0.1199990 0.1538543 -0.2527420 -0.8398664
> odds_ratio = exp(log_odds_ratio)
> odds_ratio
(Intercept) factor(sex)M factor(picture)B factor(picture)C
1.1274957 1.1663209 0.7766682 0.4317682
> probability = odds_ratio/(1+odds_ratio)
> probability
(Intercept) factor(sex)M factor(picture)B factor(picture)C
0.5299638 0.5383879 0.4371487 0.3015629
The coefficients reported are in log odds so I take the exponential of the coef vector to make the odds_ratio vector.
My question is on interpretation of the picture B and picture C odds ratios:
0.7766682 0.4317682
I am interpreting 0.7766682 that seeing picture B will increase the odds ratio of choosing A (i.e. response=1) 0.7766682 MORE than picture A. Is that correct?
I then calculate the probabilities using the odds ratios above.
probability
(Intercept) factor(sex)M factor(picture)B factor(picture)C
0.5299638 0.5383879 0.4371487 0.3015629
How should one interpret these probabilities? Picture B has a .437 probability of what?
Finally, how would you graphically show the different effects of the 3 pictures so interpretation can be understood for a non-statistician audience?
Would you plot the regression lines?Using log odds Betas or exp(Betas)? If so can you give an example plot?
Thank you very much
glm
the argumentfamily = binomial(link = logit)
to get logistic regression. The default is linear regression. $\endgroup$