
Stuart-Maxwell Test for Testing Marginal Homogeneity in Paired Multicategory Data
Source:R/stuartMaxwellTest.R
stuartMaxwellTest.RdA nonparametric test for marginal homogeneity in square contingency tables for dependent samples, generalizing the McNemar test to more than two categories.
Value
A list with class "htest" containing the following
components:
statisticthe value of the chi-squared test statistic.
parameterthe degrees of freedom.
p.valuethe p-value of the test.
methoda character string indicating the test performed.
data.namea character string giving the name of the data.
nthe total sample size, including categories with perfect agreement (not shown on screen).
Details
This function computes the marginal homogeneity test for a \(k \times
k\) matrix of assignments of objects to k categories or two
vectors x, y of category scores for n data objects by
two raters. The statistic is distributed as \(\chi^2\) with
k-1 degrees of freedom.
It can be viewed as an extension of the
McNemar test to \(k \times k\) table.
The null hypothesis is marginal homogeneity: for every category \(i\)
the probability of being classified into \(i\) is the same for both
classifications, \(p_{i+} = p_{+i}\). (Equality of the
cell probabilities [i, j] and [j, i] is the stronger
hypothesis of symmetry, which implies marginal homogeneity but is not
implied by it.)
If x is a matrix, it is taken as a two-dimensional contingency table,
and hence its entries should be nonnegative integers. Otherwise, both x and
y must be vectors or factors of the same length.
Incomplete cases are
removed, vectors are coerced into factors, and the contingency table is
computed from these. Since rows and columns must represent the same
categories, both are given the union of the categories observed in x
and y (those of x first): a category observed in only one of the two
classifications becomes a row or column of zeros instead of making the
table non-square. Levels observed in neither are dropped.
If there is perfect agreement for any category k, that category must be omitted in order to invert matrix S.
If for any category k, all frequencies in row k and column
k are 0, except possibly for the main diagonal element (e.g., for
perfect agreement for category k, in such cases also the
corresponding row and column marginal frequencies would be equal), then the
category is not included in the test and should be ignored, say the
Stuart-Maxwell test is performed with respect to the remaining categories
only. The degree of freedom df in this case can still be considered
k - 1, where k is the number of original categories; this
treats omitted categories as if they were included but contributed 0 to the
value of \(\chi^2\) - a reasonable view since such categories
have equal row and column marginals (see Stuart, 1955).
References
Stuart, A (1955) A test for homogeneity of the marginal distributions in a two-way classification. Biometrika, 42, 412-416.
Maxwell, A.E. (1970) Comparing the classification of subjects by two independent judges. British Journal of Psychiatry, 116, 651-655.
Agresti, A. (2002) Categorical Data Analysis. John Wiley & Sons, pp 86 ff.
UCLA OARC (Stata textbook examples), An Introduction to Categorical Analysis, Chapter 9, Section 9.3.2 (Coffee Market Share Example): https://stats.oarc.ucla.edu/stata/examples/icda/an-introduction-to-categorical-analysis-by-alan-agrestichapter-9-models-for-matched-pairs/.
See also
bhapkarTest(), mcnemar.test(), chisq.test()
Other test.categorical:
barnardTest(),
bhapkarTest(),
breslowDayTest(),
cochranQTest(),
gTest(),
lehmacherTest(),
mantelTrendTest(),
woolfTest()
Examples
# Hypothetical 3 x 3 contingency table
hyp <- as.table(matrix(c(20,3,0,10,30,5,5,15,40), nrow=3))
stuartMaxwellTest(hyp)
#>
#> Stuart-Maxwell test for marginal homogeneity
#>
#> data: hyp
#> chi-squared = 13.765, df = 2, p-value = 0.001026
#>
# same as defined with two vectors
d.hyp <- expand.grid(c("A","B","C"), c("A","B","C"))[
rep(1:9, times = hyp), ]
row.names(d.hyp) <- NULL
stuartMaxwellTest(x=d.hyp[,1], y=d.hyp[,2])
#>
#> Stuart-Maxwell test for marginal homogeneity
#>
#> data: d.hyp[, 1] and d.hyp[, 2]
#> chi-squared = 13.765, df = 2, p-value = 0.001026
#>
mc <- as.table(matrix(c(
732, 1524, 1575, 1577, 1602, 837, 1554, 1437,
1672, 1600, 841, 1363, 1385, 1484, 1524, 791), nrow=4))
stuartMaxwellTest(mc)
#>
#> Stuart-Maxwell test for marginal homogeneity
#>
#> data: mc
#> chi-squared = 0.089722, df = 3, p-value = 0.993
#>
# UCLA OARC: Coffee Market Share Example (Agresti, Chapter 9)
# Stuart-Maxwell chi-squared = 12.29, df = 4, p = 0.0153 (rounded)
coffee <- matrix(c(
93, 17, 44, 7, 10,
9, 46, 11, 0, 9,
17, 11,155, 9, 12,
6, 4, 9, 15, 2,
10, 4, 12, 2, 27
), nrow = 5, byrow = TRUE)
stuartMaxwellTest(coffee)
#>
#> Stuart-Maxwell test for marginal homogeneity
#>
#> data: coffee
#> chi-squared = 12.291, df = 4, p-value = 0.01531
#>