Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added file on chisquare_test #5890

Merged
merged 6 commits into from
Jan 14, 2025
Merged

Conversation

Neema-Joju
Copy link
Contributor

Description

Added a new file entry on chi-square test. Improving documentation and providing more context for the users to understand.

Issue Solved

#5689

Type of Change

  • Adding a new entry
  • Updating the documentation

Checklist

  • All writings are my own.
  • My entry follows the Codecademy Docs style guide.
  • My changes generate no new warnings.
  • I have performed a self-review of my own writing and code.
  • I have checked my entry and corrected any misspellings.
  • I have made corresponding changes to the documentation if needed.
  • I have confirmed my changes are not being pushed from my forked main branch.
  • I have confirmed that I'm pushing from a new branch named after the changes I'm making.
  • I have linked any issues that are relevant to this PR in the Issues Solved section.

@mamtawardhani mamtawardhani self-assigned this Dec 26, 2024
@mamtawardhani mamtawardhani added python Python entries new entry New entry or entries status: under review Issue or PR is currently being reviewed labels Dec 26, 2024
Copy link
Collaborator

@mamtawardhani mamtawardhani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for contributing to Codecademy Docs @Neema-Joju 😄

The entry looks good for a second round of review! 🚀

@Neema-Joju
Copy link
Contributor Author

Hi @mamtawardhani
I was going through the changes made. I would like to point out a small error. The chi square test in statsmodel cannot be applied to check goodness-of-fit and test of independence. It can only be used to check if the proportions are different from the expected. I think scipy chi-square test can check goodness of fit but not the other way around.

@avdhoottt avdhoottt self-assigned this Jan 7, 2025
@avdhoottt avdhoottt added status: under review Issue or PR is currently being reviewed and removed status: ready for next review labels Jan 7, 2025
Copy link
Collaborator

@avdhoottt avdhoottt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Neema-Joju, I've suggested some changes; please make them as soon as possible. Thank you!!

Comment on lines 35 to 57
from statsmodels.stats.proportion import proportions_chisquare

# Observed counts
counts = [150, 80, 100, 70]

# Total number of observations
nobs = sum(counts)

# Perform the chi-square test
chi2, p_value, expected_table = proportions_chisquare(counts, nobs)

# Print the results
print(f"Chi-square statistic: {chi2}")
print(f"P-value: {p_value}")
print("\nExpected Counts:")
print(expected_table)

# Interpret the p-value
alpha = 0.05
if p_value < alpha:
print("\nReject the null hypothesis: The proportions are significantly different.")
else:
print("\nFail to reject the null hypothesis: The proportions are not significantly different.")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the syntax, you used the scipy.stats.chisquare function, but here you are using statsmodels.stats.proportion.proportions_chisquare; both are two different approaches, and It can confuse the viewer. Can you add the syntax of this(statsmodels.stats.proportion.proportions_chisquare) method in the syntax section above?

Copy link
Collaborator

@avdhoottt avdhoottt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!!

@avdhoottt avdhoottt merged commit c33ca88 into Codecademy:main Jan 14, 2025
7 checks passed
Copy link

👋 @Neema-Joju
You have contributed to Codecademy Docs, and we would like to know more about you and your experience.
Please take a minute to fill out this four question survey to help us better understand Docs contributions and how we can improve the experience for you and our learners.
Thank you for your help!

🎉 Your contribution(s) can be seen here:

https://www.codecademy.com/resources/docs/python/statsmodels/chi-squared-tests

Please note it may take a little while for changes to become visible.
If you're appearing as anonymous and want to be credited, visit the linked accounts page and ensure that your GitHub account is linked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants