Skip to contents

Test the probability of cluster-mass statistics over a range of threshold values

Usage

walk_threshold_steps(
  empirical_statistics,
  null_statistics,
  steps,
  top_n = Inf,
  binned = FALSE,
  add1 = TRUE,
  progress = TRUE
)

Arguments

empirical_statistics

A predictor-by-time matrix of empirical timewise statistics.

null_statistics

A simulation-by-time-by-predictor 3D array of null (permuted) timewise statistics.

steps

A vector of threshold values to test

top_n

How many clusters to return, in the order of the size of the cluster-mass statistic. Defaults to Inf which return all detected clusters.

binned

Whether the data has been aggregated/collapsed into time bins. Defaults to FALSE, which requires a cluster to span at least two time points. If TRUE, allows length-1 clusters to exist.

add1

Whether to add 1 to the numerator and denominator when calculating the p-value. Use TRUE to effectively count the observed statistic as part of the permuted null distribution (recommended with larger nsim prior to publishing results).

progress

Whether to display a progress bar

Value

A data frame of predictor clusters-mass statistics by threshold.

Examples

# \donttest{
# \dontshow{
options("jlmerclusterperm.nthreads" = 2)
jlmerclusterperm_setup(cache_dir = tempdir(), verbose = FALSE)
julia_progress(show = FALSE)
# }

# Specification object
spec <- make_jlmer_spec(
  weight ~ 1 + Diet, subset(ChickWeight, Time <= 20),
  subject = "Chick", time = "Time"
)
spec
#> ── jlmer specification ───────────────────────────────────────── <jlmer_spec> ──
#> Formula: weight ~ 1 + Diet2 + Diet3 + Diet4
#> Predictors:
#>   Diet: Diet2, Diet3, Diet4
#> Groupings:
#>   Subject: Chick
#>   Trial:
#>   Time: Time
#> Data:
#> # A tibble: 533 × 6
#>   weight Diet2 Diet3 Diet4 Chick  Time
#>    <dbl> <dbl> <dbl> <dbl> <ord> <dbl>
#> 1     42     0     0     0 1         0
#> 2     51     0     0     0 1         2
#> 3     59     0     0     0 1         4
#> # ℹ 530 more rows
#> ────────────────────────────────────────────────────────────────────────────────

# Compute timewise statistics for the observed and permuted data
empirical_statistics <- compute_timewise_statistics(spec)
null_statistics <- permute_timewise_statistics(spec, nsim = 100)

# Test cluster mass/probability under different threshold values
walk_threshold_steps(empirical_statistics, null_statistics, steps = 1:3,
                     progress = FALSE)
#> # A tibble: 9 × 8
#>   threshold predictor id    start   end length sum_statistic  pvalue
#>       <int> <chr>     <fct> <dbl> <dbl>  <dbl>         <dbl>   <dbl>
#> 1         1 Diet2     1         2    20     10         19.4  0.00990
#> 2         1 Diet3     1         2    20     10         34.6  0.00990
#> 3         1 Diet4     1         2    20     10         39.4  0.00990
#> 4         2 Diet2     1         4     8      3          8.50 0.0297 
#> 5         2 Diet3     1         2    20     10         34.6  0.00990
#> 6         2 Diet4     1         2    20     10         39.4  0.00990
#> 7         3 Diet3     1         4     8      3         12.7  0.00990
#> 8         3 Diet3     2        16    20      3         10.4  0.00990
#> 9         3 Diet4     1         2    12      6         29.7  0.00990

# \dontshow{
JuliaConnectoR::stopJulia()
# }
# }