block.random() from the psych library is a good tool for creating block-randomized experimental designs, however, the function as-written requires that you do some calculations before you can start, and generates a matrix that only includes numerical indices for the levels of your experimental factors.
An example plant growth experiment, with the kind of information you typically know when setting out to do an experimental design:
- two experimental factors, say fertilizer and sunlight
- three levels of fertilizer (5mL/day, 10mL/day, 20mL/day)
- two levels of sunlight (direct sun, shade)
- your power analysis tells you you need 15 samples per group
You’d use block.random in the following way:
> plan=block.random(n=90,c(fertilizer=3,sunlight=2))
> headtail(plan)
blocks fertilizer sunlight
S1 1 3 2
S2 1 2 1
S3 1 3 1
S4 1 1 1
... ... ... ...
S87 15 3 2
S88 15 2 1
S89 15 1 1
S90 15 1 2
OK great, but two problems:
- You’ve got to realize that you need 90 total samples before you can use the function (15 per group, times 3 levels of fertilizer, times 2 levels of sunlight) this is a trivial problem to solve
- You can’t necessarily use the output directly, as you’ve got to correlate the numeric levels of the factors (1:3 for fertilizer, 1:2 for sunlight) to your actual levels (5mL/day, 10mL/day, 20mL/day for fertilizer) and (direct sun, shade for sunlight)
I’d rather have something including my level names that I can just directly print for reference or quickly format as a table for inclusion into a report.
How can I accomplish this?
With a simple wrapper function for
block.random(), all of the above is possible.usage is like so:
you can also set a seed for reproducibility:
create.randomization.plan(15, factors, seed=123)