Last data update: 2014.03.03

R: Hosmer-Lemeshow Goodness of Fit (GOF) Test
 hoslem.test R Documentation

## Hosmer-Lemeshow Goodness of Fit (GOF) Test

### Description

Hosmer-Lemeshow Goodness of Fit (GOF) Test.

### Usage

```hoslem.test(x, y, g = 10)
```

### Arguments

 `x` a numeric vector of observations, binary (0/1). `y` expected values. `g` number of bins to use to calculate quantiles.

### Details

The Hosmer-Lemeshow test is a statistical test for goodness of fit for logistic regression models.

### Value

A list with class `"htest"` containing the following components:

 `statistic` the value of the chi-squared test statistic, (`sum((observed - expected)^2 / expected)`). `parameter` the degrees of freedom of the approximate chi-squared distribution of the test statistic (`g - 2`). `p.value` the p-value for the test. `method` a character string indicating the type of test performed. `data.name` a character string giving the name(s) of the data. `observed` the observed frequencies in a `g`-by-2 contingency table. `expected` the expected frequencies in a `g`-by-2 contingency table.

### Author(s)

Peter Solymos by adapting code pieces from R help mailing list

### References

Hosmer D W, Lemeshow S 2000. Applied Logistic Regression. New York, USA: John Wiley and Sons.

### Examples

```set.seed(123)
n <- 500
x <- rnorm(n)
y <- rbinom(n, 1, plogis(0.1 + 0.5*x))
m <- glm(y ~ x, family=binomial)
hoslem.test(m\$y, fitted(m))
```

### Results

```
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(ResourceSelection)
ResourceSelection 0.2-6 	 2016-02-15
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/ResourceSelection/hoslem.test.Rd_%03d_medium.png", width=480, height=480)
> ### Name: hoslem.test
> ### Title: Hosmer-Lemeshow Goodness of Fit (GOF) Test
> ### Aliases: hoslem.test
> ### Keywords: htest
>
> ### ** Examples
>
> set.seed(123)
> n <- 500
> x <- rnorm(n)
> y <- rbinom(n, 1, plogis(0.1 + 0.5*x))
> m <- glm(y ~ x, family=binomial)
> hoslem.test(m\$y, fitted(m))

Hosmer and Lemeshow goodness of fit (GOF) test

data:  m\$y, fitted(m)
X-squared = 4.5227, df = 8, p-value = 0.8072

>
>
>
>
>
> dev.off()
null device
1
>

```