There is a bug when the Stata command linktest is used after fitting a logistic regression model with the glm command. If used after the logit command it works correctly, calculating the linear predictor, squaring this and then fitting a new LOGISTIC regression model with the linear predictor and its square as predictors. However, if exactly the same logistic regression model is fitted using glm then linktest gives a different result. The result is erroneous, it relates to a LINEAR regression of the binary outcome on the linear predictor and its square from the logistic regression model. This is an inappropriate way to test for an incorrectly specified link function in the logistic regression model. This is all illustrated below. Can this be fixed?
use https://www.stata-press.com/data/r17/auto, clear
logit foreign mpg weight, nolog
linktest, nolog
predict xb, xb
gen xb2= xb*xb
logit foreign xb xb2, nolog
* correctly agrees with linktest
use https://www.stata-press.com/data/r17/auto, clear
glm foreign mpg weight, family(binomial) nolog
linktest, nolog
predict xb, xb
gen xb2= xb*xb
glm foreign xb xb2, family(binomial) nolog
* does not agree with linktest following glm
* does agree with linktest following logit
glm foreign xb xb2, family(gaussian) nolog
* agrees with linktest following glm
* but this is linear not logistic regression!
Chris Frost
use https://www.stata-press.com/data/r17/auto, clear
logit foreign mpg weight, nolog
linktest, nolog
predict xb, xb
gen xb2= xb*xb
logit foreign xb xb2, nolog
* correctly agrees with linktest
use https://www.stata-press.com/data/r17/auto, clear
glm foreign mpg weight, family(binomial) nolog
linktest, nolog
predict xb, xb
gen xb2= xb*xb
glm foreign xb xb2, family(binomial) nolog
* does not agree with linktest following glm
* does agree with linktest following logit
glm foreign xb xb2, family(gaussian) nolog
* agrees with linktest following glm
* but this is linear not logistic regression!
Chris Frost
Comment