R code for likelihood testing

Asked

Viewed 1,068 times

-2

I have a data set to do a logistic regression for the dependent variable "parturition" which is binary qualitative.

With the command below I get the univariate logistic model:

GLM.1 <- glm(parto ~ serie, family=binomial(logit), data=Dataset)

With this other command below I get the p value of the chi-square of the likelihood ratio test.

1-pchisq(GLM.1$null.deviance-GLM.1$deviance, GLM.1$df.null-GLM.1$df.residual)

Which commands should I use to find each of the following components separately?

  1. deviance
  2. L(reduced model)
  3. L(saturated model)
  • For that you need a data set and a probability distribution. Please clarify the question. (And by the way, what kind of test? A verisimilitude ratio test?)

  • My data set contains a sample of over 400 individuals. I need to make a logistic regression for the dependent variable "childbirth" which is binary qualitative. I have some independent variables that are also qualitative, with two or more categories. So I need to do the likelihood ratio test.

  • Ask a more complete question, with snippets of code you’re using and even make the data (or a sample of it) available, if possible. In stackoverflow, it is always recommended to share a minimum reproducible code -- short and vague questions like this end up being penalized. But trying to contribute substantively, I recommend you take a look at this answer here: https://stats.stackexchange.com/questions/6505/likelihood-ratio-test-in-r

  • Thanks Rui Barradas and Rogeriojb. I improved the questions. I hope you can help me!!

  • Thank you Rui Barradas and Rogeriojb. I was able to solve the problem with the lmtest package using the lrtest(GLM.1) function on the link sent by Rogeriojb.

1 answer

1


Now it’s easier to answer the question. Just see the section Value page ?glm.

L_sat <- GLM.1$deviance/(-2)
L_red <- GLM.1$null.deviance/(-2)

Notes further that it is possible to simplify the calculation of p-value, using the argument lower.tail that all functions of the R have. This may still be important because rounding errors are smaller.

pchisq(GLM.1$null.deviance-GLM.1$deviance, GLM.1$df.null-GLM.1$df.residual, lower.tail = FALSE)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.