Description Usage Arguments Details Value Note Author(s) References See Also Examples
Fit a linear model with a responsesurface component, and produce appropriate analyses and summaries.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 
formula 
Formula to pass to 
data 

... 
In 
object 
An object of class 
adjust 
Adjustment to apply to the P values in the coefficient matrix, chosen from among the available 
threshold 
Threshold for canonical analysis – see Value 
x 
An object produced by 
In rsm
, the model formula must contain at least an FO
term; optionally, you can add
one or more TWI()
terms and/or a PQ()
term. All variables that appear
in TWI
or PQ
must be included in FO
.
For convenience, specifying SO()
is the same as including FO()
, TWI()
, and PQ()
,
and is the safe, preferred way of specifying a full secondorder model.
The variables in FO
comprise the variables to consider in responsesurface methods. They need not all appear in TWI
and PQ
terms; and more than one TWI
term is allowed. For example, the following two model formulas are equivalent:
1 2 
The first version, however, creates duplicate x2:x3
terms – which rsm
can handle but there may be warning messages if it is subsequently used for predictions or plotted in contour.lm
.
In summary.rsm
, any ...
arguments are passed to summary.lm
, except for threshold
, which is passed to canonical
.
rsm
returns an rsm
object, which is a lm
object with
additional members as follows:
order 
The order of the model: 1 for firstorder, 1.5 for firstorder plus interactions, or 2 for a model that contains square terms. 
b 
The firstorder responsesurface coefficients. 
B 
The matrix of secondorder responsesurface coefficients, if present. 
labels 
Labels for the responsesurface terms. These make the summary much more readable. 
coding 
Coding formulas, if provided in the 
summary
is the summary method for rsm
objects. It returns an object of class
summary.rsm
, which is an extension of the summary.lm
class with these additional list elements:
sa 
Unitlength vector of the path of steepest ascent (firstorder models only). 
canonical 
Canonical analysis (secondorder models only) from 
lof 
ANOVA table including lackoffit test. 
coding 
Coding formulas in parent 
Its print
method shows the regression summary,
followed by an ANOVA and lackoffit test. For firstorder models, it shows the direction of
steepest ascent, and for secondorder models, it shows the canonical analysis of the
response surface.
loftest
returns an anova
object that tests the fitted model against a model
that interpolates the means of the responsesurfacevariable combinations.
canonical
returns a list with elements xs
, the stationary point, and eigen
, the eigenanalysis of the matrix B of secondorder coefficients. Any eigenvalues less than threshold
are taken to be zero, thus modeling stationary ridges or valleys in their corresponding canonical directions. Setting a larger threshold
may improve the numerical conditioning and bring the stationary point much closer to the design center, thus avoiding as much extrapolation. See vignette("rsm") for more details.
xs
returns just the stationary point.
codings
returns a list
of coding formulas if the model was fitted to
coded.data
, or NULL
otherwise.
Support is provided for the emmeans package: its emmeans
and related functions work with special provisions for models fitted to coded data. The optional mode
argument can have values of "asis"
(the default), "coded"
, or "decoded"
. The first two are equivalent and simply return LS means based on the original model formula and the variables therein (raw or coded), without any conversion. When coded data were used and the user specifies mode = "decoded"
, the user must specify results in terms of the decoded variables rather than the coded ones. See the illustration in the Examples section.
Russell V. Lenth
Lenth RV (2009) “ResponseSurface Methods in R, Using rsm”, Journal of Statistical Software, 32(7), 1–17. http://www.jstatsoft.org/v32/i07/.
FO
, SO
,
lm
, summary
, coded.data
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28  library(rsm)
CR < coded.data (ChemReact, x1~(Time85)/5, x2~(Temp175)/5)
### 1storder model, using only the first block
CR.rs1 < rsm (Yield ~ FO(x1,x2), data=CR, subset=1:7)
summary(CR.rs1)
### 2ndorder model, using both blocks
CR.rs2 < rsm (Yield ~ Block + SO(x1,x2), data=CR)
summary(CR.rs2)
### Example of a risingridge situation from Montgomery et al, Table 6.2
RRex < ccd(Response~A+B, n0=c(0,3), alpha="face", randomize=FALSE, oneblock=TRUE)
RRex$Response < c(52.3, 5.3, 46.7, 44.2, 58.5, 33.5, 32.8, 49.2, 49.3, 50.2, 51.6)
RRex.rsm < rsm(Response ~ SO(A,B), data = RRex)
canonical(RRex.rsm)
canonical(RRex.rsm, threshold = 1) # xs is MUCH closer to the experiment
## Not run:
# Illustration of emmeans support
emmeans::emmeans(CR.rs2, ~ x1 * x2, mode = "coded",
at = list(x1 = c(1, 0, 1), x2 = c(2, 2)))
# The following will yield the same results:
emmeans::emmeans(CR.rs2, ~ Time * Temp, mode = "decoded",
at = list(Time = c(80, 85, 90), Temp = c(165, 185)))
## End(Not run)

Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.