0
$\begingroup$

I want to see if light conditions (light/dark) and categories (camera trap, wild, zoo) can predict a correct identification (1= correct, 0 = incorrect). I only want to consider the interaction not the main effects.

I first tried:

modelC <- glm(Correct~Light*Category, family = binomial(link="logit"))

But I received NAs for the interaction. Which command in Rconsiders only the interaction?

Call:
glm(formula = EC_Correct ~ EC_Light * EC_Category, family = binomial(link = "logit"))

Deviance Residuals: 
    Min       1Q   Median       3Q      Max  
-0.8842  -0.5022  -0.3357  -0.2031   2.7899  

Coefficients: (2 not defined because of singularities)
                              Estimate Std. Error z value Pr(>|z|)    
(Intercept)                    -0.7376     0.2592  -2.845 0.004434 ** 
EC_Lightlight                  -1.2693     0.3355  -3.783 0.000155 ***
EC_CategoryWild                -0.8409     0.3654  -2.301 0.021379 *  
EC_CategoryZoo                 -1.8643     0.6210  -3.002 0.002680 ** 
EC_Lightlight:EC_CategoryWild       NA         NA      NA       NA    
EC_Lightlight:EC_CategoryZoo        NA         NA      NA       NA    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

(Dispersion parameter for binomial family taken to be 1)

    Null deviance: 408.26  on 644  degrees of freedom
Residual deviance: 361.49  on 641  degrees of freedom
AIC: 369.49

Number of Fisher Scoring iterations: 6

Or:

Call:
glm(formula = EC_Correct ~ EC_Light:EC_Category, family = binomial(link = "logit"))

Deviance Residuals: 
    Min       1Q   Median       3Q      Max  
-0.8842  -0.5022  -0.3357  -0.2031   2.7899  

Coefficients: (3 not defined because of singularities)
                                     Estimate Std. Error z value Pr(>|z|)    
(Intercept)                           -3.8712     0.5833  -6.637 3.21e-11 ***
EC_Lightdark:EC_CategoryCamera trap    3.1336     0.6383   4.909 9.14e-07 ***
EC_Lightlight:EC_CategoryCamera trap   1.8643     0.6210   3.002  0.00268 ** 
EC_Lightdark:EC_CategoryWild               NA         NA      NA       NA    
EC_Lightlight:EC_CategoryWild          1.0234     0.6545   1.564  0.11792    
EC_Lightdark:EC_CategoryZoo                NA         NA      NA       NA    
EC_Lightlight:EC_CategoryZoo               NA         NA      NA       NA    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

(Dispersion parameter for binomial family taken to be 1)

    Null deviance: 408.26  on 644  degrees of freedom
Residual deviance: 361.49  on 641  degrees of freedom
AIC: 369.49

Number of Fisher Scoring iterations: 6
$\endgroup$
6
  • $\begingroup$ I think the first thing you should do is to examine your data-set to see why you get those NA coefficients. Perhaps you should show us the joint distribution of Light and Category. Trying to interpret an interaction without looking at the main effects as well is fraught with problems so unless you really know why you want to do it best to avoid it. $\endgroup$
    – mdewey
    Aug 10, 2017 at 13:59
  • $\begingroup$ You probably only have four values of Light * Category in your data. $\endgroup$
    – mdewey
    Aug 10, 2017 at 15:58
  • $\begingroup$ I understand this. I have values for Camera trap (light & dark), Wild (light) and zoo (light). But why is there no value for Zoo & Light? $\endgroup$
    – Steph
    Aug 11, 2017 at 15:15
  • $\begingroup$ Because you specified A:B not A*B. In fact with that structure I think you would be better to either specify A+B or construct a four level factor for the combinations you do have. $\endgroup$
    – mdewey
    Aug 11, 2017 at 15:55
  • $\begingroup$ I ran it with A*B but then I get NAs for the interaction and we're especially interested in the interaction. Same applies to A+B. Do I got it right that you mean to create a new column (predictor) with values: "lightCameratrap" "darkCameratrap" "lightWild" and "lightZoo" ? $\endgroup$
    – Steph
    Aug 11, 2017 at 17:34

2 Answers 2

1
$\begingroup$

You might want to try this.

modelC <- glm(Correct~Light:Category, family = binomial(link="logit"))

$\endgroup$
5
  • $\begingroup$ Thanks, this could work. Do you have an idea why I get NAs for "zoo"? Is that because I only have the "light" condition and no darks? I receive following: EC_Lightdark:EC_CategoryCamera trap 3.1336 0.6383 4.909 EC_Lightlight:EC_CategoryCamera trap 1.8643 0.6210 3.002 EC_Lightdark:EC_CategoryWild NA NA NA EC_Lightlight:EC_CategoryWild 1.0234 0.6545 1.564 EC_Lightdark:EC_CategoryZoo NA NA NA EC_Lightlight:EC_CategoryZoo NA NA NA $\endgroup$
    – Steph
    Aug 10, 2017 at 14:01
  • $\begingroup$ @Steph That could be a reason. Would you be able to provide that cross tabulation of the two variables i.e. table(Light, Category)? $\endgroup$
    – tatami
    Aug 10, 2017 at 14:20
  • $\begingroup$ You mean the full list? I have 645 rows in total, I could only paste it partly :-) $\endgroup$
    – Steph
    Aug 10, 2017 at 14:44
  • $\begingroup$ @Steph no i meant run the function table(Light, Category) and provide the output $\endgroup$
    – tatami
    Aug 10, 2017 at 14:50
  • $\begingroup$ I added it to my question. In the first model I recieve only NAs for the interaction and in the second one it shows the interaction. The NAs for EC_Lightdark:EC_CategoryWild make sense, because there is no "dark" in the "wild" category. But I am confused about the "zoos" because there are only "light"s but no "dark". $\endgroup$
    – Steph
    Aug 10, 2017 at 15:57
1
$\begingroup$

We need to remind purselves here of what an interaction means. For two caegorical variables, as here, it means that the effect of one variable is different at differemt levels of the other. Since you have values for light at all three levels but for dark at only one you cannot expect to see how the effect of light varies at differemt levels of your other variable. You do not have the data you need to look at the interaction.

$\endgroup$
2
  • $\begingroup$ Thank you very much for the explanation, I understand this. Still I am confused why R reports me a value for "wild" and "light" even tough there can not be an interaction term, because "dark" is missing :/ $\endgroup$
    – Steph
    Aug 12, 2017 at 10:11
  • $\begingroup$ It reports them because it can estimate them but it does not mean they are very useful. Basically the effect of dark is only being estimated for one level of your other variable. $\endgroup$
    – mdewey
    Aug 12, 2017 at 14:10

Your Answer

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

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