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:Anova
test? 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. $\endgroup$car:Anova
does 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). $\endgroup$car::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:Anova
is model objects from theordinal
package. Last I checked, it gives strange results unless theRVAideMemoire
package is used with it. As a further note, I looked quickly at the documentation and vignettes for thebrglm2
package. I didn't see any use ofanova
or comparison of models, so you might be cautious usinganova
as well. $\endgroup$brglm
documentation 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 forbrglm2
is not described theoretically (although this does not explain the difference, but is just general piece of advise) 2) Thecar::Anova
package ignores the method parameter, and only works with vanilla (old-fasioned)glm
. $\endgroup$