Tidiers for cluster permutation test objects
Examples
# \donttest{
library(dplyr, warn.conflicts = FALSE)
# Specification object
spec <- make_jlmer_spec(
weight ~ 1 + Diet, filter(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
#> ────────────────────────────────────────────────────────────────────────────────
# Method for `<timewise_statistics>`
empirical_statistics <- compute_timewise_statistics(spec)
class(empirical_statistics)
#> [1] "timewise_statistics"
tidy(empirical_statistics)
#> # A tibble: 33 × 3
#> predictor time statistic
#> <chr> <dbl> <dbl>
#> 1 Diet2 0 -1.60
#> 2 Diet3 0 -1.37
#> 3 Diet4 0 -0.916
#> 4 Diet2 2 1.67
#> 5 Diet3 2 2.45
#> 6 Diet4 2 3.53
#> 7 Diet2 4 2.60
#> 8 Diet3 4 4.48
#> 9 Diet4 4 6.27
#> 10 Diet2 6 3.52
#> # ℹ 23 more rows
reset_rng_state()
null_statistics <- permute_timewise_statistics(spec, nsim = 100)
class(null_statistics)
#> [1] "timewise_statistics"
tidy(null_statistics)
#> # A tibble: 3,300 × 4
#> predictor time statistic sim
#> <chr> <dbl> <dbl> <fct>
#> 1 Diet2 0 -0.898 001
#> 2 Diet2 0 1.40 002
#> 3 Diet2 0 -1.44 003
#> 4 Diet2 0 -0.449 004
#> 5 Diet2 0 1.38 005
#> 6 Diet2 0 -0.692 006
#> 7 Diet2 0 0.113 007
#> 8 Diet2 0 0.334 008
#> 9 Diet2 0 0.558 009
#> 10 Diet2 0 -0.449 010
#> # ℹ 3,290 more rows
# Method for `<empirical_clusters>`
empirical_clusters <- extract_empirical_clusters(empirical_statistics, threshold = 2)
class(empirical_clusters)
#> [1] "empirical_clusters"
tidy(empirical_clusters)
#> # A tibble: 3 × 6
#> predictor id start end length sum_statistic
#> <chr> <fct> <dbl> <dbl> <dbl> <dbl>
#> 1 Diet2 1 4 8 3 8.50
#> 2 Diet3 1 2 20 10 34.6
#> 3 Diet4 1 2 20 10 39.4
# Method for `<null_cluster_dists>`
null_cluster_dists <- extract_null_cluster_dists(null_statistics, threshold = 2)
class(null_cluster_dists)
#> [1] "null_cluster_dists"
tidy(null_cluster_dists)
#> # A tibble: 300 × 6
#> predictor start end length sum_statistic sim
#> <chr> <dbl> <dbl> <dbl> <dbl> <fct>
#> 1 Diet2 10 20 6 14.8 001
#> 2 Diet2 NA NA NA 0 002
#> 3 Diet2 NA NA NA 0 003
#> 4 Diet2 NA NA NA 0 004
#> 5 Diet2 NA NA NA 0 005
#> 6 Diet2 NA NA NA 0 006
#> 7 Diet2 NA NA NA 0 007
#> 8 Diet2 NA NA NA 0 008
#> 9 Diet2 NA NA NA 0 009
#> 10 Diet2 NA NA NA 0 010
#> # ℹ 290 more rows
# }