The code inserted below from ResourceSelection :: hoslem.test performs a validation of Hosmer and Lemeshow. Examining why an output that does not exactly match what is being done by other software (Stata), I found that the difference is due to the use of the default argument R for the quantile function (type = 7). I would like to use this function with a different default value to calculate quantiles (type = 6).
FWIW, a link to 9 possible methods used by R, can be found at:
https://www.amherst.edu/media/view/129116/original/Sample+Quantiles.pdf
The Stata manual for pctile refers to the default method and the 'altdef' method. It was difficult for me to compare these two methods with the corresponding types of R.
However
hoslem.test(yhat, y, type=6)
It produces:
> hl <- hoslem.test(y, yhat, type=6)
Error in hoslem.test(y, yhat, type = 6) : unused argument (type = 6)
Is there a way to execute the function below with the non-default argument for the quantile function?
Those. allows you to add the following line :, type = 6 ':
qq <- unique(quantile(yhat, probs = seq(0, 1, 1/g), type=6))
This function:
> ResourceSelection::hoslem.test
function (x, y, g = 10)
{
DNAME <- paste(deparse(substitute(x)), deparse(substitute(y)),
sep = ", ")
METHOD <- "Hosmer and Lemeshow goodness of fit (GOF) test"
yhat <- y
y <- x
qq <- unique(quantile(yhat, probs = seq(0, 1, 1/g)))
cutyhat <- cut(yhat, breaks = qq, include.lowest = TRUE)
observed <- xtabs(cbind(y0 = 1 - y, y1 = y) ~ cutyhat)
expected <- xtabs(cbind(yhat0 = 1 - yhat, yhat1 = yhat) ~
cutyhat)
chisq <- sum((observed - expected)^2/expected)
PVAL = 1 - pchisq(chisq, g - 2)
PARAMETER <- g - 2
names(chisq) <- "X-squared"
names(PARAMETER) <- "df"
structure(list(statistic = chisq, parameter = PARAMETER,
p.value = PVAL, method = METHOD, data.name = DNAME, observed = observed,
expected = expected), class = "htest")
}