0

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. Any help would be appreciated! Thank you!

Edit: here is a mock example of my issue

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)

This comes 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
Kon-kon
  • 3
  • 3
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. If you are looking for data modeling advice rather than programming help, you should ask at [stats.se] instead. – MrFlick Jan 20 '23 at 16:34
  • I think you should read up on "perfect collinearity" and why it breaks regression models like these. Maybe start with the answers to this question: https://stats.stackexchange.com/questions/221902/what-is-an-example-of-perfect-multicollinearity – Vincent Jan 21 '23 at 00:27

0 Answers0