# Understanding / plotting 2 variables where both are allowed to vary in logistic regression

I'm hoping someone can help clarify a few things for me.

I ran some relatively simple logistic regressions in r and am having trouble with interpretation. I'm interested in the effects of elevation and a species diversity index on the presence/absence of a disease in individual animals.

I ran a simple model of: Result~Elevation+Diversity which gave this result

Call:
glm(formula = Test_Result ~ Elevation + Simpsons_Diversity, family = binomial,
data = XXXXXX)

Deviance Residuals:
Min       1Q   Median       3Q      Max
-0.8141  -0.6984  -0.5317  -0.4143   2.3337

Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept)        -2.118e+00  1.594e-01 -13.289  < 2e-16
Elevation           1.316e-04  2.247e-05   5.855 4.76e-09
Simpsons_Diversity -9.907e-01  2.725e-01  -3.635 0.000278

Null deviance: 3015.2  on 3299  degrees of freedom
Residual deviance: 2923.6  on 3297  degrees of freedom
AIC: 2929.6


I have a strong suspicion that diversity decreases with increasing elevation which I have confirmed although the relationship isn't quite as strong as I thought. When I run a model with an interaction term elevation*diversity I get:

Call:
glm(formula = Test_Result ~ Elevation_1000 + Simpsons_Diversity_100 +
Elevation_1000 * Simpsons_Diversity_100, family = binomial,
data = XXXXXXX)

Deviance Residuals:
Min       1Q   Median       3Q      Max
-0.7908  -0.6959  -0.5437  -0.3963   2.4215

Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept)                           -2.014422   0.179507 -11.222  < 2e-16
Elevation_1000                         0.112466   0.027433   4.100 4.14e-05
Simpsons_Diversity_100                -0.015851   0.005780  -2.743   0.0061
Elevation_1000:Simpsons_Diversity_100  0.001408   0.001200   1.173   0.2406

Null deviance: 3015.2  on 3299  degrees of freedom
Residual deviance: 2922.2  on 3296  degrees of freedom
AIC: 2930.2

Number of Fisher Scoring iterations: 5


Showing that adding the interaction term doesn't really help the fit of the model (AIC = 2930) and the interaction term itself is not significant (p-value=0.24).

Am I on the right track so far?

If I am, I understand how to convert coefficients to odds ratios and interpret those. My main question is can I plot the predicted probabilities for a combination of elevation and diversity where each variable is allowed to vary? Or is this essentially plotting the interaction?

I was able to create a dataframe where I varied elevation and diversity and I used my simple non-interaction model to obtain predicted probabilities using the PREDICT fuction) for those combinations, but I want to make sure that I am doing things correctly. I've attached the plot of predicted probs for different levels of diversity. • What you are doing makes perfect sense. Creating a new data frame where you modify and fix values of your variables is something I do all the time to obtain predicted probabilities. – StatsStudent Jan 22 '16 at 0:31
• With an interaction you look at whether the effect of diversity changes with elevation. That is different from the expectation that diversity changes with elevation. – Maarten Buis Jan 22 '16 at 10:46
• Thank you for your comments! It's good to see that I am on the right track. So, if there were to be a significant interaction effect would the slopes of each line in the above graph vary depending on the value of diversity? I am having trouble with the fact that elevation has a strong positive association with the dependent var. and diversity has a less strong, but still significant negative association, and the interaction term isn't significant. Does his mean that no matter what level of diversity I look at, the effect of elevation on the outcome will stay the same? Thanks again! – GHacker Jan 22 '16 at 16:46