Methods for class design objects {DoE.base} | R Documentation |
Methods for subsetting, printing, summarizing and plotting class design objects
## S3 method for class 'design': x[i, j, drop.attr = TRUE, drop = FALSE] ## S3 method for class 'design': print(x, show.order=NULL, ...) 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) ## Default S3 method: 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, ...) ## 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, ...)
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 |
... |
further arguments to functions print , summary , aggregate ,
contrasts , or in case of plotting,
plot , mosaic , or the function plot.design from package graphics |
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 |
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. |
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 not work when directly
using function plot.design from package graphics) |
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 manageable plot sizes. For example,
mosaic plots are most easily readible for up to three or at most four factors.
Main effects plots with too many factors may also be hard to read because of overlapping
labeling.select can also be used for bringing the factors into a desirable order. |
colname.bgcolor |
|
rowname.bgcolor |
|
body.bgcolor |
|
colname.textcolor |
|
rowname.textcolor |
|
body.textcolor |
|
font |
|
maxheight |
|
maxwidth |
|
title |
|
rowname.bar |
|
colname.bar |
|
rownumbers |
|
placement |
|
suppress.X11.warnings |
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 methods for print
or summary
provide design-specific information -
especially the summary
method will develop further. 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.
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.
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
|
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.
The package is currently subject to intensive development; most key functionality is now included. Some changes to input and output structures may still occur.
Ulrike Groemping
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
.
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)