rsmformula: Functions for supporting response surface analysis with...

View source: R/rsmformula.R

rsmformulaR Documentation

Functions for supporting response surface analysis with package rsm

Description

These functions support response surface analysis with package rsm. Function rsmformula creates a model formula for use with function rsm, using the FO, TWI and PQ notation. Function code.design prepares a fractional factorial 2-level design with center points from package FrF2 or a ccd, bbd or lhs design from this package for convenient use with package rsm functionality, function decode.design reverses the coding action.

Usage

code.design(design)
decode.design(design)
rsmformula(design, response=NULL, factor.names=NULL, 
    use.blockvar = TRUE, degree=2, coded=TRUE, ...)

Arguments

design

a response surface design of class design with at least one response variable and of a type derived from ccd, bbd, or lhs

response

character string specifying the response variable to be analysed (default: the first response of the design)

factor.names

character vector specifying the factors to be included (default: all experimental factors)

use.blockvar

logical indicating whether or not the block effect (if available) is to be included into the model

degree

default is 2 for a full second order model. For a first order only model, specify 1; for a model with main effects and 2-factor interactions, specify 1.5. degree corresponds to the order element of the object created by function rsm.

coded

logical indicating whether the formula is to be provided in coded names (x1, x2 etc., coded=TRUE) or original variable names (coded=FALSE)

...

reserved for future usage

Details

Function code.design rescales the variables of a design with quantitative variables according to the information stored in the coding element of the design.info attribute of design, function decode.design rescales a coded design to original units.

Function rsmformula creates a formula for use with function rsm. If this function is created in coded variable names (which is the default), it can be used in function rsm together with the coded data object created by function code.design for creating a response surface model, which can be post-processed by the utilities provided in package rsm, especially the [rsm:rsm]{methods} for class rsm objects and functions steepest or canonical.path.

IMPORTANT: coded vs. original units
The text below assumes that the design has been entered using the default.levels or the factor.names option to specify the factor levels in original units.
The usual steepest ascent analysis is done in coded units, i.e. if e.g. factor X1 has original units 10 (code -1 = (10-20)/10) and 30 (code +1 = (30-20)/10) and factor X2 has original units 0.1 (code -1 = (0.1 - 0.2)/0.1) and 0.3 (code +1 = (0.3 - 0.2)/0.1), an increase of 10 for a change in factor X1 from 10 to 30 is considered steeper (slope 10/2) than an increase of 9 for a change in factor X2 from 0.1 to 0.3 (slope 9/2). If this behavior is desired, usage of rsmformula with option coded=TRUE and a design generated by code.design is needed.
Otherwise, i.e. when assessment is desired in original units, the ascent for factor X2 (9/0.2) would of course be much steeper than for factor X1 (10/20) in the above example. For obtaining an assessment based on the original units, one can simply use rsmformula with option coded=FALSE and the design itself in original units in the rsm model. This only makes sense for first order models: function steepest always assesses the slope at the origin; for first order models, it does not matter where the slope is assessed. For models with order (=degree) 1.5 or 2, the steepest analysis in original units is adequate only for the exceptional case that 0 is the point of interest.

Value

Function code.design returns a coded.data object for usage with function rsm; this object can be returned to its original state by applying function decode.design.

Function rsmformula returns a formula with an FO (=first order) portion, for degree=1.5 additionally a TWI (=two factor interactions, 2fis) portion, and for degree=2 also a PQ (=pure quadratic) portion.

This representation of the model formula is needed for response surface analyses with package rsm. Per default, the formula comes in coded variable names (x1, x2 etc.).

Note

This package is still under (slow) development. Reports about bugs and inconveniences are welcome.

Author(s)

Ulrike Groemping

References

Lenth, R.V. (2009). Response-Surface Methods in R, using rsm. Journal of Statistical Software 32(7), 1-17. URLhttp://www.jstatsoft.org/v32/i07/.

Myers, R.H., Montgomery, D.C. and Anderson-Cook, C.M. (2009). Response Surface Methodology. Process and Product Optimization Using Designed Experiments. Wiley, New York.

See Also

See also rsm, steepest, canonical.path, contour.lm, . The formula method for class design objects creates equivalent model formulae in standard model notation.

Examples

  ## an artificial example with random response
  ## purely for demonstrating how the functions work together with rsm
  plan <- ccd.design(5, ncenter=6, 
         factor.names = list(one=c(10,30),two=c(1,5),three=c(0.1,0.9),
                             four=c(2,4),five=c(-1,1)))
  set.seed(298)
  plan <- add.response(plan, rnorm(38))
  
  ## coding
  plan.c <- code.design(plan)
  plan.c
  decode.design(plan.c)
  
  ## first order analysis
     ## formulae needed for first order models:
    rsmformula(plan, degree=1)                ## coded
    rsmformula(plan, degree=1, coded=FALSE)   ## original units
    
    ## steepest ascent: steepness assessed in coded units, 
    ## results also presented in original units
    linmod1 <- rsm(rsmformula(plan, degree=1), data=plan.c)
    summary(linmod1)
    steepest(linmod1)
    
    ## steepest ascent: steepness assessed in original units!!! 
    ## this is different from the usual approach!!! 
    ## cf. explanation in Details section
    linmod1.original <- rsm(rsmformula(plan, degree=1, coded=FALSE), data=plan)
    summary(linmod1.original)
    steepest(linmod1.original)

  ## second order analysis (including quadratic, degree=1.5 would omit quadratic
    ## formulae needed for second order models:
    rsmformula(plan, degree=2)               ## coded
    rsmformula(plan, degree=2, coded=FALSE)  ## original units
       ## the formulae can also be constructed analogously to the FO formulae 
       ## by using SO instead of FO
       ## rsmformula returns the more detailed function because 
       ##     it can be more easily modified to omit one of the effects
    
    ## the stationary point is not affected by using coded or original units
    ##     neither is the decision about the nature of the stationary point
    ## a subsequent canonical path analysis will however be affected,
    ##     analogously to the steepest ascent (cf. Details section)
    
    ## analysis in coded units
    linmod2 <- rsm(rsmformula(plan, degree=2), data=plan.c)
    summary(linmod2)
    ## analysis in original units
    linmod2.original <- rsm(rsmformula(plan, degree=2, coded=FALSE), data=plan)
    summary(linmod2.original)
    ## the contour plot may be nicer when using original units
    contour(linmod2, form=~x1*x2)
    contour(linmod2.original, form=~one*two)
    ## the canonical path is usually more reasonable in coded units
    canonical.path(linmod2)            ## coded units
    canonical.path(linmod2.original)   ## original units
    
    ## analogous analysis without the special formula notation of function rsm
    linmod <- rsm(rnorm.38. ~ Block.ccd + (one + two + three + four + five)^2 + 
          I(one^2) + I(two^2) + I(three^2) + I(four^2) + I(five^2), data=plan)
    summary(linmod)
    contour(linmod, form=~one*two)  ## contour plot is possible
    ## steepest or canonical.path cannot be used, 
    ## because the model is a conventional lm
 
    ## contour will not work on the convenience model
    ## lm(plan), which is otherwise identical to linmod
    ## (it will neither work on lm(formula(plan), plan))
    ## or lm(rsmformula(plan), plan)
   

DoE.wrapper documentation built on Aug. 21, 2023, 5:10 p.m.