I am currently working with a logistic model in R and I have a question regarding the p-values that I get from different types of tests.
Since I have separation in my data (caused by X) I use the brglm2 package and my models look like this:
model1 = glm(Y ~ X + D + S,
family = binomial(link = "logit"),
method = "brglm_fit",
data = data )
model2 = glm(Y ~ X + D,
family = binomial(link = "logit"),
method = "brglm_fit",
data = data )
Where:
Y: 0 or 1
S: factor with 3 levels
D: factor with 2 levels
To test for example for the significance of S, I use:
anova(model1, model2, test="Chisq")
Result:
Analysis of Deviance Table
Model 1: Y ~ X + D
Model 2: Y ~ X + S + D
Resid. Df Resid. Dev Df Deviance Pr(>Chi)
1 265 17.0218
2 263 8.1608 2 8.861 0.01191 *
As I understand this is the two models significantly differ from each other and that is the effect of S (or from leaving it out).
If I use the Anova function of the car package (type II or type III), I get slightly different results (depending on the model they can be totally different)
Anova(model1)
Analysis of Deviance Table (Type II tests)
Response: Y
LR Chisq Df Pr(>Chisq)
X 306.718 1 < 2e-16 ***
S 8.085 2 0.01756 *
D 5.814 1 0.01590 *
If I now want to know the which levels of S are different from each other, I run a post-hoc test using the multcomp or the lsmeans package (both return the same results).
summary( glht(model1, linfct=mcp(S = "Tukey")) )
Simultaneous Tests for General Linear Hypotheses
Multiple Comparisons of Means: Tukey Contrasts
Fit: glm(formula = Y ~ X + S + D, family = binomial,
data = data, control = list(maxit = 10000), method = "brglm_fit")
Linear Hypotheses:
Estimate Std. Error z value Pr(>|z|)
K - A == 0 -3.1136 1.9280 -1.615 0.239
R - A == 0 -3.7331 1.9983 -1.868 0.148
R - K == 0 -0.6195 1.7794 -0.348 0.935
(Adjusted p values reported -- single-step method)
I understand that the anova() function tests the difference between the models and that Anova() tests for the effects of the variables on the dependent variable with different types of SS and that the results from the two can therefore differ. I usually rely rather on the results obtained from the model comparison. But how does it happen that the post-hoc test is so far off? Is this not the appropriate way to test for the effect of the different levels of a factor in logistic regression?
car:Anovatest? It may also help to post your data (or more generally, any reproducible example), if possible. I see no reason the Tukey tests should look like the former tests, but the 1st 2 should be similar. – gung - Reinstate Monica May 18 '18 at 18:28car:Anovadoes not correctly implement the brglmFit function. Effectively it compares model1 with brglmfit to reduced models like model 2 *without brglmfit*. So regarding this part, it is a buggy implementation of the brglmfit procedure into the glm function and how related methods in R interpret this (anova just picks the deviance scores from glm, on the other hand Anova has to recalculate the glm for the different reduced models and forgets to pass the method=brglmfit stuff). – Sextus Empiricus May 20 '18 at 10:03car::Anova, it doesn't claim to be able to handle model objects frombrglm2. This is something that R users need to be cautious about. Another example withcar:Anovais model objects from theordinalpackage. Last I checked, it gives strange results unless theRVAideMemoirepackage is used with it. As a further note, I looked quickly at the documentation and vignettes for thebrglm2package. I didn't see any use ofanovaor comparison of models, so you might be cautious usinganovaas well. – Sal Mangiafico May 20 '18 at 13:58brglm2doesn't mentionAnova, andAnovadoesn't mentionbrglm2, it's a gamble that they will work correctly in conjunction --- as we see --- unless the user examines the code or does some testing. It would be a service for the authors ofbrglm2to address this question directly. (As I said, in a quick look I didn't see anything in the documentation usinganova). Personally I would like to seecar::Anovaupdated to handle more types of models correctly, as it is so valuable. I love howemmeanscan handle so many model types and lists them. – Sal Mangiafico May 20 '18 at 14:45brglmdocumentation actually mentions that methods for model comparison, such as anova, are to be considered experimental. Yet, this relates more to the theoretical side. Or, at least this issue with different p-values (which is practical and not a theoretical issue) leads to a discussion split into two issues 1) behavior of model comparison forbrglm2is not described theoretically (although this does not explain the difference, but is just general piece of advise) 2) Thecar::Anovapackage ignores the method parameter, and only works with vanilla (old-fasioned)glm. – Sextus Empiricus May 20 '18 at 16:21