1

Have this result from a chisq.test in R.

rslt <- chisq.test(a$x, a$y)

Pearson's Chi-squared test
data:  a$x and a$y
X-squared = 32944, df = 9, p-value < 2.2e-16

but extracting the p.value is just 0

> rslt$p.value
[1] 0

I expected to get 2.2e-16 not 0.

I also tried to unlist the rslt.

> unlist(rslt)
         statistic.X-squared                 parameter.df                      p.value                       method 
          "32943.9488257678"                          "9"                          "0" "Pearson's Chi-squared test"

but I still get 0 instead of 2.2e-16.

Is there anyway to get the information from the description or the actual value instead of the shortened value?

Thanks.

wfvdc1
  • 31
  • 3
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. Does `rslt$p.value==0` return true? Floating point numbers get weird. – MrFlick Dec 06 '19 at 21:51
  • 2
    If you [plug that chi-sq value into wolfram alpha](https://www.wolframalpha.com/input/?i=P%5BX%3E32943.9488257678%5D+for+X%7Echi+squared+with+9+dof) you get 1.01 x 10^(-7140). For all intents and purposes, that number is 0. You should reject the null hypothesis. R can't handle precision that small. – MrFlick Dec 06 '19 at 21:55

2 Answers2

2
rslt = chisq.test(cbind(c(10,20),c(30,40)))

Pearson's Chi-squared test with Yates' continuity correction

data:  cbind(c(10, 20), c(30, 40))
X-squared = 0.44643, df = 1, p-value = 0.504

we can always use the chi-sq estimate from the test, and calculate p.value. Using example above you can see they are the same.

rslt$p.value == pchisq(rslt$statistic,rslt$parameter,lower.tail=FALSE)
X-squared 


TRUE 

Using you example, as the p.value is very small, use the log:

pchisq(32943.9488257678,9,lower.tail=F,log.p=TRUE)
-16440.44
StupidWolf
  • 45,075
  • 17
  • 40
  • 72
1

It seems that your p-value is zero, which is: < 2.2e-16. Or smaller than R can handle.

SmokeyShakers
  • 3,372
  • 1
  • 7
  • 18