|
17 | 17 | # DONE: With strata, calculate overall CMH tests controlling for strata |
18 | 18 | # FIXED: rmeans and cmeans tests were labeled incorrectly |
19 | 19 |
|
20 | | - |
21 | | - |
22 | 20 | #' Generalized Cochran-Mantel-Haenszel Tests |
23 | 21 | #' |
24 | 22 | #' Provides generalized Cochran-Mantel-Haenszel tests of association of two |
25 | 23 | #' possibly ordered factors, optionally stratified other factor(s). With |
26 | | -#' strata, \code{CMHtest} calculates these tests for each level of the |
| 24 | +#' strata, `CMHtest` calculates these tests for each level of the |
27 | 25 | #' stratifying variables and also provides overall tests controlling for the |
28 | 26 | #' strata. |
29 | 27 | #' |
|
41 | 39 | #' The CMH analysis for a two-way table produces generalized |
42 | 40 | #' Cochran-Mantel-Haenszel statistics (Landis etal., 1978). |
43 | 41 | #' |
44 | | -#' These include the CMH \bold{correlation} statistic (\code{"cor"}), treating |
| 42 | +#' These include the CMH **correlation** statistic (`"cor"`), treating |
45 | 43 | #' both factors as ordered. For a given statum, with equally spaced row and |
46 | 44 | #' column scores, this CMH statistic reduces to \eqn{(n-1) r^2}, where \eqn{r} |
47 | | -#' is the Pearson correlation between X and Y. With \code{"midrank"} scores, |
| 45 | +#' is the Pearson correlation between X and Y. With `"midrank"` scores, |
48 | 46 | #' this CMH statistic is analogous to \eqn{(n-1) r_S^2}, using the Spearman |
49 | 47 | #' rank correlation. |
50 | 48 | #' |
51 | | -#' The \bold{ANOVA} (row mean scores and column mean scores) statistics, treat |
| 49 | +#' The **ANOVA** (row mean scores and column mean scores) statistics, treat |
52 | 50 | #' the columns and rows respectively as ordinal, and are sensitive to mean |
53 | 51 | #' shifts over columns or rows. These are transforms of the \eqn{F} statistics |
54 | 52 | #' from one-way ANOVAs with equally spaced scores and to Kruskal-Wallis tests |
55 | | -#' with \code{"midrank"} scores. |
| 53 | +#' with `"midrank"` scores. |
56 | 54 | #' |
57 | | -#' The CMH \bold{general} association statistic treat both factors as |
| 55 | +#' The CMH **general** association statistic treat both factors as |
58 | 56 | #' unordered, and give a test closely related to the Pearson \eqn{\chi^2} test. |
59 | 57 | #' When there is more than one stratum, the overall general CMH statistic gives |
60 | 58 | #' a stratum-adjusted Pearson \eqn{\chi^2}, equivalent to what is calculated by |
61 | 59 | #' \code{\link[stats]{mantelhaen.test}}. |
62 | 60 | #' |
63 | 61 | #' For a 3+ way table, one table of CMH tests is produced for each combination |
64 | | -#' of the factors identified as \code{strata}. If \code{overall=TRUE}, an |
| 62 | +#' of the factors identified as `strata`. If `overall=TRUE`, an |
65 | 63 | #' additional table is calculated for the same two primary variables, |
66 | | -#' controlling for (pooling over) the \code{strata} variables. |
| 64 | +#' controlling for (pooling over) the `strata` variables. |
67 | 65 | #' |
68 | 66 | #' These overall tests implicitly assume no interactions between the primary |
69 | 67 | #' variables and the strata and they will have low power in the presence of |
|
73 | 71 | #' observations) are automatically omitted from the analysis. |
74 | 72 | #' |
75 | 73 | #' @aliases CMHtest CMHtest.formula CMHtest.default Cochran Mantel Haenszel test print.CMHtest |
76 | | -#' @param x A 2+ way contingency table in array form, or a class \code{"table"} |
| 74 | +#' @param x A 2+ way contingency table in array form, or a class `"table"` |
77 | 75 | #' object with optional category labels specified in the dimnames(x) attribute. |
78 | 76 | #' @param formula a formula specifying the variables used to create a |
79 | | -#' contingency table from \code{data}. This should be a one-sided formula when |
80 | | -#' \code{data} is in array form, and a two-sided formula with a response |
81 | | -#' \code{Freq} if \code{data} is a data frame with a cell frequency variable. |
| 77 | +#' contingency table from `data`. This should be a one-sided formula when |
| 78 | +#' `data` is in array form, and a two-sided formula with a response |
| 79 | +#' `Freq` if `data` is a data frame with a cell frequency variable. |
82 | 80 | #' For convenience, conditioning formulas can be specified indicating strata. |
83 | | -#' @param data either a data frame, or an object of class \code{"table"} or \code{"ftable"}. |
| 81 | +#' @param data either a data frame, or an object of class `"table"` or `"ftable"`. |
84 | 82 | #' @param subset an optional vector specifying a subset of observations to be used. |
85 | | -#' @param na.action a function which indicates what should happen when the data contain \code{NA}s. Ignored if \code{data} is a contingency table |
| 83 | +#' @param na.action a function which indicates what should happen when the data contain `NA`s. |
| 84 | +#' Ignored if `data` is a contingency table. |
86 | 85 | #' @param strata For a 3- or higher-way table, the names or numbers of the |
87 | 86 | #' factors to be treated as strata. By default, the first 2 factors are |
88 | 87 | #' treated as the main table variables, and all others considered stratifying factors. |
89 | 88 | #' @param rscores Row scores. Either a set of numbers (typically integers, |
90 | | -#' \code{1:R}) or the string \code{"midrank"} for standardized midrank scores, |
91 | | -#' or \code{NULL} to exclude tests that depend on row scores. |
| 89 | +#' `1:R`) or the string `"midrank"` for standardized midrank scores, |
| 90 | +#' or `NULL` to exclude tests that depend on row scores. |
92 | 91 | #' @param cscores Column scores. Same as for row scores. |
93 | | -#' @param types Types of CMH tests to compute: Any one or more of \code{c("cor", "cmeans", "rmeans", "general")}, or |
94 | | -#' \code{"ALL"} for all of these. |
| 92 | +#' @param types Types of CMH tests to compute: Any one or more of `c("cor", "cmeans", "rmeans", "general")`, or |
| 93 | +#' `"ALL"` for all of these. |
95 | 94 | #' @param overall logical. Whether to calculate overall tests, controlling for the stratifying factors. |
96 | 95 | #' @param details logical. Whether to include computational details in the result |
97 | 96 | #' @param \dots Other arguments passed to default method. |
98 | 97 | #' @param digits Digits to print. |
99 | 98 | #' |
100 | | -#' @return An object of class \code{"CMHtest"} , a list with the following 4 components: |
| 99 | +#' @return An object of class `"CMHtest"` , a list with the following 4 components: |
101 | 100 | #' |
102 | | -#' \item{table}{A matrix containing the test statistics, with columns \code{Chisq}, \code{Df} and \code{Prob} } |
| 101 | +#' \item{table}{A matrix containing the test statistics, with columns `Chisq`, `Df` and `Prob` } |
103 | 102 | #' \item{names}{The names of the table row and column variables} |
104 | 103 | #' \item{rscore}{Row scores} |
105 | 104 | #' \item{cscore}{Column scores} |
106 | 105 | #' |
107 | | -#' If \code{details==TRUE}, additional components are included. |
| 106 | +#' If `details==TRUE`, additional components are included. |
108 | 107 | #' |
109 | | -#' If there are strata, the result is a list of \code{"CMHtest"} objects. If |
110 | | -#' \code{overall=TRUE} another component, labeled \code{ALL} is appended to the |
| 108 | +#' If there are strata, the result is a list of `"CMHtest"` objects. If |
| 109 | +#' `overall=TRUE` another component, labeled `ALL` is appended to the |
111 | 110 | #' list. |
112 | 111 | #' |
113 | 112 | #' @author Michael Friendly |
|
120 | 119 | #' Cochran-Mantel-Haenszel chi-squared test of the null that two nominal |
121 | 120 | #' variables are conditionally independent in each stratum, assuming that there |
122 | 121 | #' is no three-way interaction |
| 122 | +#' @family association tests |
123 | 123 | #' |
124 | | -#' @references Stokes, M. E. & Davis, C. S. & Koch, G., (2000). |
125 | | -#' \emph{Categorical Data Analysis using the SAS System}, 2nd Ed., Cary, NC: |
| 124 | +#' @references |
| 125 | +#' Stokes, M. E. & Davis, C. S. & Koch, G., (2000). |
| 126 | +#' *Categorical Data Analysis using the SAS System*, 2nd Ed., Cary, NC: |
126 | 127 | #' SAS Institute, pp 74-75, 92-101, 124-129. Details of the computation are |
127 | | -#' given at: |
128 | | -#' \url{http://support.sas.com/documentation/cdl/en/statug/63033/HTML/default/viewer.htm#statug_freq_a0000000648.htm |
129 | | -#' } |
| 128 | +#' given at: <http://support.sas.com/documentation/cdl/en/statug/63033/HTML/default/viewer.htm#statug_freq_a0000000648.htm> |
130 | 129 | #' |
131 | 130 | #' Cochran, W. G. (1954), Some Methods for Strengthening the Common |
132 | | -#' \eqn{\chi^2} Tests, \emph{Biometrics}, 10, 417-451. |
| 131 | +#' \eqn{\chi^2} Tests, *Biometrics*, 10, 417-451. |
133 | 132 | #' |
134 | 133 | #' Landis, R. J., Heyman, E. R., and Koch, G. G. (1978). Average Partial |
135 | 134 | #' Association in Three-way Contingency Tables: A Review and Discussion of |
136 | | -#' Alternative Tests, \emph{International Statistical Review}, \bold{46}, |
| 135 | +#' Alternative Tests, *International Statistical Review*, **46**, |
137 | 136 | #' 237-254. |
138 | 137 | #' |
139 | 138 | #' Mantel, N. (1963), Chi-square Tests with One Degree of Freedom: Extensions |
140 | | -#' of the Mantel-Haenszel Procedure," \emph{Journal of the American Statistical |
141 | | -#' Association}, 58, 690-700. |
| 139 | +#' of the Mantel-Haenszel Procedure," *Journal of the American Statistical |
| 140 | +#' Association*, 58, 690-700. |
142 | 141 | #' @keywords htest |
143 | 142 | #' @export |
144 | 143 | #' @examples |
|
0 commit comments