Learn R Programming

DoE.base (version 0.23-2)

Methods for class design objects: Methods for class design objects

Description

Methods for subsetting, printing, summarizing and plotting class design objects

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, ...)
showData(dataframe,colname.bgcolor = "grey50", 
       rowname.bgcolor = "grey50", 
       body.bgcolor = "white", 
       colname.textcolor = "white", 
       rowname.textcolor = "white", 
       body.textcolor = "black",
       font = "Courier 12", 
       maxheight = 30, 
       maxwidth = 80, 
       title = NULL,
       rowname.bar = "left",
       colname.bar = "top",
       rownumbers = FALSE, 
       placement = "-20-40",
       suppress.X11.warnings = TRUE)
## S3 method for class 'default':
showData(dataframe, 
       colname.bgcolor = "grey50", 
       rowname.bgcolor = "grey50", 
       body.bgcolor = "white", 
       colname.textcolor = "white", 
       rowname.textcolor = "white", 
       body.textcolor = "black",
       font = "Courier 12", 
       maxheight = 30, 
       maxwidth = 80, 
       title = NULL,
       rowname.bar = "left",
       colname.bar = "top",
       rownumbers = FALSE, 
       placement = "-20-40",
       suppress.X11.warnings = TRUE)
## S3 method for class 'design':
showData(dataframe,
       colname.bgcolor = "grey50", 
       rowname.bgcolor = "grey50", 
       body.bgcolor = "white", 
       colname.textcolor = "white", 
       rowname.textcolor = "white", 
       body.textcolor = "black",
       font = "Courier 12", 
       maxheight = 30, 
       maxwidth = 80, 
       title = NULL,
       rowname.bar = "left",
       colname.bar = "top",
       rownumbers = FALSE, 
       placement = "-20-40",
       suppress.X11.warnings = TRUE)
## 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)
## S3 method for class 'design':
plot(x, y=NULL, select=NULL, ...)

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 t
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 d
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,
dataframe
data frame; if of S3 class design, the method for design is used, otherwise the default method
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
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
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) f
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 desig
y
a character vector of names of numeric variables in x to be plotted as responses, or a numeric response vector, or a numeric matrix containing response columns, or a data frame of numeric response variables (the latter would n
select
a vector of integers with position numbers of experimental factors, a character vector of factor letters, or a character vector of factor names for factors to be selected for plotting; select has been added in order to obtain
colname.bgcolor
as documented in relimp
rowname.bgcolor
as documented in relimp
body.bgcolor
as documented in relimp
colname.textcolor
as documented in relimp
rowname.textcolor
as documented in relimp
body.textcolor
as documented in relimp
font
as documented in relimp
maxheight
as documented in relimp
maxwidth
as documented in relimp
title
as documented in relimp
rowname.bar
as documented in relimp
colname.bar
as documented in relimp
rownumbers
as documented in relimp
placement
as documented in relimp
suppress.X11.warnings
as documented in relimp

Value

  • extractorThe 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 [object Object],[object Object],[object Object]
  • The print, summary and plot 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.

Details

Items of class design are data frames with attributes, that have been created for conducting experiments. Apart from the methods documented here, a separate file documents the method formula.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 default method for showData is the function from package relimp, which is also used in R-Commander for viewing data sets. The method for class design objects is needed for successfully using the view button of design dataframes in R-commander. They are undesigned before viewing. However, it is preferrable to inspect a printout from function print.design which provides additional information. This can also be done in the R-Commander using the Design menu in package RcmdrPlugin.DoE (to be available soon). 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). The method for plot calls the method available in package graphics (see plot.design) wherever this makes sense (x not of class design, x of class design but not following the class design structure defined in package DoE.base, and x a design with all factors being R-factors and at least one response available). Function plot.design from package graphics is not an adequate choice for designs without responses or designs with experimental factors that are not R-factors. For designs with all factors being R-factors and no response defined (e.g. a freshly-created design from function link{oa.design}), function plot.design creates a mosaic plot of the frequency table of the design, which may be quite useful to understand the structure for designs with relatively few factors (cf. example below; function plot.design calls function mosaic for this purpose). For designs with at least one experimental factor that is not an R-factor, function plot.design calls function plot.data.frame in order to create a scatter plot matrix. Currently, there is no good method for plotting designs with mixed qualitative and quantitative factors.

See Also

See also the following functions known to produce objects of class design: FrF2, pb, fac.design, oa.design, and function plot.design from package graphics; a method for function lm is described in the separate help file lm.design.

Examples

Run this code
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 for plotting designs
  ## plotting a design without response (uses function mosaic from package vcd)
  plot(oa12)
  ## equivalent to mosaic(~A+B+C, oa12)
  ## alternative order:
  mosaic(~C+A+B, oa12)
  ## using the select function: the plots show that the projection for factors 
  ## C, D and E (columns 3, 14 and 15 of the array) is a full factorial, 
  ## while A, D and E does (columns 1, 14, and 15 of the array) do not occur in 
  ## all combinations
  plot(oa.design(L24.2.13.3.1.4.1,nlevels=c(2,2,2,3,4)),select=c("E","D","A"))
  plot(oa.design(L24.2.13.3.1.4.1,nlevels=c(2,2,2,3,4)),select=c("E","D","C"))
  
  ## plotting a design with response
  y=rnorm(12)
  plot(oa12, y)
  ## plot design with a response included
  oa12.r <- add.response(oa12,y)
  plot(oa12.r)
  ## plotting a numeric design (with or without response, 
  ##   does not make statistical sense here, for demo only)
  noa12 <- qua.design(oa12, quantitative="all")
  plot(noa12, y, main="Scatter Plot Matrix")

#### 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)

Run the code above in your browser using DataLab