Skip to contents

If no group of interest specified, pulls first condition against others.

Usage

get_kspval(
  df,
  value,
  group,
  goi = NULL,
  rep0 = .Machine$double.xmin,
  signed = FALSE,
  viz = FALSE
)

Arguments

df

df; has columns value and group, NA values are filtered out

value

string; colname of values to rank by

group

string; colname of categorizations

goi

group of interest value within df[,group]

rep0

numeric; value to replace 0 results with

signed

logical; TRUE to return GSEA-style enrichment score as second element of list: ks_pval[1] = pval, ks_pval[1] = ES

viz

logical; TRUE to output density plot of values

Value

Kolgomorov-Smirnov enrichment p-value & enrichment score

Details

Signed ES score adapted from franapoli/signed-ks-test which is based on GSEA enrichment score calculation. Positive ES indicates that by rank, the goi are "left" of / smaller than the rest of the values, while negative ES indicates the goi is "right" of / greater than the rest of values. Use viz = TRUE to visualize the values and resulting KS p-value.

Examples

set.seed(13)
df = data.frame(
  group = c(rep("A", 50), rep("B",50)),
  values = c(rnorm(50, mean = 0), rnorm(50, mean = 2)))
Rubrary::get_kspval(df, value = "values", group = "group", goi = "A", signed = TRUE)
#> $pval
#> [1] 8.759313e-13
#> 
#> $ES
#> [1] 0.72
#>