Skip to contents

This function assigns specific treatment or unit levels to actual units.

Usage

assign_trts(
  .edibble = NULL,
  order = "random",
  seed = NULL,
  constrain = nesting_structure(.edibble),
  ...,
  .record = TRUE
)

assign_units(
  .edibble = NULL,
  order = "random",
  seed = NULL,
  constrain = nesting_structure(.edibble),
  ...,
  .record = TRUE
)

Arguments

.edibble

An edibble design which should have units, treatments and allotment defined.

order

A character vector signifying the apportion of treatments to units. The value should be either "random", "systematic-fastest", "systematic-slowest", "systematic-random-fastest", "systematic-random-slowest" or a class name corresponding to the algorithm for order_trts(). "random" allocates the treatment randomly to units based on specified allotment with restrictions implied by unit structure. "systematic-slowest" allocates the treatment in a systematic order to units such that the treatment level is slow in varying. In contrast, "systematic-fastest" is fast in varying for treatment levels. "systematic-random-fastest" and "systematic-random-slowest" allocates the treatment in a systematic order to units but where it is not possible to divide treatments equally (as the number of units are not divisible by the number of levels of the treatment factor), then the extras are chosen randomly.

seed

A scalar value used to set the seed so that the result is reproducible.

constrain

The nesting structure for units.

...

Arguments parsed into order_trts functions.

.record

Whether to record the step.

Value

An edibble design.

Examples

# 10 subject, 2 vaccine treatments
design() %>%
  set_units(subject = 10) %>%
  set_trts(vaccine = 2) %>%
  allot_trts(vaccine ~ subject) %>%
  assign_trts() %>%
  serve_table()
#> # An edibble: 10 x 2
#>      subject  vaccine
#>      <U(10)>   <T(2)>
#>        <chr>    <chr>
#>  1 subject01 vaccine1
#>  2 subject02 vaccine2
#>  3 subject03 vaccine1
#>  4 subject04 vaccine2
#>  5 subject05 vaccine1
#>  6 subject06 vaccine1
#>  7 subject07 vaccine2
#>  8 subject08 vaccine2
#>  9 subject09 vaccine2
#> 10 subject10 vaccine1

# 20 subjects, 2 blocks, assign subjects to blocks
design() %>%
  set_units(subject = 20,
            block = 2) %>%
  allot_units(block ~ subject) %>%
  assign_units() %>%
  serve_table()
#> # An edibble: 20 x 2
#>      subject  block
#>      <U(20)> <U(2)>
#>        <chr>  <chr>
#>  1 subject01 block1
#>  2 subject02 block2
#>  3 subject03 block1
#>  4 subject04 block2
#>  5 subject05 block2
#>  6 subject06 block1
#>  7 subject07 block1
#>  8 subject08 block2
#>  9 subject09 block2
#> 10 subject10 block1
#> 11 subject11 block1
#> 12 subject12 block2
#> 13 subject13 block2
#> 14 subject14 block1
#> 15 subject15 block1
#> 16 subject16 block2
#> 17 subject17 block1
#> 18 subject18 block2
#> 19 subject19 block1
#> 20 subject20 block2