Learn R Programming

sjmisc (version 1.8)

chisq_gof: Chi-square goodness-of-fit-test

Description

This method performs a Chi-square goodness-of-fit-test (GOF) either on a numeric vector against probabilities, or a Goodness-of-fit test for glms for binary data.

Usage

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

Arguments

x
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, wh
weights
Vector with weights, used to weight x.

Value

  • For vectors, returns the object of the computed chisq.test. For glm-objects, an object of class chisq_gof with following values:
    • p.valuethe p-value for the goodness-of-fit test
    • z.scorethe standardized z-score for the goodness-of-fit test
    • RSSthe residual sums of squares term
    • X2the pearson chi-squared statistic

Examples

Run this code
data(efc)
# differing from population
chisq_gof(efc$e42dep, c(0.3,0.2,0.22,0.28))
# equal to population
chisq_gof(efc$e42dep, prop.table(table(efc$e42dep)))

# goodness-of-fit test for logistic regression
efc$services <- dicho(efc$tot_sc_e, "v", 0, as.num = TRUE)
fit <- glm(services ~ neg_c_7 + c161sex + e42dep,
           data = efc,
           family = binomial(link = "logit"))
chisq_gof(fit)

Run the code above in your browser using DataLab