## Example data
dta <- data.frame(
y = gl(3, 2),
x = sample(gl(3, 2))
)
## Asymptotic Cochran-Mantel-Haenszel Test
ct <- cmh_test(y ~ x, data = dta)
## The linear statistic, i.e., the contingency table...
(T <- statistic(ct, type = "linear"))
## ...and its expectation...
(mu <- expectation(ct))
## ...and variance...
(sigma <- variance(ct))
## ...and covariance...
(Sigma <- covariance(ct))
## ...and its inverse
(SigmaPlus <- covariance(ct, invert = TRUE))
## The standardized contingency table...
(T - mu) / sqrt(sigma)
## ...is identical to the standardized linear statistic
statistic(ct, type = "standardized")
## The quadratic form...
U <- as.vector(T - mu)
U %*% SigmaPlus %*% U
## ...is identical to the test statistic
statistic(ct, type = "test")
Run the code above in your browser using DataLab