# Goodness of fit test - overview

This page offers structured overviews of one or more selected methods. Add additional methods for comparisons by clicking on the dropdown button in the right-hand column. To practice with a specific method click the button at the bottom row of the table

Goodness of fit test
McNemar's test
Logistic regression
Independent variableIndependent variableIndependent variables
None2 paired groupsOne or more quantitative of interval or ratio level and/or one or more categorical with independent groups, transformed into code variables
Dependent variableDependent variableDependent variable
One categorical with $J$ independent groups ($J \geqslant 2$)One categorical with 2 independent groupsOne categorical with 2 independent groups
Null hypothesisNull hypothesisNull hypothesis
• H0: the population proportions in each of the $J$ conditions are $\pi_1$, $\pi_2$, $\ldots$, $\pi_J$
or equivalently
• H0: the probability of drawing an observation from condition 1 is $\pi_1$, the probability of drawing an observation from condition 2 is $\pi_2$, $\ldots$, the probability of drawing an observation from condition $J$ is $\pi_J$

Let's say that the scores on the dependent variable are scored 0 and 1. Then for each pair of scores, the data allow four options:

1. First score of pair is 0, second score of pair is 0
2. First score of pair is 0, second score of pair is 1 (switched)
3. First score of pair is 1, second score of pair is 0 (switched)
4. First score of pair is 1, second score of pair is 1
The null hypothesis H0 is that for each pair of scores, P(first score of pair is 0 while second score of pair is 1) = P(first score of pair is 1 while second score of pair is 0). That is, the probability that a pair of scores switches from 0 to 1 is the same as the probability that a pair of scores switches from 1 to 0.

Other formulations of the null hypothesis are:

• H0: $\pi_1 = \pi_2$, where $\pi_1$ is the population proportion of ones for the first paired group and $\pi_2$ is the population proportion of ones for the second paired group
• H0: for each pair of scores, P(first score of pair is 1) = P(second score of pair is 1)

Model chi-squared test for the complete regression model:
• H0: $\beta_1 = \beta_2 = \ldots = \beta_K = 0$
Wald test for individual regression coefficient $\beta_k$:
• H0: $\beta_k = 0$
or in terms of odds ratio:
• H0: $e^{\beta_k} = 1$
Likelihood ratio chi-squared test for individual regression coefficient $\beta_k$:
• H0: $\beta_k = 0$
or in terms of odds ratio:
• H0: $e^{\beta_k} = 1$
in the regression equation $\ln \big(\frac{\pi_{y = 1}}{1 - \pi_{y = 1}} \big) = \beta_0 + \beta_1 \times x_1 + \beta_2 \times x_2 + \ldots + \beta_K \times x_K$. Here $x_i$ represents independent variable $i$, $\beta_i$ is the regression weight for independent variable $x_i$, and $\pi_{y = 1}$ represents the true probability that the dependent variable $y = 1$ (or equivalently, the proportion of $y = 1$ in the population) given the scores on the independent variables.
Alternative hypothesisAlternative hypothesisAlternative hypothesis
• H1: the population proportions are not all as specified under the null hypothesis
or equivalently
• H1: the probabilities of drawing an observation from each of the conditions are not all as specified under the null hypothesis

The alternative hypothesis H1 is that for each pair of scores, P(first score of pair is 0 while second score of pair is 1) $\neq$ P(first score of pair is 1 while second score of pair is 0). That is, the probability that a pair of scores switches from 0 to 1 is not the same as the probability that a pair of scores switches from 1 to 0.

Other formulations of the alternative hypothesis are:

• H1: $\pi_1 \neq \pi_2$
• H1: for each pair of scores, P(first score of pair is 1) $\neq$ P(second score of pair is 1)

Model chi-squared test for the complete regression model:
• H1: not all population regression coefficients are 0
Wald test for individual regression coefficient $\beta_k$:
• H1: $\beta_k \neq 0$
or in terms of odds ratio:
• H1: $e^{\beta_k} \neq 1$
If defined as Wald $= \dfrac{b_k}{SE_{b_k}}$ (see 'Test statistic'), also one sided alternatives can be tested:
• H1 right sided: $\beta_k > 0$
• H1 left sided: $\beta_k < 0$
Likelihood ratio chi-squared test for individual regression coefficient $\beta_k$:
• H1: $\beta_k \neq 0$
or in terms of odds ratio:
• H1: $e^{\beta_k} \neq 1$
AssumptionsAssumptionsAssumptions
• Sample size is large enough for $X^2$ to be approximately chi-squared distributed. Rule of thumb: all $J$ expected cell counts are 5 or more
• Sample is a simple random sample from the population. That is, observations are independent of one another
• Sample of pairs is a simple random sample from the population of pairs. That is, pairs are independent of one another
• In the population, the relationship between the independent variables and the log odds $\ln (\frac{\pi_{y=1}}{1 - \pi_{y=1}})$ is linear
• The residuals are independent of one another
• Variables are measured without error
Also pay attention to:
• Multicollinearity
• Outliers
Test statisticTest statisticTest statistic
$X^2 = \sum{\frac{(\mbox{observed cell count} - \mbox{expected cell count})^2}{\mbox{expected cell count}}}$
Here the expected cell count for one cell = $N \times \pi_j$, the observed cell count is the observed sample count in that same cell, and the sum is over all $J$ cells.
$X^2 = \dfrac{(b - c)^2}{b + c}$
Here $b$ is the number of pairs in the sample for which the first score is 0 while the second score is 1, and $c$ is the number of pairs in the sample for which the first score is 1 while the second score is 0.
Model chi-squared test for the complete regression model:
• $X^2 = D_{null} - D_K = \mbox{null deviance} - \mbox{model deviance}$
$D_{null}$, the null deviance, is conceptually similar to the total variance of the dependent variable in OLS regression analysis. $D_K$, the model deviance, is conceptually similar to the residual variance in OLS regression analysis.
Wald test for individual $\beta_k$:
The wald statistic can be defined in two ways:
• Wald $= \dfrac{b_k^2}{SE^2_{b_k}}$
• Wald $= \dfrac{b_k}{SE_{b_k}}$
SPSS uses the first definition.

Likelihood ratio chi-squared test for individual $\beta_k$:
• $X^2 = D_{K-1} - D_K$
$D_{K-1}$ is the model deviance, where independent variable $k$ is excluded from the model. $D_{K}$ is the model deviance, where independent variable $k$ is included in the model.
Sampling distribution of $X^2$ if H0 were trueSampling distribution of $X^2$ if H0 were trueSampling distribution of $X^2$ and of the Wald statistic if H0 were true
Approximately the chi-squared distribution with $J - 1$ degrees of freedom

If $b + c$ is large enough (say, > 20), approximately the chi-squared distribution with 1 degree of freedom.

If $b + c$ is small, the Binomial($n$, $P$) distribution should be used, with $n = b + c$ and $P = 0.5$. In that case the test statistic becomes equal to $b$.

Sampling distribution of $X^2$, as computed in the model chi-squared test for the complete model:
• chi-squared distribution with $K$ (number of independent variables) degrees of freedom
Sampling distribution of the Wald statistic:
• If defined as Wald $= \dfrac{b_k^2}{SE^2_{b_k}}$: approximately the chi-squared distribution with 1 degree of freedom
• If defined as Wald $= \dfrac{b_k}{SE_{b_k}}$: approximately the standard normal distribution
Sampling distribution of $X^2$, as computed in the likelihood ratio chi-squared test for individual $\beta_k$:
• chi-squared distribution with 1 degree of freedom
Significant?Significant?Significant?
• Check if $X^2$ observed in sample is equal to or larger than critical value $X^{2*}$ or
• Find $p$ value corresponding to observed $X^2$ and check if it is equal to or smaller than $\alpha$
For test statistic $X^2$:
• Check if $X^2$ observed in sample is equal to or larger than critical value $X^{2*}$ or
• Find $p$ value corresponding to observed $X^2$ and check if it is equal to or smaller than $\alpha$
If $b + c$ is small, the table for the binomial distribution should be used, with as test statistic $b$:
• Check if $b$ observed in sample is in the rejection region or
• Find two sided $p$ value corresponding to observed $b$ and check if it is equal to or smaller than $\alpha$
For the model chi-squared test for the complete regression model and likelihood ratio chi-squared test for individual $\beta_k$:
• Check if $X^2$ observed in sample is equal to or larger than critical value $X^{2*}$ or
• Find $p$ value corresponding to observed $X^2$ and check if it is equal to or smaller than $\alpha$
For the Wald test:
• If defined as Wald $= \dfrac{b_k^2}{SE^2_{b_k}}$: same procedure as for the chi-squared tests. Wald can be interpret as $X^2$
• If defined as Wald $= \dfrac{b_k}{SE_{b_k}}$: same procedure as for any $z$ test. Wald can be interpreted as $z$.
n.a.n.a.Wald-type approximate $C\%$ confidence interval for $\beta_k$
--$b_k \pm z^* \times SE_{b_k}$
where the critical value $z^*$ is the value under the normal curve with the area $C / 100$ between $-z^*$ and $z^*$ (e.g. $z^*$ = 1.96 for a 95% confidence interval).
n.a.n.a.Goodness of fit measure $R^2_L$
--$R^2_L = \dfrac{D_{null} - D_K}{D_{null}}$
There are several other goodness of fit measures in logistic regression. In logistic regression, there is no single agreed upon measure of goodness of fit.
n.a.Equivalent ton.a.
-
-
Example contextExample contextExample context
Is the proportion of people with a low, moderate, and high social economic status in the population different from $\pi_{low} = 0.2,$ $\pi_{moderate} = 0.6,$ and $\pi_{high} = 0.2$?Does a tv documentary about spiders change whether people are afraid (yes/no) of spiders?Can body mass index, stress level, and gender predict whether people get diagnosed with diabetes?
SPSSSPSSSPSS
Analyze > Nonparametric Tests > Legacy Dialogs > Chi-square...
• Put your categorical variable in the box below Test Variable List
• Fill in the population proportions / probabilities according to $H_0$ in the box below Expected Values. If $H_0$ states that they are all equal, just pick 'All categories equal' (default)
Analyze > Nonparametric Tests > Legacy Dialogs > 2 Related Samples...
• Put the two paired variables in the boxes below Variable 1 and Variable 2
• Under Test Type, select the McNemar test
Analyze > Regression > Binary Logistic...
• Put your dependent variable in the box below Dependent and your independent (predictor) variables in the box below Covariate(s)
JamoviJamoviJamovi
Frequencies > N Outcomes - $\chi^2$ Goodness of fit
• Put your categorical variable in the box below Variable
• Click on Expected Proportions and fill in the population proportions / probabilities according to $H_0$ in the boxes below Ratio. If $H_0$ states that they are all equal, you can leave the ratios equal to the default values (1)
Frequencies > Paired Samples - McNemar test
• Put one of the two paired variables in the box below Rows and the other paired variable in the box below Columns
Regression > 2 Outcomes - Binomial
• Put your dependent variable in the box below Dependent Variable and your independent variables of interval/ratio level in the box below Covariates
• If you also have code (dummy) variables as independent variables, you can put these in the box below Covariates as well
• Instead of transforming your categorical independent variable(s) into code variables, you can also put the untransformed categorical independent variables in the box below Factors. Jamovi will then make the code variables for you 'behind the scenes'
Practice questionsPractice questionsPractice questions