View source: R/liu_agresti_ccor.R
| liu_agresti_ccor | R Documentation |
Computes the Liu–Agresti estimate of the common cumulative odds ratio (\Psi) and its log (\alpha = \log \Psi) for ordinal data from two independent groups. This statistic quantifies the direction and strength of ordinal association between groups. The implementation follows Section 2 of Liu & Agresti (1996), treating the first level of group as the reference.
liu_agresti_ccor(responses, group, strata = NULL,
se = c("liu_agresti","bootstrap","naive"),
B = 1000, seed = NULL, eps = 1e-12)
responses |
A numeric vector (typically coded as consecutive integers, e.g., 1 to 5 for a Likert-type scale) or an ordered factor of ordinal item responses. Numeric inputs are internally converted to an ordered factor via |
group |
A grouping vector indicating the group to which each observation belongs. It must contain exactly two unique values (e.g., |
strata |
Optional factor/character of length |
se |
Standard-error method: |
B |
Number of bootstrap replicates when |
seed |
Optional RNG seed for bootstrap reproducibility. |
eps |
Small numerical constant for stability (avoids zero divisions). |
This function creates a contingency table of dimension 2 \times C, where C denotes the number of distinct ordinal response categories. It computes cumulative marginal frequencies and estimates the odds ratio using Liu and Agresti's formulation (1996). The variance of the log-transformed estimate is computed according to their Eq.~3.
Formally, letting cumulation be over Y \le j, and with N_k = n_{1k} + n_{2k} for stratum k, the estimator is
\widehat{\Psi}=\frac{\sum_k \sum_{j=1}^{C-1} (a_{jk} d_{jk})/N_k}{\sum_k \sum_{j=1}^{C-1} (b_{jk} c_{jk})/N_k},
with the first level of group as the reference and the second as the focal. The estimator reduces to the standard Mantel–Haenszel odds ratio when C = 2.
The estimate \widehat{\Psi} is based on cumulative frequencies and is designed for ordinal response categories. It quantifies the association between group membership and the likelihood of higher category responses.
Strata in which at least one of the two groups is completely absent are skipped in the computation of the estimator.
The function is not designed to handle missing values; observations with NA should be removed prior to use.
If one of the response categories is completely absent from one group, then the cumulative margins used in the computation may contain zero values. In such cases, either the numerator or the denominator of the Liu–Agresti formula will be zero, making the estimate numerically unstable. When this occurs, the estimate may be 0, Inf, or NaN, and users should carefully inspect the output and, if necessary, collapse sparse categories or strata.
When strata are very small or categories are extremely sparse, consider se = "bootstrap" for more robust interval estimation.
A named vector (class "liu_agresti_ccor") returning the following elements (the first three mirror the original concise summary, additional fields follow for inference):
Psi_hat |
The Liu–Agresti estimate of the common cumulative odds ratio ( |
Alpha_hat |
|
SE_log_Psi |
The standard error of |
z |
Wald statistic based on |
p_two_sided |
Two-sided p-value associated with the Wald statistic. |
CI_log_lower |
Lower bound of the 95% confidence interval for |
CI_log_upper |
Upper bound of the 95% confidence interval for |
Sebastien Beland
Faculte des sciences de l'education
Universite de Montreal (Canada)
sebastien.beland@umontreal.ca
Liu, I., & Agresti, A. (1996). Mantel–Haenszel-Type Inference for Cumulative Odds Ratios with a Stratified Ordinal Response. Biometrics, 52(4), 1223–1234.
mantelhaen.test (binary case), clm, vglm for parametric cumulative logit models.
# Simulated balanced example
set.seed(123)
group <- rep(c("ref", "foc"), each = 100)
stopifnot(length(group) == 200)
responses <- sample(1:4, size = length(group), replace = TRUE)
stopifnot(length(responses) == length(group))
liu_agresti_ccor(as.integer(responses), factor(group))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.