qua.design {DoE.base} | R Documentation |
Function to switch between qualitative and quantitative factors and different contrast settings
Description
The function allows to switch between qualitative and quantitative factors and different contrast settings.
Usage
qua.design(design, quantitative = NA, contrasts = character(0), ...)
change.contr(design, contrasts=contr.treatment)
Arguments
design |
an experimental design,
data frame of class |
quantitative |
can be EITHER one of the single entries OR an unnamed vector of length OR a named vector (names from the factor names of the design) with
an entry |
contrasts |
only takes effect for factors for which quantitative is For customizing, a character string can be given; the names must correspond to names of factors
to be modified, and entries must be names of contrast functions.
The contrast functions are then applied to the respective factors
with the correct number of levels. |
... |
currently not used |
Details
With function qua.design
, option quantitative
has the following implications:
An experimental factor for which quantitative is TRUE
is recoded into a numeric variable.
An experimental factor for which quantitative is NA
is recoded into an R-factor
with the default contrasts given below.
An experimental factor for which quantitative is FALSE is recoded into an R-factor
with treatment contrasts (default) or with custom contrasts as indicated by the
contrasts
parameter.
If the intention is to change contrasts only, function change.contr
is a convenience interface to function qua.design
.
The default contrasts for factors in class design
objects
(exception: purely quantitative design types like lhs or rsm designs)
depend on the number and content of levels:
2-level experimental factors are coded as R-factors with -1/1 contrasts,
experimental factors with more than two quantitative (=can be coerced to numeric) levels are
coded as R factors with polynomial contrasts (with scores the numerical levels of the factor),
and qualitatitve experimental factors with more than two levels are coded
as R factors with treatment contrasts.
Note that, for 2-level factors, the default contrasts from function qua.design
differ from the default contrasts with which the factors were generated in case of
functions fac.design
or oa.design
. Thus, for recreating
the original state, it may be necessary to explicity specify the desired contrasts.
Function change.contr
makes all factors qualitative. Per default, treatment
contrasts (cf. contr.treatment
)
are assigned to all factors. The default contrasts can of course be modified.
Warning: It is possible to misuse these functions especially for designs that have been
combined from several designs. For example, while setting factors in an lhs design
(cf. lhs.design
) to
qualitative is prevented, if the lhs design has been crossed with another design of a different
type, it would be possible to make such a nonsensical modification.
Value
A data frame of class design
; the element quantitative
of attribute design.info
,
the data frame itself and the desnum
attribute are modified as appropriate.
Author(s)
Ulrike Groemping
Examples
## usage with all factors treated alike
y <- rnorm(12)
plan <- oa.design(nlevels=c(2,6,2))
lm(y~.,plan)
lm(y~., change.contr(plan)) ## with treatment contrasts instead
plan <- qua.design(plan, quantitative = "none")
lm(y~.,plan)
plan <- qua.design(plan, quantitative = "none", contrasts=c(B="contr.treatment"))
lm(y~.,plan)
plan <- qua.design(plan, quantitative = "none")
lm(y~.,plan)
plan <- qua.design(plan, quantitative = "all")
lm(y~.,plan)
plan <- qua.design(plan) ## NA resets to default state
lm(y~.,plan)
## usage with individual factors treated differently
plan <- oa.design(factor.names = list(liquid=c("type1","type2"),
dose=c(0,10,50,100,200,500), temperature=c(10,15)))
str(undesign(plan))
## Not run:
## would cause an error, since liquid is character and cannot be reasonably coerced to numeric
plan <- qua.design(plan, quantitative = "all")
## End(Not run)
plan <- qua.design(plan, quantitative = "none")
str(undesign(plan))
plan <- qua.design(plan, quantitative = c(dose=TRUE,temperature=TRUE))
str(undesign(plan))
## reset all factors to default
plan <- qua.design(plan, quantitative = NA)
str(undesign(plan))
desnum(plan)
## add a response
y <- rnorm(12)
plan <- add.response(plan,y)
## set dose to treatment contrasts
plan <- qua.design(plan, quantitative = c(dose=FALSE), contrasts=c(dose="contr.treatment"))
str(undesign(plan))
desnum(plan)