I'm trying to fit a GLM on some data and I feel like there should be an interaction term between two of the explanatory variables (one categorical and one discrete) but all the non-zero instances of the discrete variable occur on the "1" state of the categorical variable (partly why I feel like there should be an interaction). When I put the interaction in the glm (var1*var2), it just shows N/A for the interaction term (var1:var2) in the summary ANOVA.
I have Included a mock example below
a <- data.frame("y" <- c(0,1,2,3),
"var1" <- c(0,1,1,1),
"var2" <- c(0,0,1,2))
a.glm <- glm(y ~ var1*var2, family=poisson, data = a)
summary(a.glm)
and then this shows up in the console:
Call:
glm(formula = y ~ var1 * var2, family = poisson, data = a)
Deviance Residuals:
1 2 3 4
-0.00002 -0.08284 0.12401 -0.04870
Coefficients: (1 not defined because of singularities)
Estimate Std. Error z value Pr(>|z|)
(Intercept) -22.303 42247.166 0.00 1.00
var1 22.384 42247.166 0.00 1.00
var2 0.522 0.534 0.98 0.33
var1:var2 NA NA NA NA
(Dispersion parameter for poisson family taken to be 1)
Null deviance: 4.498681 on 3 degrees of freedom
Residual deviance: 0.024614 on 1 degrees of freedom
AIC: 13.63
Number of Fisher Scoring iterations: 20
This is the table giving the mean of y for each combination in my actual data.
| | 0 | 1 | 2 | 3 |
| 0 | 1.592 | N/A | N/A | N/A |
| 1 | 1.859 | 1.759 | 1.543 | 0.813 |
|mean| 1.721 | 1.759 | 1.543 | 0.813 |
I'd rather not make var2 categorical as there clearly seems to be a negative correlation between var2 and y which is being overshadowed by the var1 = 0 values. (there are relatively few observations of var2 = 2 and 3 which does not help overcome this effect)
Any help would be appreciated!
Thank you!
var1andvar2is perfectly collinear withvar2. That seems to be the problem. – Dave Armstrong Jan 20 '23 at 17:52yis generated according to a very specific process. I think you'll find if you generate more samples, and perhaps some randomness to the response, you will solve this problem. – AdamO Jan 20 '23 at 18:49