Skip to contents

Tests whether the score distribution of a single target element differs from the pooled background (everything else) via a two-sided Wilcoxon rank-sum test. Target membership is a logical column (e.g. is_HAR, the whole column is the target) or a value on a categorical column (e.g. gene_name == "FOXP2", that value vs every other). This is the single-element case of av_calc_shift, which sweeps every element of a column; both share one engine, so a single av_calc_shift row equals the matching av_compare_target call.

Usage

av_compare_target(
  obj,
  target_col,
  target_value = TRUE,
  abs_score = TRUE,
  balance_by = NULL,
  per = "variant_id",
  min_n = 5L
)

Arguments

obj

An AlphaVarSet object.

target_col

Character. Column that defines the target element.

target_value

Value to treat as the target. Default TRUE (logical columns); for categorical columns supply the specific element.

abs_score

Logical. If TRUE (default), uses absolute scores.

balance_by

Character or NULL. When set, collapses each arm to one balanced value per unit per (two-step weighted mean over balance_by) before testing, so an over-represented track variable (e.g. output_type) cannot dominate. Must differ from per and target_col.

per

Character. Unit (replication) unit for balance_by; default "variant_id". The (per, across) unit variable of the framework. When a per unit straddles several elements of target_col (a per-track column), the test becomes a paired Wilcoxon signed-rank blocked by per. Ignored when balance_by is NULL.

min_n

Minimum n per arm (default 5). Elements below it are dropped.

Value

The updated AlphaVarSet with results at obj$stats$comparisons[[<key>]]: <key> is paste0(target_col, "_vs_rest") for logical columns or paste0(target_col, "=", target_value) otherwise. The entry is a list (method, global_p, results_tidy, params, dropped_groups); results_tidy carries group, n_group, n_rest, median_group, median_rest, median_diff, p_val, p_adj, effect_size (rank-biserial r, or matched rank-biserial r when paired), significance_stars. The list also carries global_effect / global_effect_type for the omnibus.

See also

av_calc_shift for the all-element sweep.

Examples

example_file <- system.file("extdata", "bcl11a_rs1427407_example.csv", package = "AlphaVaR")
obj <- av_import_csv(example_file)
#> Reading bcl11a_rs1427407_example.csv ...

# ATAC tracks against every other modality.
obj <- av_compare_target(obj, target_col = "output_type", target_value = "ATAC")
obj$stats$comparisons[["output_type=ATAC"]]$results_tidy
#> # A tibble: 1 × 12
#>   group n_group n_rest median_group median_rest median_diff p_val p_adj
#>   <chr>   <int>  <int>        <dbl>       <dbl>       <dbl> <dbl> <dbl>
#> 1 ATAC      320   2356        0.814       0.454       0.360     0     0
#> # ℹ 4 more variables: effect_size <dbl>, effect_type <chr>, method <chr>,
#> #   significance_stars <chr>

# Collapsing each arm to one value per biosample matches the arms, so the
# track-level Mann-Whitney becomes a paired signed-rank test.
obj <- av_compare_target(obj, target_col = "output_type", target_value = "ATAC",
                         balance_by = "variant_id", per = "biosample_name")
#> Warning: Dropped 4 of 2676 rows with NA in 'output_type', 'quantile_score', 'variant_id', or 'biosample_name'.
res <- obj$stats$comparisons[["output_type=ATAC"]]
res$method
#> [1] "Wilcoxon signed-rank One-vs-Rest (BH) [balanced by variant_id per biosample_name]"
res$results_tidy
#> # A tibble: 1 × 12
#>   group n_group n_rest median_group median_rest median_diff    p_val    p_adj
#>   <chr>   <int>  <int>        <dbl>       <dbl>       <dbl>    <dbl>    <dbl>
#> 1 ATAC       69     69        0.686       0.416       0.289 2.05e-11 2.05e-11
#> # ℹ 4 more variables: effect_size <dbl>, effect_type <chr>, method <chr>,
#> #   significance_stars <chr>