## What is Goodness-Of-Fit?

The goodness-of-fit test is a statistical hypothesis test to see how well sample data fit a distribution from a population with a normal distribution. Put differently, this test shows if your sample data represents the data you would expect to find in the actual population or if it is somehow skewed. Goodness-of-fit establishes the discrepancy between the observed values and those that would be expected of the model in a normal distribution case.

There are multiple methods for determining goodness-of-fit. Some of the most popular methods used in statistics include the chi-square, the Kolmogorov-Smirnov test, the Anderson-Darling test, and the Shipiro-Wilk test.

### Key Takeaways

• Goodness-of-fit tests are statistical tests aiming to determine whether a set of observed values match those expected under the applicable model.
• There are multiple types of goodness-of-fit tests, but the most common is the chi-square test.
• Chi-square determines if a relationship exists between categorical data.
• The Kolmogorov-Smirnov test—used for large samples—determines whether a sample comes from a specific distribution of a population.
• Goodness-of-fit tests can show you whether your sample data fit an expected set of data from a population with normal distribution.

## Understanding Goodness-Of-Fit

Goodness-of-fit tests are statistical methods often used to make inferences about observed values. These tests determine how related actual values are to the predicted values in a model, and when used in decision-making, goodness-of-fit tests can help predict future trends and patterns.

The most common goodness-of-fit test is the chi-square test, typically used for discrete distributions. The chi-square test is used exclusively for data put into classes (bins), and it requires a sufficient sample size to produce accurate results.

Goodness-of-fit tests are commonly used to test for the normality of residuals or to determine whether two samples are gathered from identical distributions.

## Types of Goodness-Of-Fit Tests

### Chi-Square Test

$\chi^2=\sum\limits^k_{i=1}(O_i-E_i)^2/E_i$

The chi-square test, also known as the chi-square test for independence, is an inferential statistics method that tests the validity of a claim made about a population based on a random sample. However, it does not indicate the type or intensity of the relationship. For instance, it does not conclude whether the relationship is positive or negative.

To qualify for the chi-square test for independence, variables must be mutually exclusive.

To calculate a chi-square goodness-of-fit, it is necessary to set the desired alpha level of significance (e.g., if your confidence level is 95% or .95, then the alpha is .05), identify the categorical variables to test, and define hypothesis statements about the relationships between them. The null hypothesis asserts that no relationship exists between variables, and the alternative hypothesis assumes that a relationship exists. The frequency of the observed values is measured and subsequently used with the expected values and the degrees of freedom to calculate chi-square. If the result is lower than alpha, the null hypothesis is invalid, indicating a relationship exists between the variables.

### Kolmogorov-Smirnov Test

$D=\max\limits_{1\leq i\leq N}\bigg(F(Y_i)-\frac{i-1}{N},\frac{i}{N}-F(Y_i)\bigg)$

Named after Russian mathematicians Andrey Kolmogorov and Nikolai Smirnov, the Kolmogorov-Smirnov test (also known as the K-S test) is a statistical method that determines whether a sample is from a specific distribution within a population. The Kolmogorov-Smirnov test—recommended for large samples (e.g., over 2000)—is non-parametric, meaning it does not rely on any distribution to be valid. It focuses The goal is to prove the null hypothesis, which is the sample of the normal distribution.

Contrary to the chi-square test, the Kolmogorov-Smirnov test applies to continuous distributions. Like chi-square, it uses a null and alternative hypothesis and an alpha level of significance. Null indicates that the data follow a specific distribution within the population, and alternative indicates that the data did not follow a specific distribution within the population. The alpha is used to determine the critical value used in the test.

The calculated test statistic, often denoted as D, determines whether the null hypothesis is accepted or rejected. If D is greater than the critical value at alpha, the null hypothesis is rejected. If D is less than the critical value, the null hypothesis is accepted, indicating

### Shipiro-Wilk Test

$W=\frac{\big(\sum^n_{i=1}a_i(x_{(i)}\big)^2}{\sum^n_{i=1}(x_i-\bar{x})^2},$

The Shipiro-Wilk test determines if a sample follows a normal distribution. Using a sample with one variable of continuous data, the Shipiro-Wilk test only checks for normality. It is recommended for small sample sizes up to 2000. Alike the others, it uses alpha and forms two hypotheses: null and alternative. The null hypothesis states that the sample comes from the normal distribution, whereas the alternative hypothesis states that the sample does not come from the normal distribution.

The Shipiro-Wilk test uses a probability plot called the QQ Plot. This scatterplot visually displays two sets of quantiles on the y-axis, arranged from smallest to largest. If each quantile came from the same distribution, the scatterplot will display a linear series of plots. The Shipiro-Wilk test uses the QQ Plot to estimate the variance. Using QQ Plot variance along with the estimated variance of the population, one can determine if the sample belongs to a normal distribution. If the quotient of both variances equal or are close to 1, then the null hypothesis can be accepted. If considerably lower than 1, it can be rejected.

## Example of a Goodness-of-Fit Test

For example, a small community gym might be operating under the assumption that it has its highest attendance on Mondays, Tuesdays and Saturdays, average attendance on Wednesdays, and Thursdays, and lowest attendance on Fridays and Sundays. Based on these assumptions, the gym employs a certain number of staff members each day to check in members, clean facilities, offer training services, and teach classes.

However, the gym is not performing well financially and the owner wants to know if these attendance assumptions and staffing levels are correct. The owner decides to count the number of gym attendees each day for six weeks. He can then compare the gym's assumed attendance with its observed attendance using a chi-square goodness-of-fit test for example. With the new data, he can determine how to best manage the gym and improve profitability.

## Goodness-of-Fit FAQs

### What Does Goodness-of-Fit Mean?

Goodness-of-Fit is a statistical hypothesis test used to see how closely observed data mirrors expected data. Goodness-of-Fit tests can help determine if a sample follows a normal distribution, if categorical variables are related, or if random samples are from the same distribution.

### Why Is Goodness-of-Fit Important?

Goodness-of-Fit tests help determine if observed data aligns with what is expected. Decisions can be made based on the outcome of the hypothesis test conducted. For example, a retailer wants to know what product offering appeals to young people. The retailer surveys a random sample of old and young people to identify which product is preferred. Using chi-square, they identify that, with 95% confidence, a relationship exists between product A and young people. Based on these results, it could be determined that this sample represents the population of young adults. Retail marketers can use this to reform their campaigns.

### What Is Goodness-of-Fit in the Chi-Square Test?

The chi-square test whether relationships exist between categorical variables and whether the sample represents the whole. It estimates how closely the observed data mirrors the expected data, or how well they fit.

### How Do You Do the Goodness-of-Fit Test?

The Goodness-of-FIt test consists of different testing methods. The goal of the test will help determine which method to use. For example, if the goal is to test normality on a relatively small sample, the Shipiro-Wilk test may be suitable. If wanting to determine whether a sample came from a specific distribution within a population, the Kolmogorov-Smirnov test will be used. Each test uses its own unique formula. However, they have commonalities, such as a null hypothesis and level of significance.

## The Bottom Line

Goodness-of-fit tests determine how well sample data fit what is expected of a population. From the sample data, an observed value is gathered and compared to the calculated expected value using a discrepancy measure. There are different goodness-of-fit hypothesis tests available depending on what outcome you're seeking.

Choosing the right goodness-of-fit test largely depends on what you want to know about a sample and how large the sample is. For example, if wanting to know if observed values for categorical data match the expected values for categorical data, use chi-square. If wanting to know if a small sample follows a normal distribution, the Shipiro-Wilk test might be advantageous. There are many tests available to determine goodness-of-fit.