Return the raw, standardized or Pearson's residuals (the default) of a chi-squared test on a two-way frequency table.

chisq.residuals(tab, digits = 2, std = FALSE, raw = FALSE)

Arguments

tab

frequency table

digits

number of digits to display

std

if TRUE, returns the standardized residuals. Otherwise, returns the Pearson residuals. Incompatible with raw.

raw

if TRUE, returns the raw (observed - expected) residuals. Otherwise, returns the Pearson residuals. Incompatible with std.

Details

This function is just a wrapper around the chisq.test base R function. See this function's help page for details on the computation.

See also

Examples

## Sample table
data(Titanic)
tab <- apply(Titanic, c(1,4), sum)
## Pearson residuals
chisq.residuals(tab)
#>       Survived
#> Class     No   Yes
#>   1st  -6.61  9.57
#>   2nd  -1.87  2.70
#>   3rd   2.29 -3.32
#>   Crew  3.02 -4.37
## Standardized residuals
chisq.residuals(tab, std = TRUE)
#>       Survived
#> Class      No   Yes
#>   1st  -12.59 12.59
#>   2nd   -3.52  3.52
#>   3rd    4.89 -4.89
#>   Crew   6.87 -6.87
## Raw residuals
chisq.residuals(tab, raw = TRUE)
#>       Survived
#> Class      No    Yes
#>   1st  -98.01  98.01
#>   2nd  -25.94  25.94
#>   3rd   50.06 -50.06
#>   Crew  73.89 -73.89