Skip to contents

Useful after fitting to test "synchronic" differences between groups. Within a temporal unit :

Usage

test_globally(df, x = x_pred, y = y_pred, by = group, test_fun = kruskal_p)

test_pairwise(df, x = x_pred, y = y_pred, by = group, test_fun = wilcox_p)

Arguments

df

tibble() typically the result of quake()

x, y, group

colnames to use. Default to x_pred/y_pred

by

colname for the group to use. Default to group

test_fun

function to pick among comparison_testers(comparison testers). By default kruskal_p/wilcox_p for synchrony/synchrony_pw, respectively.

Details

  • test_globally will test if at least one group differs from the others

  • test_pairwise will test all pairwise differences between groups present at that time.

Functions

  • test_globally: test for global differences

  • test_pairwise: test for pairwise differences

Examples


# for the sake of speed
x <- animals %>%
  quake(5, min=tpq, max=taq) %>%
  fit_gam(y=value, by=taxa, x_pred=seq(-100, 100, 50))
#>  * fitting with gam(value ~ s(x_new, bs = "cs"))
#>  * quake . using shake_uniform
#>  * launching 5 permutations

x %>% spaghetti(by=taxa)


# global testing
x %>% test_globally(by=taxa)
#>  * testing global differences within taxa along 5 slices using kruskal_p
#> # A tibble: 5 × 2
#>   x_pred        p
#>    <dbl>    <dbl>
#> 1   -100 0.000471
#> 2    -50 0.000471
#> 3      0 0.00196 
#> 4     50 0.000471
#> 5    100 0.000536

# pairwise testing
x %>% test_pairwise(by=taxa)
#>  * testing differences between pairs of taxa along 5 slices using wilcox_p
#> # A tibble: 30 × 3
#>    x_pred pw                 p
#>     <dbl> <chr>          <dbl>
#>  1   -100 cat ~ bird   0.00794
#>  2   -100 cat ~ mouse  0.00794
#>  3   -100 cat ~ frog   0.00794
#>  4   -100 bird ~ mouse 0.00794
#>  5   -100 bird ~ frog  0.00794
#>  6   -100 mouse ~ frog 0.00794
#>  7    -50 cat ~ bird   0.00794
#>  8    -50 cat ~ mouse  0.00794
#>  9    -50 cat ~ frog   0.00794
#> 10    -50 bird ~ mouse 0.00794
#> # … with 20 more rows

# you can filter "significant" ones
alpha=0.01
x %>%
  test_pairwise(by=taxa) %>%
  dplyr::mutate(signif=p<alpha)
#>  * testing differences between pairs of taxa along 5 slices using wilcox_p
#> # A tibble: 30 × 4
#>    x_pred pw                 p signif
#>     <dbl> <chr>          <dbl> <lgl> 
#>  1   -100 cat ~ bird   0.00794 TRUE  
#>  2   -100 cat ~ mouse  0.00794 TRUE  
#>  3   -100 cat ~ frog   0.00794 TRUE  
#>  4   -100 bird ~ mouse 0.00794 TRUE  
#>  5   -100 bird ~ frog  0.00794 TRUE  
#>  6   -100 mouse ~ frog 0.00794 TRUE  
#>  7    -50 cat ~ bird   0.00794 TRUE  
#>  8    -50 cat ~ mouse  0.00794 TRUE  
#>  9    -50 cat ~ frog   0.00794 TRUE  
#> 10    -50 bird ~ mouse 0.00794 TRUE  
#> # … with 20 more rows
  # you can continue the pipe with
  # dplyr::filter(!signif) to only get not different
  # or
  # dplyr::filter(signif) to only the different ones

# yet before, you probably need to adjust your alpha
# by the number of tests, ie do some Bonferroni correction
# the number of tests is simply dplyr::n()

x %>%
  test_pairwise(by=taxa) %>%
  dplyr::mutate(alpha_adj=alpha/dplyr::n(),
                signif=p<alpha_adj)
#>  * testing differences between pairs of taxa along 5 slices using wilcox_p
#> # A tibble: 30 × 5
#>    x_pred pw                 p alpha_adj signif
#>     <dbl> <chr>          <dbl>     <dbl> <lgl> 
#>  1   -100 cat ~ bird   0.00794  0.000333 FALSE 
#>  2   -100 cat ~ mouse  0.00794  0.000333 FALSE 
#>  3   -100 cat ~ frog   0.00794  0.000333 FALSE 
#>  4   -100 bird ~ mouse 0.00794  0.000333 FALSE 
#>  5   -100 bird ~ frog  0.00794  0.000333 FALSE 
#>  6   -100 mouse ~ frog 0.00794  0.000333 FALSE 
#>  7    -50 cat ~ bird   0.00794  0.000333 FALSE 
#>  8    -50 cat ~ mouse  0.00794  0.000333 FALSE 
#>  9    -50 cat ~ frog   0.00794  0.000333 FALSE 
#> 10    -50 bird ~ mouse 0.00794  0.000333 FALSE 
#> # … with 20 more rows