For logistic regression models, performs a Chi-squared goodness-of-fit-test.

`chisq_gof(x, prob = NULL, weights = NULL)`

- x
A numeric vector or a

`glm`

-object.- prob
Vector of probabilities (indicating the population probabilities) of the same length as

`x`

's amount of categories / factor levels. Use`nrow(table(x))`

to determine the amount of necessary values for`prob`

. Only used, when`x`

is a vector, and not a`glm`

-object.- weights
Vector with weights, used to weight

`x`

.

For vectors, returns the object of the computed `chisq.test`

.
For `glm`

-objects, an object of class `chisq_gof`

with
following values: `p.value`

, the p-value for the goodness-of-fit test;
`z.score`

, the standardized z-score for the goodness-of-fit test;
`rss`

, the residual sums of squares term and `chisq`

, the pearson
chi-squared statistic.

For vectors, this function is a convenient function for the
`chisq.test()`

, performing goodness-of-fit test. For
`glm`

-objects, this function performs a goodness-of-fit test.
A well-fitting model shows *no* significant difference between the
model and the observed data, i.e. the reported p-values should be
greater than 0.05.

Hosmer, D. W., & Lemeshow, S. (2000). Applied Logistic Regression. Hoboken, NJ, USA: John Wiley & Sons, Inc.

```
data(efc)
efc$neg_c_7d <- ifelse(efc$neg_c_7 < median(efc$neg_c_7, na.rm = TRUE), 0, 1)
m <- glm(
neg_c_7d ~ c161sex + barthtot + c172code,
data = efc,
family = binomial(link = "logit")
)
# goodness-of-fit test for logistic regression
chisq_gof(m)
#>
#> # Chi-squared Goodness-of-Fit Test
#>
#> Chi-squared: 852.765
#> z-score: 3.546
#> p-value: 0.000
#>
#> Summary: model does not fit well.
# goodness-of-fit test for vectors against probabilities
# differing from population
chisq_gof(efc$e42dep, c(0.3,0.2,0.22,0.28))
#>
#> Chi-squared test for given probabilities
#>
#> data: dummy
#> X-squared = 234.76, df = 3, p-value < 2.2e-16
#>
# equal to population
chisq_gof(efc$e42dep, prop.table(table(efc$e42dep)))
#>
#> Chi-squared test for given probabilities
#>
#> data: dummy
#> X-squared = 0, df = 3, p-value = 1
#>
```