Statistical tests for paired categorical variable.

paired_test_categorical(tab)

Arguments

tab

a frequency table (an integer `table`, if a `matrix` is provided, it will be coerced to a `table` internally)

Value

A list with components `P` (the computed P-value), `stat` (the test statistic, either t or F), `df` (degrees of freedom), `testname` (test name), `statname` (statistic name), `namefun` ("paired_tstat", "rep_aov"), `latexstat` (LaTeX representation of statname), `plotmathstat` (for R - the plotmath representation of `statname`, as a character string), `note` (contains a character string note about the test).

Details

If the test is requested for two paired groups, the mcnemar.test is used.

If the test is requested for more than two paired groups, the test based on Cochran-Mantel-Haenzen for repeated measures is used (powered by mantelhaen.test)

Note

This function could be used as `catTest` option in the summary.formula with method `reverse`.

Examples

# \donttest{
  library(Hmisc)

  data(Arthritis)

  ## two groups
  summary(Treatment ~ Sex,
    data = Arthritis,
    method = "reverse",
    test = TRUE,
    catTest = paired_test_categorical
  )
#> 
#> 
#> Descriptive Statistics by Treatment
#> 
#> +----------+--------------------+--------------------+------------------------------+
#> |          |Placebo             |Treated             |  Test                        |
#> |          |(N=43)              |(N=41)              |Statistic                     |
#> +----------+--------------------+--------------------+------------------------------+
#> |Sex : Male|           26%  (11)|           34%  (14)|Chi-square=5.92 d.f.=1 P=0.015|
#> +----------+--------------------+--------------------+------------------------------+

  ## more than two groups
  summary(Improved ~ Sex,
    data = Arthritis,
    method = "reverse",
    test = TRUE,
    catTest = paired_test_categorical
  )
#> 
#> 
#> Descriptive Statistics by Improved
#> 
#> +----------+-----------------+-----------------+-----------------+------------------------+
#> |          |None             |Some             |Marked           |  Test                  |
#> |          |(N=42)           |(N=14)           |(N=28)           |Statistic               |
#> +----------+-----------------+-----------------+-----------------+------------------------+
#> |Sex : Male|        40%  (17)|        14%  ( 2)|        21%  ( 6)|chi2=1.71 d.f.=3 P=0.634|
#> +----------+-----------------+-----------------+-----------------+------------------------+
# }