Search code examples
rchi-squared

R chisq.test giving different P-values


I'm running chisq.test on some data, and I'm getting some unexpected results. Essentially, chisq.test is generating 2 different P-values on the same data. In the first instance, I'm viewing the entire output of chisq.test

chisq.test(a2_survey$Q3,a2_survey$Q4)

Pearson's Chi-squared test

data:  a2_survey$Q3 and a2_survey$Q4
X-squared = 326.23, df = 25, p-value < 2.2e-16

Alternatively, I'll just request the p-value,

chisq.test(a2_survey$Q3,a2_survey$Q4)$p.value
[1] 3.161995e-54

I have run this type of test in 5 instances (where I compare outputs), and it's only this one time where my p-value results are different from one another. Does someone have thoughts on why I'm getting two different outputs?

Thanks!!


Solution

  • With chisq.test(a2_survey$Q3,a2_survey$Q4) what you have is p-value < 2.2e-16. Which simply says that p-value is less than 2.2e-16.

    The p-value is

    chisq.test(a2_survey$Q3,a2_survey$Q4)$p.value
    

    You may check this by using the X-squared and df returned by chisq.test as in

    pchisq(326.23, df=25, lower.tail=FALSE)