How to Calculate the Deviance Residual When Logistic Regression is performed

Asked 2 years ago, Updated 2 years ago, 216 views

I would like to obtain a secondary device for logistic regression at R.
When using the glm.fit function, the following warning was issued:

glm.fit:fitted probabilities numerically 0 or 1 occurred 

So, I used the logistf function with reference to here.

cont<-logistf.control (maxit=1000, maxstep=100)
plcont<-logistpl.control (maxit=1000)
res<-logistf(y-x, first=TRUE, control=cont, plcontrol=plcont)

The summary(res) is as follows:

>summary(res)
logistf(formula=dat[,j]~Dat_res[,i], control=cont, plcontrol=plcont, first=TRUE)

Model fitted by Penalized ML
Coeficients:
                   coefse(coef)lower 0.95 upper 0.95 Chisqp
(Intercept) 0.13751990.11492692 - 0.08696857 0.3642894 1.4393220.230249
Data_res[,i]- 0.7204668 0.05044381-0.82565105-0.6269034 Inf 0.000000
             method
(Intercept) 2
Data_res[,i]2

Method: 1-Wald, 2-Profile normalized log-likelihood, 3-None

Likelyhood ratio test=895.6586 on 1 df, p=0, n=1000
Wald test = 203.9916 on 1 df, p = 0

Based on this result, I am thinking of calculating the device residual (residual device) as described in this site, but I am not sure how to derive it.
I apologize for the lack of understanding, but I appreciate your cooperation.

r

2022-09-30 21:59

1 Answers

The definition of deviation in the generalized linear model (GLM) is logarithmic likelihood of the -2x model (although there is another definition, it is considered intended from the context of the slide or question), where the secondary device usually refers to the deviation between the estimated model and the saturation model.

In this case, the loglik of the logisf object contains the logarithmic likelihood of the penalty estimation model and the full model, so it can be calculated by -2*(res$loglik[1]-res$loglik[2]).

And this is equivalent to the test statistic of the likelihood ratio test in the default setting, so it should be the same as the value of Likehood ratio test=... when displayed in summary().

It may be meddling, but online descriptions are often fragmentary, so I think you should read at least one textbook that explains systematically. For example, Takuya Kubo's Introduction to Statistical Modeling for Data Analysis (2012, Iwanami Bookstore) is one of the books that mentions deviation.

However, be aware of the following disclaimer.

It's been a while since my reply, but it might cause misunderstanding, so I'll add the following

I read the question and comment again and noticed that you and I have both confused residual deviance and deviance residuals. In some parts, I wrote "deviance residuals", but all I meant was residual deviance. This residual deviance is defined as -2*.

However, in the referenced slides, we simply refer to the above residual device as "deviance" as -2* (logistic likelihood) or -2* (logistic likelihood - full model logarithmic likelihood) is confusing.

On the other hand, the deviance residuals/deviance residuals calculated for each observation refer to the square root of the above (residual) deviance.deviance=-2* and residula deviance=-2* (logistic likelihood-full model logarithmic likelihood).

Note that there is a double confusing point (the latter may be distinguished by using "unit--" or "casewise---" to avoid misreading).

It says "deviance residuals" in the title and "residual deviance" in the body. I answered because I thought it was intended to be a residual deviance to the model, but if what I actually want is not a residual deviance, but this (casewise) deviance residuals, glide&mode.Yes (there are many other definitions of residuals used in GLM, but I think which one should be used depends on the purpose). On the other hand, logistf does not have the ability to calculate residuals, so it is calculated from logarithmic likelihood or posterior logarithmic probability.

https://github.com/georgheinze/logistf/issues/37

As I wrote in the comment, the residual of linear regression model and the deviation residual of GLM do not necessarily behave the same way, so I hope you don't think you can always treat it the same way as the residual.


2022-09-30 21:59

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.