Skip to contents

This is a wrapper around shakers that allows to run it k times and adds and index to the resulting tibble. As the typical entry point in permutationnal analysis it also checks your data to avoid further problems.

Usage

quake(x, k = 1, shaker = shake_uniform, ...)

Arguments

x

tibble()

k

number of new datasets to create

shaker

one of the shaker functions (shake_uniform() by default)

...

arguments expected by the selected shaker function. They must be provided and named. See examples

Value

a 'shaken' tibble() with new columns and iteration index

Examples

set.seed(2329) # replicability
# shaking uniform
df_u
#> # A tibble: 8 × 5
#>     tpq   taq species site    mes
#>   <dbl> <dbl> <chr>   <chr> <dbl>
#> 1    34    43 fox     a      1.22
#> 2   -90   -46 fox     a      1.90
#> 3    87    98 fox     b      2.94
#> 4     5    32 fox     b      4.38
#> 5   -95   -85 hound   a      4.35
#> 6    42    69 hound   a      2.91
#> 7    10    50 hound   b      1.58
#> 8    27    46 hound   b      1.45
df_u %>% quake(k=5, shake_uniform, min=tpq, max=taq)
#>  * quake . using shake_uniform
#>  * launching 5 permutations
#> # A tibble: 40 × 7
#>        k   tpq   taq species site    mes x_new
#>    <int> <dbl> <dbl> <chr>   <chr> <dbl> <dbl>
#>  1     1    34    43 fox     a      1.22  40.0
#>  2     1   -90   -46 fox     a      1.90 -87.8
#>  3     1    87    98 fox     b      2.94  97.3
#>  4     1     5    32 fox     b      4.38  19.2
#>  5     1   -95   -85 hound   a      4.35 -94.8
#>  6     1    42    69 hound   a      2.91  61.2
#>  7     1    10    50 hound   b      1.58  32.0
#>  8     1    27    46 hound   b      1.45  39.1
#>  9     2    34    43 fox     a      1.22  34.7
#> 10     2   -90   -46 fox     a      1.90 -52.2
#> # … with 30 more rows
# not that you can omit shakers' argument names, providing they come in the right order
# eg:  df_u %>% quake(k=5, shake_uniform, tpq, taq)

# shaking gaussian
df_g
#> # A tibble: 8 × 5
#>     c14   sd1 species site    mes
#>   <dbl> <dbl> <chr>   <chr> <dbl>
#> 1    34     6 fox     a      1.22
#> 2   -90    18 fox     a      1.90
#> 3    87     7 fox     b      2.94
#> 4     5    12 fox     b      4.38
#> 5   -95     7 hound   a      4.35
#> 6    42    12 hound   a      2.91
#> 7    10    17 hound   b      1.58
#> 8    27    10 hound   b      1.45
df_g %>% quake(k=5, shake_gaussian, mean=c14, sd=sd1)
#>  * quake . using shake_gaussian
#>  * launching 5 permutations
#> # A tibble: 40 × 7
#>        k   c14   sd1 species site    mes  x_new
#>    <int> <dbl> <dbl> <chr>   <chr> <dbl>  <dbl>
#>  1     1    34     6 fox     a      1.22  36.2 
#>  2     1   -90    18 fox     a      1.90 -96.4 
#>  3     1    87     7 fox     b      2.94  88.3 
#>  4     1     5    12 fox     b      4.38  14.2 
#>  5     1   -95     7 hound   a      4.35 -96.7 
#>  6     1    42    12 hound   a      2.91  41.2 
#>  7     1    10    17 hound   b      1.58   7.63
#>  8     1    27    10 hound   b      1.45  38.5 
#>  9     2    34     6 fox     a      1.22  41.8 
#> 10     2   -90    18 fox     a      1.90 -84.5 
#> # … with 30 more rows

# on a more realistic dataset bigger baby:
# animals %>% quake(k=2, shake_uniform, tpq, taq)