Skip to contents

This implements the rsm package's building-block provisions for handling sequences of experiments. We often want to join two or more designs into one blocked design for purposes of analysis.

Usage

djoin(design1, design2, ..., blkname = "Block", blocklev)
stdorder(design)

Arguments

design1

A coded.data object (must have been created by rsm 2.00 or higher).

design2

A data.frame (or coded.data) to be appended; or a call to a function that will create a design

...

Additional designs to be appended

blkname

Name to give to the blocking variable that distinguishes the designs that are joined

blocklev

Label to use in the blocking variable for the added design

design

A coded.data object to be displayed.

Details

djoin may be used to augment a design with all manner of other designs, including regular designs generated by cube and its relatives, data.frames, and other coded.data objects. The underlying paradigm is that each design joined is a separate block, and the order in which they are joined could matter.

It tries to do this in a smart way: The first design, design1, is required to be a coded.data object. If design2 is a data.frame, and variables with the coded names are not present, it is automatically coded according to design1's coding formulas. If design2 is a coded.data object, and its coding formulas differ from those of design1, then design1 is recoded with design2's codings before the designs are joined. In both cases, any variables in design2 not matched in design1 are excluded, and any design1 variables absent in design2 are added with values of NA.

Value

djoin returns a coded.data object with the combined designs, and coding formulas from the last coded.data object added. The generated blocking variable will be a factor. The designs are sorted by blocks and run.order within blocks; and its row.names will be integers corresponding to this ordering.

The function stdorder sorts such data by block and std.order within block to display the designs in their pre-randomized order.

Author

Russell V. Lenth

See also

Examples

# Some existing data
CR1 <- coded.data(ChemReact1, x1 ~ (Time - 85)/5, x2 ~ (Temp - 175)/5)
# add the second part of the experiment; it gets coded automagically
djoin(CR1, ChemReact2)
#>     Time   Temp Yield Block
#> 1  80.00 170.00  80.5     1
#> 2  80.00 180.00  81.5     1
#> 3  90.00 170.00  82.0     1
#> 4  90.00 180.00  83.5     1
#> 5  85.00 175.00  83.9     1
#> 6  85.00 175.00  84.3     1
#> 7  85.00 175.00  84.0     1
#> 8  85.00 175.00  79.7     2
#> 9  85.00 175.00  79.8     2
#> 10 85.00 175.00  79.5     2
#> 11 92.07 175.00  78.4     2
#> 12 77.93 175.00  75.6     2
#> 13 85.00 182.07  78.5     2
#> 14 85.00 167.93  77.0     2
#> 
#> Data are stored in coded form using these coding formulas ...
#> x1 ~ (Time - 85)/5
#> x2 ~ (Temp - 175)/5

# A new experiment in a different part of the design space
newdes <- cube(Yield ~ x1 + x2,  n0 = 3, 
    coding = c(x1 ~ (Time - 70)/10, x2 ~ (Temp - 180)/5))
# Time passes ... we do the experiment and plug-in the observed Yield values
newdes$Yield <- rnorm(7, 75, 3) # these are our pretend results
combined <- djoin(CR1, newdes)
# Observe that the combined dataset is recoded to the new formulas
print(combined, decode = FALSE)
#>      x1 x2    Yield Block
#> 1   1.0 -2 80.50000     1
#> 2   1.0  0 81.50000     1
#> 3   2.0 -2 82.00000     1
#> 4   2.0  0 83.50000     1
#> 5   1.5 -1 83.90000     1
#> 6   1.5 -1 84.30000     1
#> 7   1.5 -1 84.00000     1
#> 11  0.0  0 78.16627     2
#> 21  1.0 -1 72.58397     2
#> 31  0.0  0 79.78852     2
#> 41 -1.0  1 77.32797     2
#> 51 -1.0 -1 78.45627     2
#> 61  0.0  0 81.39811     2
#> 71  1.0  1 77.11079     2
#> 
#> Variable codings ...
#> x1 ~ (Time - 70)/10
#> x2 ~ (Temp - 180)/5

# List the new design in standard order
stdorder(newdes)
#>   run.order std.order Time Temp    Yield
#> 5         5         1   60  175 78.45627
#> 2         2         2   80  175 72.58397
#> 4         4         3   60  185 77.32797
#> 7         7         4   80  185 77.11079
#> 3         3         5   70  180 79.78852
#> 6         6         6   70  180 81.39811
#> 1         1         7   70  180 78.16627
#> 
#> Data are stored in coded form using these coding formulas ...
#> x1 ~ (Time - 70)/10
#> x2 ~ (Temp - 180)/5