Reshape designs with repeated measurements {DoE.base}R Documentation

Reshape designs with repeated measurements

Description

Convenience functions to reshape a design with repeated measurements from long to wide or vice versa

Usage

### generic function
reptowide(design, constant=NULL, ...)
reptolong(design)

Arguments

design

a data frame of S3 class design.
For function reptowide, the design must have repeated measurements (repeat.only=TRUE in design.info attribute).
For reptolong, the design must be in the wide form produced by function reptowide.

constant

NULL or character vector; if design contains variables other than the experimental factors and the block column (e.g. covariables) that do not change over repeated measurements within the same experimental unit, constant must be a character vector with the respective variable names

...

currently not used

Details

Both functions leave the design unchanged (with a warning) for all class design objects that are not of the required repeated measurements form.

If design is not of class design, an error is thrown.

The reptowide function makes use of the function reshape in package stats, the reptolong function does not.

Value

A data frame of class design with the required reshaping.

The reptowide function returns a design with one row containing all the repeated measurements for the same experimental setup (therefore wide), the reptolong function reshapes a wide design back into the long form with all repeated measurements directly underneath each other.

The attributes of the design are treated along with the data frame itself: The reptowide function resets elements of the design.info attribute (response.names, repeat.only) and adds the new elements format with value “repeatedMeasuresWide”, responselist and, if there are variables that are neither experimental factors nor responses, restlist for those of these that do change with repeated measurements. The reptolong function reinstates the original long version.

Note that the order of variables may change, if there are any variables in addition to the factors and responses.

Note

The package is currently subject to intensive development; most key functionality is now included. Some changes to input and output structures may still occur.

Author(s)

Ulrike Groemping

See Also

See Also FrF2, pb, fac.design, oa.design

Examples

    ### design without response data
    ### response variable y is added per default
    plan <- oa.design(nlevels=c(2,6,2), replication=2, repeat.only=TRUE)
    pw <- reptowide(plan)  ## make wide
    pl <- reptolong(pw)  ## make long again
    
    ### design with response and further data
    y <- rexp(24)
    temp <- rep(sample(19:30),each=2)  ## constant covariable
    prot.id <- factor(Letters[1:24]) ## non-constant character covariable
    plan.2 <- add.response(plan, y)
    plan.2$temp <- temp     ## not response
    plan.2$prot.id <- prot.id   ##not response
    plan.2
    reptowide(plan.2, constant="temp")

[Package DoE.base version 1.2-4 Index]