shuffling-functions: Basic functions for shuffling labels

Description Usage Arguments Examples

Description

These functions reflect alternative ways of shuffling labels so as to respect the constraints of the study design.

Usage

1
2
3
4
5
6
7
shuffle(.data, x)

shuffle_sync(.data, x, ...)

shuffle_each(.data, x, unit)

shuffle_each_sync(.data, x, unit, ...)

Arguments

.data

Data frame.

x

Unquoted name of factor whose levels are to be shuffled.

...

Unquoted names of factors over whose combinations the shuffling is to be synchronized.

unit

Unquoted name of variable within the levels of which the shuffling of 'x' is to be restricted.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Use shuffle for data with a single between subjects factor
d <- data.frame(group = rep(c("treatment", "control"), c(6, 6)),
                subject = 1:12)
shuffle(d, group)

shuffle_sync(three_way, A, B, C) # shuffle A over B-C
shuffle_sync(three_way, B, A, C) # shuffle B over A-C

# For multilevel data, nest any within-subject factors
# before shuffling. There should be one row per subject.
three_nest <- tidyr::nest(three_mix, A)
d <- shuffle_sync(three_nest, B, C)
# then restore
tidyr::unnest(d)

## Not run: 
# throws error because within-subject factor B introduced
# pseudoreplications
shuffle_each(two_within, A, subject)

## End(Not run)
# nest first
nested <- tidyr::nest(two_within, B)
result <- shuffle_each(nested, A, subject)
# then restore
tidyr::unnest(result)

shuffle_each_sync(three_mix, A, subject, B) # over B, ignore C
shuffle_each_sync(three_mix, A, subject, B, C) # over B:C

dalejbarr/exchangr documentation built on March 26, 2021, 9:49 p.m.