How to take the Hosmer-Lemeshow test on R?

Asked

Viewed 938 times

6

I have a data set to make the logistic regression of the dependent variable childbirth which is binary qualitative.

With the following command I obtain the multivariate logistic model in the program R:

GLM.1 <- glm(parto ~ trabalho + financiamento + consulta, family=binomial(logit), data=Dataset)

The independent variables in this model are also binary qualitative.

I would like to know which R command should I use to get the Hosmer-Lemeshow test to check if this model is adjusted.

If you need to use a specific R package for this, I would like to know what this package would be and what function to use.

  • You could post your dataset to perform the tests?

2 answers

5


With a quick search of the Stack Overflow in English and with the command RSiteSearch of own R found 2 functions for such test. hoslem.test package ResourceSelection and logitgof package generalhoslem

  • Using the package ResourceSelection with the command hoslem.test(Dataset$parto, fitted(GLM.1)) meeting the following result: X-Squared = 455, df = 8, p-value < 2.2e-16. However, using the package generalhoslem with the command logitgof(Dataset$parto, fitted(GLM.1)) , for the same data, I find this other result: X-Squared = 4.3539, df = 7, p-value = 0.7382. Also, using the SPSS program, also for the same data, I still find another result X-Squared = 4,168, df = 8, p-value = 0,842. Could you explain to me why these results are different?

  • I have no idea why. I used the example given in help of function hoslem.test and compared the result of both functions, and the result was the same.

  • Follow the link (https://www.dropbox.com/s/64jo0auqeowj8fh/teste.xlsx?dl=0). Command to generate the model: GLM.1 <- glm(parto ~ trabalho + financiamento + consulta, family=binomial(logit), data=Dataset). Results updated with what I got in the tests for the variables: package ResourceSelection and command hoslem.test(Dataset$parto, fitted(GLM.1)) found X-Squared = 455, df = 8, p-value < 2.2e-16; bundle generalhoslem and command logitgof(Dataset$parto, fitted(GLM.1)) found X-Squared = 2.2901, df = 3, p-value = 0.5144. In the SPSS X-Squared = 2,357; df = 5; p-valeu = 0,798

  • I just rotated here, and the difference that appeared here was in the degrees of freedom and the p-value of the test. GLM.1 <- glm(parto ~ trabalho + financiamento + consulta, family=binomial(logit), data=test. The command hoslem.test(GLM.1$y, fitted(GLM.1)) resulted in X-squared = 2.2901, df = 8, p-value = 0.9708 and the result of the command logitgof(GLM.1$y, fitted(GLM.1)) was X-squared = 2.2901, df = 3, p-value = 0.5144 with a Warning In logitgof(GLM.1$y, fitted(GLM.1)) : Not possible to compute 10 rows. There might be too few observations.

  • I put the package reshape to run together with the package ResourceSelection and I turned the remote hoslem.test(Dataset$parto, fitted(GLM.1)). So, the result is now the same as Rafael Cunha X-Squared = 2.2901, df = 8, p-value = 0.9708. With the package generalhoslem and command logitgof(Dataset$parto, fitted(GLM.1)) the result continues giving X-Squared = 2.2901, df = 3, p-value = 0.5144, and the same message appears Warning in logitgof(Dataset$parto, fitted(GLM.1)) : Not possible to Compute 10 Rows. There Might be Too few Observations.

  • Perhaps this difference is due to some difference in the implementation of the codes...

Show 1 more comment

1

What I know about the Hosmer and Lemeshow test is that this difference may be due to the grouping of the data, when the data are not multiples of ten or the group quantity for the statistical test, which is usually 10, clusters are different in spss and resourseselection test in r. For example with 105 samples in spss it groups the first 9 with 11 data and the last group with 6 while in r with the resourse Selection package it tries to leave of the same size all groups, Then some groups will be with 11 others with 10 samples per group, which gives difference in result. I particularly can’t identify which one is right.

Browser other questions tagged

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