Run Rao-Scott Adjusted Cochran-Armitage Trend Test for a Specific Injury Threshold
Source:R/RSCABS_AO.R
run_threshold_RSCA.RdThis function performs the Rao-Scott adjusted Cochran-Armitage trend test for a specific injury threshold, counting fish with injuries at or above that threshold as "affected".
Usage
run_threshold_RSCA(
data,
threshold,
score_cols = NULL,
treatment_col = "tmt",
replicate_col = "tank",
total_col = "total",
direction = "greater",
alternative = "two.sided"
)Arguments
- data
A data frame containing fish injury data
- threshold
Numeric value indicating the injury threshold (e.g., 1 for S1+)
- score_cols
Character vector of column names containing injury scores (default: NULL, auto-detected)
- treatment_col
Name of the column containing treatment groups (default: "tmt")
- replicate_col
Name of the column containing tank/replicate IDs (default: "tank")
- total_col
Name of the column containing total counts (default: "total")
- direction
Character string indicating threshold direction: "greater" for \ge threshold, "less" for \le threshold (default: "greater")
- alternative
Character string specifying the alternative hypothesis: "two.sided" (default), "greater" (proportion increases with treatment level), or "less" (proportion decreases with treatment level)
Value
A list containing:
- threshold
The numeric threshold value
- threshold_label
Character label for the threshold (e.g., "S1+")
- Z
Z-statistic from the RSCA test
- p_value
P-value based on the specified alternative hypothesis
- alternative
The alternative hypothesis used
- interm_values
Intermediate values from the Rao-Scott adjustment
- has_zero_counts
Logical indicating if any treatment group had zero affected individuals
- affected_counts
Data frame showing affected counts by treatment group
Examples
# Example data
fish_data <- data.frame(
tmt = rep(c("Control", "Low", "Medium", "High"), each = 3),
tank = paste0(rep(c("Control", "Low", "Medium", "High"), each = 3),
rep(1:3, times = 4)),
S0 = c(8,7,9, 6,5,7, 4,5,3, 2,3,1),
S1 = c(2,2,1, 3,4,2, 4,3,5, 4,3,5),
S2 = c(0,1,0, 1,1,1, 2,2,1, 3,3,3),
S3 = c(0,0,0, 0,0,0, 0,0,1, 1,1,1),
S4 = c(0,0,0, 0,0,0, 0,0,0, 0,0,0),
total = rep(10, 12)
)
# Two-sided test for trend in S2+ injuries
result_two_sided <- run_threshold_RSCA(fish_data, threshold = 2)
# One-sided test (proportion increases with treatment level)
result_greater <- run_threshold_RSCA(fish_data, threshold = 2,
alternative = "greater")
# One-sided test (proportion decreases with treatment level)
result_less <- run_threshold_RSCA(fish_data, threshold = 2,
alternative = "less")