| chisq_gof {sjstats} | R Documentation |
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 glm-objects for binary data.
chisq_gof(x, prob = NULL, weights = NULL)
x |
Numeric vector, or a |
prob |
Vector of probabilities (indicating the population probabilities) of the same length
as |
weights |
Vector with weights, used to weight |
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
X2 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
based on the X2GOFtest function of the binomTools package.
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.
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 <- ifelse(efc$tot_sc_e > 0, 1, 0)
fit <- glm(services ~ neg_c_7 + c161sex + e42dep, data = efc,
family = binomial(link = "logit"))
chisq_gof(fit)