x <- c(139,138,112,111)
y <- c(0.3,0.25,0.2,0.25)
a <- chisq.test(x,p=y)
print(a,digits=5)
or just
print(chisq.test(x,p=y),digits=5)
... gives:
Chi-squared test for given probabilities
data: x
X-squared = 5.1667, df = 3, p-value = 0.15999
If you look at the object chisq.test
creates:
str(a)
you'll see that it's of class htest
.
So the question is "How does the print method work for htest?"
If you look at ?print
, the generic function, you'll see some classes have the digits=
argument, which is really all you need, so you could guess to do what I originally suggested (as I did), but then since we see it's of class htest
, we can find out about it via getAnywhere
:
getAnywhere(print.htest)
and seeing it's in stats
(as would have been the obvious first guess anyway), we could also have seen the code by:
stats:::print.htest
So either of those last two show you exactly what it does, and also how to modify its behavior using print
, because you can see it definitely has the 'digits' argument. You could even write your own function if you really had a mind to.