Learn R Programming

coin (version 1.0-24)

MarginalHomogeneityTest: Marginal Homogeneity Test

Description

Testing marginal homogeneity in a complete block design.

Usage

## S3 method for class 'formula':
mh_test(formula, data, subset = NULL, \dots)
## S3 method for class 'table':
mh_test(object, ...)
## S3 method for class 'SymmetryProblem':
mh_test(object, distribution = c("asymptotic", "approximate"), ...)

Arguments

formula
a formula of the form y ~ x | block where y is a factor giving the data values and x a factor with two or more levels giving the corresponding replications. block is an optional factor (
data
an optional data frame containing the variables in the model formula.
subset
an optional vector specifying a subset of observations to be used.
object
an object inheriting from class SymmetryProblem or a table with identical dimnames attributes.
distribution
a character, the null distribution of the test statistic can be approximated by its asymptotic distribution (asymptotic) or via Monte-Carlo resampling (approximate). Alternatively, the functions
...
further arguments to be passed to or from methods.

Value

  • An object inheriting from class IndependenceTest with methods show, pvalue and statistic.

Details

The null hypothesis of independence of row and column totals is tested. The corresponding test for binary factors x and y is known as McNemar test. For larger tables, Stuart's $W_0$ statistic (Stuart, 1955, Agresti, 2002, page 422, also known as Stuart-Maxwell test) is computed. The marginal homogeneity statistic $W$ of Bhapkar (1966) can be derived from $W_0$ via $W = W_0 / (1 - W_0 / n)$ (see Agresti, 2002, page 422).

Scores must be a list of length one (row and column scores coincide). When scores are given or if x is ordered, the corresponding linear association test is computed (see Agresti, 2002).

Note that for a large number of observations, this function is rather inefficient.

References

Alan Agresti (2002). Categorical Data Analysis. Hoboken, New Jersey: John Wiley & Sons.

V. P. Bhapkar (1966). A note on the equivalence of two test criteria for hypotheses in categorical data. Journal of the American Statistical Association 61, 228--235.

Alan Stuart (1955). A test for homogeneity of the marginal distributions in a two-way classification. Biometrika 42(3/4), 412--416.

Examples

Run this code
### Opinions on Pre- and Extramarital Sex, Agresti (2002), page 421
  opinions <- c("always wrong", "almost always wrong", 
                "wrong only sometimes", "not wrong at all")

  PreExSex <- as.table(matrix(c(144, 33, 84, 126, 
                                  2,  4, 14,  29, 
                                  0,  2,  6,  25, 
                                  0,  0,  1,  5), nrow = 4, 
                              dimnames = list(PremaritalSex = opinions,
                                              ExtramaritalSex = opinions)))

  ### treating response as nominal
  mh_test(PreExSex)

  ### and as ordinal
  mh_test(PreExSex, scores = list(response = 1:length(opinions)))

  ### example taken from 
  ### http://ourworld.compuserve.com/homepages/jsuebersax/mcnemar.htm
  rating <- c("low", "moderate", "high")
  x <- as.table(matrix(c(20, 10,  5,
                         3, 30, 15,
                         0,  5, 40), 
                       ncol = 3, byrow = TRUE,
                       dimnames = list(Rater1 = rating, Rater2 = rating)))
  ### test statistic W_0 = 13.76
  mh_test(x)

Run the code above in your browser using DataLab