How to Present Chi-Square Test Results from Python in a Research Paper
If you’ve ever worked with categorical data, things like gender, region, preferences, or treatment outcomes, you’ve probably come across the Chi-Square test. It’s one...
If you’ve ever worked with categorical data, things like gender, region, preferences, or treatment outcomes, you’ve probably come across the Chi-Square test. It’s one...
If you’ve ever worked with categorical data, things like gender, region, preferences, or treatment outcomes, you’ve probably come across the Chi-Square test. It’s one of the most commonly used statistical methods when researchers want to know:
“Are these two categorical variables related, or is the pattern I see just due to chance?”
The Chi-Square test is perfect for situations where data is grouped into categories rather than measured on a continuous scale. Psychologists use it to compare survey responses, medical researchers use it to check treatment outcomes, and business analysts use it to test whether customer preferences vary by demographic.
Now, while the test itself is relatively straightforward, there’s another side to it: how you run the test and how you report it. This is where Python shines. Unlike manual calculations, Python lets you run the test in seconds, keep your code for reproducibility, and present your results with professional polish.
In this blog post, experts at The Academic Papers UK are going to do three things:
Let’s dive in!
When running a Chi-Square test in Python, the very first step is to bring in the libraries that make the analysis possible. Think of libraries as specialised toolkits; without them, Python on its own is a general-purpose language that doesn't know much about statistics or data analysis. For the Chi-Square test, two of the most useful libraries are pandas and scipy.stats.
The pandas library is the go-to choice for working with datasets in Python. It allows you to create data structures like DataFrames, which are essentially spreadsheets within your Python environment. Why is this important for the Chi-Square test? Because the test requires data to be arranged in a contingency table, pandas makes building, editing, and displaying such tables quick and intuitive. Instead of manually writing out nested lists or arrays, you can use pandas to clearly label rows and columns, which not only improves readability but also reduces the likelihood of errors.
Next, we need scipy.stats, a submodule of the broader SciPy library that specialises in statistical operations. This is where the real magic happens:
The chi2_contingency() function lives here, and it is the workhorse that calculates the Chi-Square statistic, p-value, degrees of freedom, and expected frequencies all in one go. Without this library, you would have to compute each of these values manually, which can be tedious and error-prone, especially with larger tables.
Get expert support interpreting your test statistic, p-value, and findings.
Together, pandas and scipy.Stats make a powerful duo. Pandas structures your data in a clean, organised way, while SciPy performs the statistical test. By importing these two libraries at the beginning of your script, you're setting up your Python environment with exactly the right tools to handle the data and generate accurate, reproducible results.
Summarising this can be done through the code:
Import pandas as pd
from scipy. Stats import chi2_contingency
Once the right libraries are in place, the next step is to prepare the dataset for analysis. For a Chi-Square test, data must be arranged in a contingency table, which is simply a table showing the frequency counts of observations across categories of two variables. For example, imagine you are studying whether gender (male/female) is related to preference for three products (A, B, and C). Your table might show how many men and women chose each product.
Creating this table in Python is straightforward with pandas, because a DataFrame works naturally as a contingency table. Each row can represent one category of the first variable (e.g., gender), while each column represents one category of the second variable (e.g., product preference). The values in the cells are the observed counts—literally, the number of people who fall into that combination.
Why is this structure so important? The Chi-Square test compares observed frequencies to expected frequencies under the assumption of independence. If your dataset is not correctly formatted, the test can't be performed, or worse, the results could be misleading. Organising the data into a contingency table ensures that the statistical function receives the information in the proper form.
Another benefit of using pandas is readability. With row and column labels, you can immediately see which variable levels correspond to each count. This makes debugging easier, and it also helps when sharing your analysis with others. Instead of a cryptic array of numbers, your table is self-explanatory, which is particularly useful for collaborative research or teaching purposes.
In short, preparing the dataset as a contingency table is not just a formality—it’s the foundation of the entire Chi-Square analysis. The Chi-Square test starts with a contingency table, a grid of observed counts across two categorical variables.
Imagine you’re testing whether gender (male/female) is related to product preference (A/B/C).
data = pd.DataFrame({
"Preference A": [30, 25],
"Preference B": [20, 30],
"Preference C": [25, 20]
}, index=["Male", "Female"])
print(data)
That gives you:
| Preference A | Preference B | Preference C | |
| Male | 30 | 20 | 25 |
| Female | 25 | 30 | 20 |
This table is all you need to run the test.
Run the Test with chi2_contingency()
Now for the fun part:
chi2, p, dof, expected = chi2_contingency(data)
print("Chi-Square Statistic:", chi2)
print("p-value:", p)
print("Degrees of Freedom:", dof)
print("Expected Frequencies:\n", expected)
The function returns:
Running the Chi-Square test in Python produces several outputs, and understanding each of them is essential for correct reporting. The first value is the Chi-Square statistic (χ²) itself. This number reflects how much the observed counts deviate from the expected counts. Larger values indicate greater differences, suggesting that the variables may not be independent. However, the statistic alone doesn’t tell you whether the difference is meaningful—that’s where the p-value comes in.
The p-value answers the question: if the variables were truly independent, what is the probability of observing differences at least this extreme? A small p-value (typically less than 0.05) indicates that the observed pattern is unlikely due to chance, and therefore, you reject the null hypothesis of independence.
The test also provides the degrees of freedom (df), which is calculated based on the size of the table using the formula (rows – 1) × (columns – 1). This value influences the shape of the Chi-Square distribution and helps determine whether the χ² statistic is large enough to be considered significant.
Finally, the function outputs the expected frequencies—the counts you would anticipate if there were no relationship between the variables. These are crucial for checking assumptions. If many expected frequencies fall below 5, the Chi-Square test may not be valid, and alternative methods (like Fisher’s Exact Test) should be considered.
Together, these outputs, χ² statistic, p-value, degrees of freedom, and expected counts, provide the complete picture. Each plays a distinct role, and knowing how to interpret them ensures your conclusions are statistically sound and academically defensible.
Let’s say you get this result:
Expected frequencies:
[[25.0, 25.0, 25.0],
[30.0, 25.0, 20.0]
Interpretation: Because p = .002, which is less than .05, there’s strong evidence of an association between gender and product preference.
If you are unsure how to run or present the Chi-Square test in your paper, get research paper help from our experts and make your work clear, accurate, and professional.



AI lacks the depth your degree requires. Our human experts deliver tailored research and authentic academic insights.
Consult with an Expert, It's freeOne of the most common challenges researchers face after running a Chi-Square test is figuring out what exactly needs to go into the write-up. Many students, and even seasoned academics, fall into the trap of reporting only the p-value and moving on. While the p-value is important, it tells only part of the story.
A complete and professional report of a Chi-Square test should include several essential components: the Chi-Square statistic, the degrees of freedom, the p-value, the effect size, and notes on whether assumptions were met. Together, these elements provide transparency and make your work reproducible.
At the heart of the test is the Chi-Square statistic, often written as χ². This number quantifies how much the observed frequencies deviate from the expected frequencies under the assumption of independence. A larger statistic means greater discrepancy, but the raw value itself isn’t meaningful until considered with the degrees of freedom. Still, reporting it is vital, as it’s the core output of the test.
Every Chi-Square test comes with degrees of freedom, calculated using the formula:
df=(r−1)(c−1)
Where r is the number of rows and c is the number of columns in the contingency table. Reporting the df is important because the Chi-Square statistic’s interpretation depends on the distribution determined by df. Without it, readers cannot verify whether your reported p-value makes sense.
The p-value is what most readers look for first. It indicates the probability of observing the data if the null hypothesis (that the two variables are independent) is true. Conventionally, if p < .05, the result is considered statistically significant. When reporting p-values, always provide the exact value (e.g., p = .032) rather than just saying “significant” or “not significant.” If the value is very small, APA and other style guides recommend writing it as p < .001.
Significance alone is not enough. A test may be statistically significant because the sample size is very large, even if the actual association is weak. That's why reporting effect size is strongly recommended. For 2x2 tables, the Phi coefficient (φ) is appropriate.
For larger tables, use Cramer’s V, calculated as:
V=underroot[χ2 / n(k−1)]
Where n is the total sample size and k is the smaller number of rows or columns. Effect sizes help readers judge the practical importance of your findings, not just whether they passed the significance threshold.
Finally, it’s good practice to mention whether the assumption regarding expected frequencies was met. The Chi-Square test assumes that all expected counts are at least 5. If this assumption is violated, results may not be reliable, and alternatives like Fisher’s Exact Test should be considered. Even if all assumptions are met, explicitly stating this reassures readers that the analysis was appropriate.
Putting It All Together
A complete report of Chi-Square results weaves these elements into a concise statement.
For example:
“A Chi-Square test of independence revealed a significant relationship between gender and product preference, χ²(2, N = 150) = 12.45, p = .002, Cramer’s V = .29. All expected frequencies were greater than 5, meeting test assumptions.”
This single sentence communicates the test statistic, degrees of freedom, sample size, p-value, effect size, and assumptions. With this information, readers have everything they need to understand and trust the results.
Therefore, in summary, it is:
1. Chi-Square Statistic (χ²): the main test statistic.
2. Degrees of Freedom (df): calculated as (rows – 1) × (columns – 1).
3. p-value: report exact values, unless they’re extremely small (then use p < .001).
4. Effect Size:
Where n is the sample size and k is the smaller number of rows or columns.
5. Expected Counts: briefly note if assumptions (expected ≥ 5) were met.
Most journals follow APA style or something similar. The key is consistency and clarity.
A Chi-Square test of independence showed a significant association between gender and product preference, χ²(2, N = 150) = 12.45, p = .002, Cramer’s V = .29.
Notice how that sentence includes everything: χ², df, sample size, p-value, and effect size.
If you have multiple categories, consider including a table like this:
| Gender | Preference A (Obs/Exp) | Preference B (Obs/Exp) | Preference C (Obs/Exp) |
| Male | 30 / 25.0 | 20 / 25.0 | 25 / 25.0 |
| Female | 25 / 30.0 | 30 / 25.0 | 20 / 20.0 |
This lets readers see where the differences come from.
Even when the Chi-Square test is correctly run, the way it’s written up can make or break a research paper. Reviewers, instructors, and examiners often notice issues not in the analysis itself but in how it is presented.
Here are some of the most frequent mistakes researchers make when reporting Chi-Square results, and how to avoid them.
Avoiding these mistakes ensures your results section is both statistically correct and academically polished, qualities that build credibility and make your research stand out.
Even seasoned researchers sometimes slip up with Chi-Square tests. Here are pitfalls to watch out for:
Need a polished and well-written paper? Get research paper writing services from our team and ensure your results are presented in the right academic style.
The Chi-Square test remains one of the most versatile tools for analysing categorical data, used across psychology, medicine, education, and business research. Running the test in Python makes the process not only efficient but also transparent and reproducible, qualities that modern research increasingly values. Yet the test itself is only half the story.
Clear, professional reporting is what transforms raw output into meaningful academic evidence. By including the Chi-Square statistic, degrees of freedom, p-value, effect size, and a statement about assumptions, researchers ensure that their results can be understood, trusted, and replicated. Ultimately, the goal of reporting is not just to show that a relationship exists but to explain its significance and strength in plain language. When done well, your Chi-Square analysis moves beyond numbers to tell a story, one that adds clarity to your research question and credibility to your work.
The Chi-Square test is a workhorse for categorical data analysis across psychology, sociology, medicine, business, and education. But running the test is only step one.
To make your research stand out:
Clear, transparent reporting isn’t just good practice; it builds credibility and trust in your findings.
Our statistics experts can explain your chi-square output and key findings.
The Chi-Square test is designed to determine whether there is a statistically significant relationship between two categorical variables. It does this by comparing observed frequencies with the frequencies you would expect if the variables were completely independent.
For example, it can test whether gender influences product choice or whether voting preferences vary by region. It’s widely used because many real-world research questions involve categorical data.
χ2=∑E(O−E)2
Where O is the observed frequency in each cell, and E is the expected frequency if the null hypothesis of independence is true. You calculate expected frequencies by multiplying row totals by column totals and dividing by the grand total. While this is manageable for small tables, it becomes cumbersome for large datasets—one reason Python is so useful.
You should use the Chi-Square test of independence whenever you want to test whether two categorical variables are related. For example, does education level influence voting behaviour? Are dietary preferences linked to age group? The key conditions are that your data are counts (not percentages) and that observations are independent of one another. If your sample is very small, however, Fisher’s Exact Test may be more appropriate.
The Chi-Square goodness-of-fit test compares observed frequencies in a single categorical variable to a theoretical distribution. For instance, you might test whether a die is fair. The independence test, by contrast, evaluates the relationship between two variables arranged in a contingency table. Both use the same basic statistic but answer different questions.
The p-value tells you the probability of observing your data, or something more extreme, if the null hypothesis of independence is true. A p-value below a threshold (often .05) means the relationship is unlikely due to chance, and you reject the null hypothesis. However, statistical significance doesn’t always mean practical significance, so effect sizes should also be reported.
The Chi-Square test is important because it provides a straightforward way to evaluate associations in categorical data, which appear in nearly every discipline. Whether it’s determining if treatments differ in medicine, preferences differ in marketing, or attitudes differ in psychology, the Chi-Square test offers a flexible, accessible method to uncover meaningful patterns in frequencies.
The test assumes that data are categorical, observations are independent, and expected cell frequencies are sufficiently large (commonly ≥ 5). Violating these assumptions can distort results. For example, small expected counts make the Chi-Square approximation less reliable. In such cases, alternatives like Fisher’s Exact Test or collapsing categories may be better options.
Not reliably. When expected counts are below 5 in more than 20% of cells, the Chi-Square test loses accuracy. For small samples, Fisher’s Exact Test provides an exact probability calculation and is often recommended. Another approach is combining categories to increase expected counts, but this should only be done if theoretically justified.
Common mistakes include applying it to continuous data without categorising, reporting only the p-value without χ² and df, or ignoring assumptions about expected counts. Another error is over-interpreting significance; finding a statistically significant result doesn’t necessarily mean the association is meaningful. Good reporting includes effect sizes, clear assumptions, and plain-language interpretations.

Book a consultation with our experts for personalised help interpreting chi-square results, checking your analysis, and presenting your conclusions clearly in your research.
Help Me Secure A+ Get a Free Consultation CallIf you want to cite this source, you can copy and paste the citation or click the Cite this article button to automatically add the citation to our free Citation Generator.
Harvey Sykes (September 22, 2025). How to Present Chi-Square Test Results from Python in a Research Paper Retrieved October 19, 2026, from https://www.theacademicpapers.co.uk/blog/2025/09/22/chi-square-test-results/
Share your requirement, expected grade, and an expert will be by your side in no time.
Yes, I want an A+