1
$\begingroup$

My understanding is that a Chi Square Goodness of Fit test and a one-proportion Z-test should have identical p-values and be equivalent (https://youtu.be/-Vssir6yUNQ?si=4-t9Np9h4bedU9xN&t=423). However, when I test them in R, they return different p-values and test statistics. Should the below code be written differently or am I misunderstanding the statistics? I am absolutely stumped why these two examples are not identical!

Reproducible example:

# Simulated data: 100 observations of a categorical variable with two levels
observed <- c(45, 55)  # Frequencies for the two categories
expected_prop <- 0.5   # Expected proportion for the first category (null hypothesis)

# Perform one proportion Z-test
prop_test <- prop.test(observed[1], n = sum(observed), p = expected_prop, alternative = "two.sided")
cat("One Proportion Z-Test:\n")
print(prop_test)

# Perform chi-square goodness of fit test
expected <- rep(sum(observed) * expected_prop, length(observed))
chi_square_test <- chisq.test(observed, p = expected, rescale.p = TRUE)
cat("\nChi-Square Goodness of Fit Test:\n")
print(chi_square_test)

Correct answer from Demetri (change correction to False):

# Load required library
library(stats)

# Simulated data: 100 observations of a categorical variable with two levels
observed <- c(45, 55)  # Frequencies for the two categories
expected_prop <- 0.5   # Expected proportion for the first category (null hypothesis)

# Perform one proportion Z-test
prop_test <- prop.test(observed[1], n = sum(observed), p = expected_prop, alternative = "two.sided", correct = F)
cat("One Proportion Z-Test:\n")
print(prop_test)

# Perform chi-square goodness of fit test
expected <- rep(sum(observed) * expected_prop, length(observed))
chi_square_test <- chisq.test(observed, p = expected, rescale.p = F)
cat("\nChi-Square Goodness of Fit Test:\n")
print(chi_square_test)
$\endgroup$
4
  • 2
    $\begingroup$ Both functions have a “correct” argument that applies a small sample correction. Could you try setting that to False and try again? $\endgroup$ Commented Sep 1, 2023 at 0:44
  • $\begingroup$ Wow, it looks like that was it! Thanks so much. I don't think I would've realized that on my own $\endgroup$
    – JElder
    Commented Sep 1, 2023 at 1:00
  • 2
    $\begingroup$ To help others who might ha e this problem, why don't you post the solution suggested by @DemetriPananos as an answer to this question? It's OK to answer your own question here. $\endgroup$
    – EdM
    Commented Sep 1, 2023 at 17:46
  • $\begingroup$ @JE52 I've posted my answer as an answer below. If this helped, please consider accepting the answer. $\endgroup$ Commented Sep 1, 2023 at 18:44

1 Answer 1

2
$\begingroup$

This is because these two functions apply a small sample correction via the correct argument. Try the following:

# Load required library
library(stats)

# Simulated data: 100 observations of a categorical variable with two levels
observed <- c(45, 55)  # Frequencies for the two categories
expected_prop <- 0.5   # Expected proportion for the first category (null hypothesis)

# Perform one proportion Z-test
prop_test <- prop.test(observed[1], n = sum(observed), p = expected_prop, alternative = "two.sided", correct = F)
cat("One Proportion Z-Test:\n")
print(prop_test)

# Perform chi-square goodness of fit test
expected <- rep(sum(observed) * expected_prop, length(observed))
chi_square_test <- chisq.test(observed, p = expected, rescale.p = F)
cat("\nChi-Square Goodness of Fit Test:\n")
print(chi_square_test)
```
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.