Skip to contents

This function performs the Rao-Scott adjusted Cochran-Armitage trend test for multiple injury thresholds, providing a comprehensive analysis of dose-response relationships at different severity levels.

Usage

run_all_threshold_tests(
  data,
  max_score = NULL,
  min_score = 1,
  score_cols = NULL,
  treatment_col = "tmt",
  replicate_col = "tank",
  total_col = "total",
  direction = "greater",
  alternative = "two.sided",
  include_fisher = TRUE
)

Arguments

data

A data frame containing fish injury data

max_score

Maximum score value to consider (default: NULL, auto-detected)

min_score

Minimum score value to consider (default: 1)

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)

include_fisher

Logical indicating whether to use Fisher's exact test when RSCA fails (default: TRUE)

Value

A list containing:

results

Data frame with test results for each threshold

proportions

Data frame with proportions of affected fish by treatment and threshold

detailed_results

List of detailed results for each threshold

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)
)

# Run two-sided tests for all thresholds
all_results <- run_all_threshold_tests(fish_data)
#> Warning: Some treatment groups have zero affected individuals at threshold S3+. RSCA test may not be valid.
#> Warning: Some treatment groups have zero affected individuals at threshold S4+. RSCA test may not be valid.

# Run one-sided tests (proportion increases with treatment level)
all_results_greater <- run_all_threshold_tests(
  fish_data,
  alternative = "greater"
)
#> Warning: Some treatment groups have zero affected individuals at threshold S3+. RSCA test may not be valid.
#> Warning: Some treatment groups have zero affected individuals at threshold S4+. RSCA test may not be valid.

# View results table
print(all_results$results)
#>   Threshold Z_statistic    P_value Has_zero_counts Alternative
#> 1       S1+   1.9595918 0.05004352           FALSE   two.sided
#> 2       S2+   0.5880787 0.55647949           FALSE   two.sided
#> 3       S3+          NA 0.19127234            TRUE   two.sided
#> 4       S4+          NA 1.00000000            TRUE   two.sided
#>                            Method
#> 1                RSCA (two.sided)
#> 2                RSCA (two.sided)
#> 3 Fisher's Exact Test (two.sided)
#> 4 Fisher's Exact Test (two.sided)
print(all_results_greater$results)
#>   Threshold Z_statistic    P_value Has_zero_counts Alternative
#> 1       S1+   1.9595918 0.02502176           FALSE     greater
#> 2       S2+   0.5880787 0.27823974           FALSE     greater
#> 3       S3+          NA 0.19127234            TRUE     greater
#> 4       S4+          NA 1.00000000            TRUE     greater
#>                          Method
#> 1                RSCA (greater)
#> 2                RSCA (greater)
#> 3 Fisher's Exact Test (greater)
#> 4 Fisher's Exact Test (greater)