Methods for class design objects {DoE.base}R Documentation

Methods for class design objects

Description

Methods for subsetting, aggregating, printing and summarizing class design objects. The formula, lm and plot methods are subject of a separate help page.

Usage

## S3 method for class 'design'
x[i, j, drop.attr = TRUE, drop = FALSE]
## S3 method for class 'design'
print(x, show.order=NULL, group.print=TRUE, std.order=FALSE, ...)
## S3 method for class 'design'
summary(object, brief = NULL, quote = FALSE, ...)
## S3 method for class 'design'
aggregate(x, ..., 
    by = NULL, response = NULL, FUN = "mean", postfix = NULL, replace = TRUE)

Arguments

x

data frame of S3 class design

i

indices for subsetting rows

j

indices for subsetting columns

drop.attr

logical, controls whether or not attributes are dropped; if TRUE, the result is no longer of class design, and all special design attributes are dropped; otherwise, the design attributes are adjusted to reflect the subsetting result

drop

logical that controls dropping of dimensions in the Extract function for data.frame objects, which is called by the method for class design

show.order

NULL or logical; if TRUE, the design is printed with run order information; default is TRUE for design types for which this information is helpful (see code for detail), FALSE otherwise

group.print

logical, default TRUE; if TRUE, structured designs (blocked and split-plot designs) are printed with intermediate lines at structure breaks; if FALSE, the designs are simply printed as data frames.

std.order

logical, default FALSE; if TRUE, the design is printed in standard order rather than in the randomized order.

...

further arguments to functions print, summary, aggregate, contrasts

object

data frame of S3 class design, like argument design

brief

NULL or logical; TRUE requests a printout of the design at the end of the summary output, FALSE suppresses such a printout. If brief = NULL (the default), the summary method prints the design object if it has up to 40 rows and up to 20 columns.

quote

logical; TRUE requests quoting strings in print parts of the output, FALSE suppresses quotes.

by

by variables for the data frame method of function aggregate, needed if x is not a wide design for which the special method for class design is intended

response

used for wide format designs only;
if NULL, all responses of the design are aggregated; specify names of selected responses (column names of the responselist element of the design.info attribute) for restricting the responses that are treated

FUN

a function to be used for aggregation, the default is "mean";
can be used like the FUN argument to apply

postfix

NULL implies postfixing the response name with (a character version of) FUN; a character string can be given instead for a user-defined postfix

replace

logical that decides whether an existing variable of the given name is to be replaced; the default is TRUE for convenience reasons. WARNING: If custom variables other than aggregation variables are added to wide format designs, it is recommended to use variables names that are not likely to be generated by this function.

Details

Items of class design are data frames with attributes, that have been created for conducting experiments. Apart from the methods documented here, separate files document the methods formula.design and plot.design.

The extractor method subsets the design, taking care of the attributes accordingly (cf. the value section). Subsetting can also handle replication in a limited way, although this is not first choice. Repeated measurements can be added to a design that has no proper replications, and proper replications can be added to a design that has no repeated measurements.

The method for print displays the design. Per default, the design is printed in the actual run order, and run order information is shown for designs with special structure (blocked, replicated). Optionally, the design can be printed in standard order, which may be useful for comparing to other designs or for getting a clearer idea about the structure of smaller designs.

The method for summary provides design-specific information - some further development may still be expected. If a standard data frame summary is desired, explicitly use function summary.data.frame instead of summary.

The method for aggregate provides aggregation utilities for wide format designs and links back to the method for data frames for designs that are not of wide format. If a wide format design is to be treated with the aggregate method for data frames, aggregate.data.frame must be used explicitly. This method calculates a mean, standard deviation or SN ratio from the individual responses (which can be repeated measurements or outer array runs from a Taguchi parameter design).

Value

extractor

The extractor function returns a class design object with modified attributes or a data frame without special attributes, depending on the situation.

If j is given, the function always returns a data frame without special attributes, even if drop.attr=FALSE or j=1:ncol(design).
If only i is given, the default option drop.attr=TRUE also returns a data frame without attributes.
Exception: Even for drop.attr=TRUE, if i is a permutation of the row numbers or a logical vector with all elements TRUE, the attributes are preserved, and attributes run.order and desnum are reordered along with the design, if necessary.
If drop.attr=FALSE and j is empty, the function returns an object of class design with rows of attributes run.order and desnum selected in line with those of the design itself. In this case, the new design.info attribute is a list with entries

type

resolving to “subset of design”,

subset.rows

a numeric or logical vector with the selected rows, and

orig.design.info

which contains the original design.info attribute.

The print and summary methods are called for their side effects and return NULL.

The method for aggregate returns the input wide format design with one or more additional response columns and the response.names element of the design.info attribute changed to only include the newly-added 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 the following functions known to produce objects of class design: FrF2, pb, fac.design, oa.design.
See also the following further methods for class design objects: formula.design, lm.design, plot.design.
Function plot.design from package graphics works on data frames with R factors as explanatory variables, if a numeric response is available; this function is invoked by method plot.design from this package, where appropriate.

Examples

oa12 <- oa.design(nlevels=c(2,2,6))
#### Examples for extractor function
  ## subsetting to half the runs drops all attributes per default
  oa12[1:6,]
  ## keep the attributes (usually not reasonable, but ...)
  oa12[1:6, drop.attr=FALSE]
  ## reshuffling a design
  ## (re-)randomize
  oa12[sample(12),]
  ## add repeated measurements
  oa12[rep(1:12,each=3),]
  ## add a proper replication 
  ## (does not work for blocked designs)
  oa12[c(sample(12),sample(12)),]
  ## subsetting and rbinding to loose also contrasts of factors
  str(rbind(oa12[1:2,],oa12[3:12]))
  ## keeping all non-design-related attributes like the contrasts
  str(undesign(oa12))

#### Examples print and summary
  ## rename factors and relabel levels of first two factors
  namen <- c(rep(list(c("current","new")),2),list(""))
  names(namen) <- c("First.Factor", "Second.Factor", "Third.Factor")
  factor.names(oa12) <- namen
  oa12   ### printed with the print method!

  ## add a few variables to oa12
  responses <- cbind(temp=sample(23:34),y1=rexp(12),y2=runif(12))
  oa12 <- add.response(oa12, responses)
  response.names(oa12)
  ## temp (for temperature) is not meant to be a response 
  ## --> drop it from responselist but not from data
  response.names(oa12) <- c("y1","y2")

## print design
  oa12
## look at design-specific summary
  summary(oa12)
## look at data frame style summary instead
  summary.data.frame(oa12)
  
## aggregation examples
  plan <- oa.design(nlevels=c(2,6,2), replications=2, repeat.only=TRUE)
  y <- rnorm(24)
  z <- rexp(24)
  plan <- add.response(plan, cbind(y=y,z=z))
  plan <- reptowide(plan)
  plan.mean <- aggregate(plan)
  plan.mean
  aggregate(plan, response="z")
  aggregate(plan, FUN=sd)
  aggregate(plan, FUN = function(obj) max(obj) - min(obj), postfix="range")
  ## several aggregates: add standard deviations to plan with means
  plan.mean.sd <- aggregate(plan.mean, FUN=sd)
  plan.mean.sd
  response.names(plan.mean.sd)
  ## change response.names element of design.info back to y.mean and z.mean
  ## may be needed for automatic analysis routines that have not been 
  ## created yet
  plan.mean.sd <- aggregate(plan.mean.sd, FUN=mean)
  plan.mean.sd
  response.names(plan.mean.sd)

[Package DoE.base version 1.2-4 Index]