Want to perform a chi-square goodness of fit test instead? Use the chi-square goodness-of-fit test calculator.
How to Use the Chi-Square Test Calculator
This calculator performs a chi-square test of independence using either an observed contingency table or paired raw categorical data.
If you already have data summarized in a contingency table, select the Summary Data option and follow these steps:
- Enter the significance level, α.
- Enter a name for each categorical variable.
- Edit the row and column category labels to match your variable names
- Enter the observed frequency in every cell.
- Add more rows or columns when either variable has more than two categories.
- Click Calculate.
Tip. Do not include row totals, column totals, percentages, or expected frequencies. The calculator finds these values automatically. In other words, you should only enter the observed counts inside the table.
Do you have the raw data instead and not sure how to even come up with the contingency table? This calculator allows you to perform a chi-square test from these raw values. In this case, just select the Raw Data option and follow these steps:
- Enter the significance level, α.
- Enter a name for each categorical variable.
- Enter the raw dataset in the Variable 1 and Variable 2 input fields. You should enter one observation per line, or separate entries with commas or semicolons. Spaces inside categories such as “Full-time employee” are preserved.
- Click Calculate.
In both cases, the calculator will instantly return the test statistic, p-value, critical value, and a statistical decision/conclusion. It will also provide you with a clear, step-by-step solution, showing you how to perform a chi-square test of independence manually.
What Is a Chi-Square Test?
A chi-square test of independence is a statistical test used to determine whether two categorical variables are statistically associated.
The hypotheses are:
- Null hypothesis, H0: The two categorical variables are independent.
- Alternative hypothesis, H1: The two categorical variables are not independent.
Therefore, a statistically significant result indicates an association between the two categorical variables. Here are some example research questions that can be addressed using a chi-square test of independence.
- Is employment status associated with preferred working arrangement?
- Is gender associated with preferred learning method?
- Is treatment group associated with recovery outcome?
- Is education level associated with voting preference?
- Is age group associated with product choice?
- Is smoking status associated with disease diagnosis?
Conditions of the Chi-Square Test
For a chi-square test of independence to be appropriate, the following conditions must be satisfied:
- The two independent variables should be categorical
- The data must be frequency counts
- Observations must be independent
- Expected frequencies must be sufficiently large. Specifically, no expected frequency should be below 1, and at least 80% of the expected frequencies should be at least 5.
Note. When a 2 × 2 table has small expected frequencies (expected frequency less than 5), Fisher’s exact test may be more appropriate. However, for larger tables, an exact or simulation-based procedure may be necessary. You may also combine categories, but only when the new grouping remains logically and scientifically meaningful.
When to Use a Chi-Square Test?
Use a chi-square test of independence when:
- You have two categorical variables.
- Each observation has one value for each variable.
- The data can be expressed as frequency counts.
- You want to determine whether the variables are associated.
- The observations are independent.
- The expected frequencies are sufficiently large.
Categorical variables place observations into groups. They may be nominal, such as blood type or employment status, or ordinal, such as low, moderate, and high satisfaction.
Although ordinal categories have a natural order, the standard chi-square calculation treats them as category labels. It does not use the numerical distance between the categories.
Chi-Square Test Formula
The Pearson chi-square statistic formula is: χ2 = Σ[(O − E)2/E]
Where:
- χ² is the chi-square statistic.
- O is the observed frequency in a cell.
- E is the expected frequency in the same cell.
Tip. The expected frequency is the count that would be expected in a cell if the two variables were independent. To find this value from a contingency table, use the formula: E = (Row total × Column total)/Grand total
How to do a chi-square test
To perform a chi-square test of independence by hand, you simply follow the 6 steps of hypothesis testing. To compute the test statistic, you simply start by creating a contingency table, compute row totals, column totals, and grand totals, and then compute the expected value for each cell. You finally apply the test statistic formula.
The following two examples are crafted to help you learn how to perform a chi-square test manually either from row data or summary data.
Example 1. Summary Data
A public health researcher wants to determine whether nurses’ work shifts are associated with reported job stress. The researcher selects a random sample of 140 registered nurses. Of these nurses, 80 work the day shift and 60 work the night shift. Among the day-shift nurses, 22 report experiencing high job stress, while the remainder do not report high job stress. Among the night-shift nurses, 30 do not report high job stress, while the remainder report experiencing high job stress.
Using the provided information, perform an appropriate statistical test at the 5% significance level to determine whether there is a relationship between work shift and reported job stress.
Solution
To perform the test manually, follow these steps.
Step 1: State the Hypotheses
We want to determine whether there is an association between two categorical variables:
- Work shift: Day or Night
- Reported job stress: High stress or Not high stress
Therefore, the chi-square test of independence is appropriate.
The hypotheses are:
- H₀: Work shift and reported job stress are independent.
- H₁: Work shift and reported job stress are not independent.
Step 2: State the Significance Level
We wish to test the hypothesis at the 5% significance level. Therefore, α = 0.05
Step 3: Compute the Test Statistic
To calculate the chi-square test statistic, follow these steps.
i) Create a Contingency Table
There are 80 day-shift nurses. Of these, 22 report high job stress. Therefore, 80 − 22 = 58 day-shift nurses do not report high job stress. Additionally, we’re told that there are 60 night-shift nurses. Of these, 30 do not report high job stress. This means that 60 − 30 = 30 night-shift nurses report high job stress.
Therefore, we can summarize the observed frequencies using the contingency table below.
| Work shift | High stress | Not high stress | Row total |
|---|---|---|---|
| Day shift | 22 | 58 | 80 |
| Night shift | 30 | 30 | 60 |
| Column total | 52 | 88 | 140 |
The values in the four cells (22, 58, 30, and 30) are the observed frequencies, denoted by O.
Therefore:
- O₁₁ = 22
- O₁₂ = 58
- O₂₁ = 30
- O₂₂ = 30
ii) Compute the Expected Frequencies
To calculate the expected frequency for each cell, we use the formula: E = (Row total × Column total) / Grand total
For day-shift nurses who report high job stress: E₁₁ = (80 × 52) / 140
= 29.7143
For day-shift nurses who do not report high job stress: E₁₂ = (80 × 88) / 140
= 50.2857
For night-shift nurses who report high job stress: E₂₁ = (60 × 52) / 140
= 22.2857
For night-shift nurses who do not report high job stress: E₂₂ = (60 × 88) / 140
= 37.7143
These expected frequencies can be summarized in the table below.
| Work shift | High stress | Not high stress |
|---|---|---|
| Day shift | 29.7143 | 50.2857 |
| Night shift | 22.2857 | 37.7143 |
All expected frequencies are greater than 5. Therefore, the expected-frequency requirement for the chi-square test is satisfied.
iii) Compute the Chi-Square Test Statistic
The chi-square test statistic is calculated using:
χ² = Σ[(O − E)² / E]
Substituting the observed and expected frequencies into the formula gives:
χ² = (O₁₁ − E₁₁)² / E₁₁ + (O₁₂ − E₁₂)² / E₁₂ + (O₂₁ − E₂₁)² / E₂₁ + (O₂₂ − E₂₂)² / E₂₂
= (22 − 29.7143)² / 29.7143 + (58 − 50.2857)² / 50.2857 + (30 − 22.2857)² / 22.2857 + (30 − 37.7143)² / 37.7143
= 2.0027 + 1.1834 + 2.6703 + 1.5779
Therefore, the test statistic, χ² = 7.4344
Step 4: Find the P-Value and Critical Value
Before finding the p-value and critical value, we need to calculate the degrees of freedom.
For a chi-square test of independence, the degrees of freedom formula is: df = (r − 1) × (c − 1)
where:
- r is the number of rows
- c is the number of columns
The contingency table has two rows and two columns. Therefore:
df = (2 − 1) × (2 − 1)
= 1 × 1
= 1
You can also use the degrees of freedom calculator to verify this result.
Using a chi-square to p-value calculator with χ² = 7.4344 and df = 1, the p-value is: p = 0.006399. We can also find the critical value for the test using a chi-square table or chi-square critical value calculator. This gives: χ²0.05, 1 = 3.8415
Step 5: Make the Decision
- P-Value Approach. Since the p-value (0.006399) is less than the significance level of 0.05, we reject the null hypothesis.
- Critical Value Approach. Since the chi-square test statistic (7.4344) is greater than the critical value of 3.8415, we reject the null hypothesis.
As you can see, both approaches lead to the same decision.
Step 6: Write the Conclusion
At the 5% significance level, there is sufficient evidence to conclude that work shift and reported job stress are not independent. In other words, there is a statistically significant association between the shift a nurse works and whether the nurse reports high job stress.
Verify Example 1 Using the Calculator
After creating the contingency table from the question, you can verify the results using the Chi-square test calculator. Just follow these simple steps:
- Select the Summary Data option
- Enter 0.05 as the significance level: 0.05
- Enter Variable 1 Name as Work Shift
- Enter Variable 2 Name as Reported Job Stress
- Enter 22 in the Day Shift and High Stress cell
- Enter 58 in the Day Shift and Not High Stress cell
- Enter 30 in the Night Shift and High Stress cell
- Enter 30 in the Night Shift and Not High Stress cell
- Click calculate
The calculator will instantly return the test statistic, p-value, and critical value as follows:
- χ²(1) = 7.4344
- P-value = 0.006399
- Critical value = 3.8415.
Besides the above statistics, you’ll also see a clear, step-by-step solution to help you learn how to perform the chi-square test manually using the six steps of hypothesis testing.
Example 2. Raw Data
A financial researcher wants to determine whether customers’ residential location is associated with their use of mobile banking. The researcher selects a random sample of 48 bank customers and records two categorical variables for each customer:
- Residential location: Urban or Rural
- Mobile banking use: Yes or No
The raw data are shown below.
Residential Location
Urban, Urban, Urban, Urban, Urban, Urban, Urban, Urban, Urban, Urban, Urban, Urban, Urban, Urban, Urban, Urban, Urban, Urban, Urban, Urban, Urban, Urban, Urban, Urban, Rural, Rural, Rural, Rural, Rural, Rural, Rural, Rural, Rural, Rural, Rural, Rural, Rural, Rural, Rural, Rural, Rural, Rural, Rural, Rural, Rural, Rural, Rural, Rural
Mobile Banking Use
Yes, Yes, Yes, Yes, Yes, Yes, Yes, Yes, Yes, Yes, Yes, Yes, Yes, Yes, Yes, Yes, Yes, Yes, No, No, No, No, No, No, Yes, Yes, Yes, Yes, Yes, Yes, Yes, Yes, Yes, Yes, No, No, No, No, No, No, No, No, No, No, No, No, No, No
Each residential-location value is paired with the mobile-banking value in the same position. For example, the first observation represents an urban customer who uses mobile banking. Using the provided raw data, perform an appropriate statistical test at the 5% significance level to determine whether residential location is associated with mobile banking use.
Solution
To perform the test manually, follow these steps.
Step 1: Hypotheses
We want to determine whether there is an association between two categorical variables:
- Residential location: Urban or Rural
- Mobile banking use: Yes or No
Therefore, the chi-square test of independence is appropriate.
The hypotheses are:
- H₀: Residential location and mobile banking use are independent.
- H₁: Residential location and mobile banking use are not independent.
Step 2: Significance Level
We wish to test the hypothesis at the 5% significance level. Therefore, α = 0.05
Step 3: Find the Test Statistic
To compute the chi-square test statistic from raw data, we first count the paired observations and organize them into a contingency table.
i) Formulate the Contingency Table
Counting the paired raw observations gives the following results:
- Of the 24 urban customers, 18 use mobile banking, and 6 do not.
- Of the 24 rural customers, 10 use mobile banking and 14 do not.
Therefore, the observed frequencies can be summarized as follows:
| Residential location | Yes | No | Row total |
|---|---|---|---|
| Urban | 18 | 6 | 24 |
| Rural | 10 | 14 | 24 |
| Column total | 28 | 20 | 48 |
The four values inside the table (18, 6, 10, and 14) are the observed frequencies, denoted by O.
Therefore:
- O₁₁ = 18
- O₁₂ = 6
- O₂₁ = 10
- O₂₂ = 14
ii) Calculate the Expected Frequencies
We can now compute the expected frequency for each cell using the formula: E = (Row total × Column total) / Grand total
For urban customers who use mobile banking: E₁₁ = (24 × 28) / 48
= 14
For urban customers who do not use mobile banking: E₁₂ = (24 × 20) / 48
= 10
For rural customers who use mobile banking: E₂₁ = (24 × 28) / 48
= 14
For rural customers who do not use mobile banking: E₂₂ = (24 × 20) / 48
= 10
The expected frequencies can be summarized as follows:
| Residential location | Yes | No |
|---|---|---|
| Urban | 14 | 10 |
| Rural | 14 | 10 |
All four expected frequencies are greater than 5. Therefore, the expected-frequency requirement for the chi-square test is satisfied.
iii) Find the Chi-Square Test Statistic
The chi-square test statistic formula is: χ² = Σ[(O − E)² / E]
Substituting the observed and expected frequencies into the formula gives:
χ² = (O₁₁ − E₁₁)² / E₁₁ + (O₁₂ − E₁₂)² / E₁₂ + (O₂₁ − E₂₁)² / E₂₁ + (O₂₂ − E₂₂)² / E₂₂
= (18 − 14)² / 14 + (6 − 10)² / 10 + (10 − 14)² / 14 + (14 − 10)² / 10
= 1.1429 + 1.6000 + 1.1429 + 1.6000
Therefore, the test statistic, χ² = 5.4857
Step 4: P-Value and Critical Value
Before finding the p-value and critical value, we need to calculate the degrees of freedom.
For a chi-square test of independence, the degrees of freedom formula is: df = (r − 1) × (c − 1)
where:
- r is the number of rows
- c is the number of columns
The contingency table has two rows and two columns. Therefore:
df = (2 − 1) × (2 − 1)
= 1 × 1
= 1
Using the p-value calculator and choosing the chi-square option, enter the chi-square value as χ² = 5.4857 and df = 1. The calculator will instantly return the p-value as: p = 0.019172
Using a chi-square distribution table or χ² critical value calculator with df = 1 and α = 0.05, the critical value is 3.8415
Step 5: Decision
- P-value approach: Since the p-value of 0.019172 is less than the significance level of 0.05, we reject the null hypothesis.
- Critical value approach: Since the chi-square test statistic of 5.4857 is greater than the critical value of 3.8415, we reject the null hypothesis.
Therefore, both decisions are the same as expected.
Step 6: Conclusion
At the 5% significance level, there is sufficient evidence to conclude that residential location and mobile banking use are not independent. In other words, there is a statistically significant association between where customers live and whether they use mobile banking.
Verify Example 2 Using the Calculator
You can verify the result using our Chi-Square Calculator. Just follow these steps:
- Select the Raw Data option.
- Enter 0.05 as the significance level.
- Enter Residential Location as the Variable 1 name.
- Enter Mobile Banking Use as the Variable 2 name.
- Copy and paste the data values into the Variable 1 and Variable 2 input fields
- Click Calculate.
The calculator will instantly pair the values according to their positions and automatically construct the contingency table. It will then perform the hypothesis test and return the chi-square test statistic, p-value, and critical value. It will also provide a clear, step-by-step solution showing you how the test was done using raw data.
Frequently Asked Questions
It performs Pearson’s chi-square test of independence. The calculator returns the chi-square statistic, p-value, andcritical value. It also provides a clear, step-by-step solution to help you learn how to do a chi-square test manually.
Yes. The calculator begins with a 2 × 2 table, but you can add more row and column categories. It can therefore analyze 2 × 3, 3 × 3, 3 × 4, and other contingency-table arrangements supported by the input interface.
Yes. Enter the two categorical variables in separate fields. The values are paired by position, and the calculator automatically identifies the categories and creates the contingency table.
Yes. The raw-data fields accept strings such as Male, Female, Online, Classroom, and Very satisfied. Numeric codes such as 1, 2, and 3 are treated as category labels.
For a 2 × 2 table, Fisher’s exact test may be more appropriate. Larger tables may require exact or simulation-based methods. Categories may only be combined when the new grouping remains meaningful.
Some calculators automatically apply Yates’ continuity correction to 2 × 2 tables, while others report the uncorrected Pearson statistic. Exact tests may also produce different p-values when expected counts are small. This calculator reports the standard Pearson chi-square statistic without Yates’ correction.
