This augmented version of chisq.test() provides more verbose output.

xchisq.test(
  x,
  y = NULL,
  correct = TRUE,
  p = rep(1/length(x), length(x)),
  rescale.p = FALSE,
  simulate.p.value = FALSE,
  B = 2000,
  data = environment(x)
)

Arguments

x, y, correct, p, rescale.p, simulate.p.value, B

as in chisq.test(), but x may also be a formula, in which case x is replaced by tally(x, data) prior to the call to chisq.test().

data

a data frame for use when x is a formula.

See also

Examples

# Physicians' Health Study data
phs <- cbind(c(104,189),c(10933,10845)) 
rownames(phs) <- c("aspirin","placebo") 
colnames(phs) <- c("heart attack","no heart attack") 
phs 
#>         heart attack no heart attack
#> aspirin          104           10933
#> placebo          189           10845
xchisq.test(phs) 
#> 
#> 	Pearson's Chi-squared test with Yates' continuity correction
#> 
#> data:  x
#> X-squared = 24.429, df = 1, p-value = 7.71e-07
#> 
#>    104.00   10933.00 
#> (  146.52) (10890.48)
#> [12.05]  [ 0.16] 
#> <-3.51>  < 0.41> 
#>    
#>    189.00   10845.00 
#> (  146.48) (10887.52)
#> [12.05]  [ 0.16] 
#> < 3.51>  <-0.41> 
#>    
#> key:
#> 	observed
#> 	(expected)
#> 	[contribution to X-squared]
#> 	<Pearson residual>
xchisq.test(sex ~ substance, data = HELPrct)
#> 
#> 	Pearson's Chi-squared test
#> 
#> data:  x
#> X-squared = 2.0264, df = 2, p-value = 0.3631
#> 
#>    36       41       30   
#> ( 41.81) ( 35.90) ( 29.29)
#> [0.8068] [0.7236] [0.0173]
#> <-0.898> < 0.851> < 0.131>
#>      
#>   141      111       94   
#> (135.19) (116.10) ( 94.71)
#> [0.2495] [0.2238] [0.0053]
#> < 0.500> <-0.473> <-0.073>
#>      
#> key:
#> 	observed
#> 	(expected)
#> 	[contribution to X-squared]
#> 	<Pearson residual>