Cochran-Armitage Trend Test for Binomial Data
Source:R/stepdown_binom.R
cochranArmitageTrendTest.RdPerforms a Cochran-Armitage test for trend in binomial proportions across ordered groups, with an optional Rao-Scott correction for overdispersion.
Arguments
- successes
Numeric vector of successes (e.g., number of survivors).
- totals
Numeric vector of total observations (e.g., total organisms).
- doses
Numeric vector of dose levels or scores corresponding to each observation.
- scoring
Method for defining trend
- alternative
Character string specifying the alternative hypothesis. Must be one of "two.sided" (default), "greater", or "less".
- rao_scott
Logical indicating whether to apply Rao-Scott correction for overdispersion (default: FALSE).
- phi
Overdispersion parameter for Rao-Scott correction. If NULL (default), it will be estimated from the data.
- phi_method
simple without trend adjustment or trend_adjusted.
Value
A list containing:
- statistic
Test statistic (Z score)
- p.value
P-value for the test
- method
Description of the test performed
- alternative
The alternative hypothesis
- data.name
Description of the data
- phi
Overdispersion parameter (only if rao_scott = TRUE)
Details
The Cochran-Armitage test is used to detect trends in binomial proportions across ordered groups. The test statistic follows a standard normal distribution under the null hypothesis of no trend.
When rao_scott = TRUE, the function applies a correction for overdispersion, which is often present in clustered binomial data. The correction divides the test statistic by the square root of the estimated dispersion parameter.
Examples
# Example with simulated data
successes <- c(20, 18, 15, 10, 5)
totals <- rep(20, 5)
doses <- c(0, 1, 2, 5, 10)
# Standard Cochran-Armitage test
result <- cochranArmitageTrendTest(successes, totals, doses)
print(result)
#>
#> Cochran-Armitage test for trend (doses scoring)
#>
#> data: proportions 1, 0.9, 0.75, 0.5, 0.25 at doses 0, 1, 2, 5, 10
#> = -5.7465, p-value = 9.108e-09
#> alternative hypothesis: two.sided
#>
# With Rao-Scott correction
result_rs <- cochranArmitageTrendTest(successes, totals, doses, rao_scott = TRUE)
#> Estimated phi = 8.571 using simple method with doses scoring
print(result_rs)
#>
#> Rao-Scott corrected Cochran-Armitage test for trend (doses scoring)
#>
#> data: proportions 1, 0.9, 0.75, 0.5, 0.25 at doses 0, 1, 2, 5, 10
#> = -1.9629, p-value = 0.04966
#> alternative hypothesis: two.sided
#>