dae (version 3.0-32)

fac.layout: Generate a randomized layout for an experiment

Description

Warning: fac.layout will be deprecated in future versions, its synonym designRandomize being preferred.

Given a systematic design, generate a layout for an experiment consisting of randomized factors that are randomized to the unrandomized factors, taking into account the nesting between the unrandomized factors for the design.

Usage

fac.layout(unrandomized, nested.factors=NULL, except=NULL, 
                  randomized, seed=NULL, unit.permutation=TRUE)

Arguments

unrandomized

A data.frame or a list of factors, along with their levels. If a list, the name of each component of the list is a factor name and the component is either a single numeric value that is the number of levels, a numeric vector that contains the levels of the factor or a character codevector that contains the labels of the levels of the factor.

nested.factors

A list of the unrandomized factors that are nested in other factors in unrandomized. The name of each component is the name of a factor that is nested and the component is a character vector containing the factors within which it is nested. It is emphasized that the nesting is a property of the design that is being employed (it is only partly based on the intrinsic nesting.

except

A character vector containing the names unrandomized factors that are to be excepted from the randomization.

randomized

A factor or a data.frame containing the values of the factor(s) to be randomized.

seed

A single value, interpreted as an integer, that specifies the starting value of the random number generator.

unit.permutation

A logical indicating whether to include the .Unit and .Permutation columns in the data.frame.

Value

A data.frame consisting of the values for .Units and .Permutation vectors, provided unit.permutation is TRUE, along with the values for the unrandomized and randomized factors that specify the randomized layout for the experiment.

Details

This functon uses the method of randomization described by Bailey (1981). That is, a permutation of the units that respects the nesting for the design, but does not permute any of the factors in the except vector, is obtained. This permutation is applied to the unrandomized factors and then a data.frame containing both the permuted unrandomized and unpermuted randomized factors is formed. To produce the randomized layout, the rows of the joint data.frame are reordered so that its unrandomized factors are in either standard order or, if a data.frame was suppled to unrandomized, data frame order.

The .Units and .Permutation vectors enable one to swap between this permutation and the randomized layout. The ith value in .Permutation gives the unit to which unit i was assigned in the randomization.

References

Bailey, R.A. (1981) A unified approach to design of experiments. Journal of the Royal Statistical Society, Series A, 144, 214--223.

See Also

fac.gen in package dae.

Examples

Run this code
# NOT RUN {
## generate a randomized layout for a 4 x 4 Latin square
## (the nested.factors agument is not needed here as none of the 
## factors are nested)
LS.unit <- data.frame(row = ordered(rep(c("I","II","III","IV"), times=4)), 
                      col = factor(rep(c(0,2,4,6), each=4)))
LS.ran <- data.frame(treat = factor(c(1:4, 2,3,4,1, 3,4,1,2, 4,1,2,3)))
data.frame(LS.unit, LS.ran)
LS.lay <- fac.layout(unrandomized=LS.unit, randomized=LS.ran, seed=7197132) 
LS.lay[LS.lay$.Permutation,]

## generate a randomized layout for a replicated randomized complete 
## block design, with the block factors arranged in standard order for 
## rep then plot and then block
RCBD.unit <- list(rep = 2, plot=1:3, block = c("I","II"))
## specify that plot is nested in block and rep and that block is nested
## in rep
RCBD.nest <- list(plot = c("block","rep"), block="rep")
## generate treatment factor in systematic order so that they correspond
## to plot
tr <- factor(rep(1:3, each=2, times=2))
## obtain randomized layout
RCBD.lay <- fac.layout(unrandomized=RCBD.unit, 
                       nested.factors=RCBD.nest, 
                       randomized=tr, seed=9719532)
#sort into the original standard order
RCBD.perm <- RCBD.lay[RCBD.lay$.Permutation,]
#resort into randomized order
RCBD.lay <- RCBD.perm[order(RCBD.perm$.Units),]

## generate a layout for a split-unit experiment in which: 
## - the main-unit factor is A with 4 levels arranged in 
##   a randomized complete block design with 2 blocks;
## - the split-unit factor is B with 3 levels.
SPL.lay <- fac.layout(unrandomized=list(block = 2, main.unit = 4, split.unit = 3), 
                       nested.factors=list(main.unit = "block", 
                                           split.unit = c("block", "main.unit")), 
                       randomized=fac.gen(list(A = 4, B = 3), times = 2), 
                       seed=155251978, unit.permutation=FALSE)
# }

Run the code above in your browser using DataLab