1\name{optimum}
2\Rdversion{1.1}
3\alias{optimum}
4\keyword{Multiple Response Optimization}
5\keyword{Six Sigma}
6\title{
7Optimal factor settings
8}
9\description{
10Calculates the best factors settings with regard to defined desirabilities and constraints.\cr
11Two approaches are currently supported, (I) evaluating (all) possible factor settings and (II) using the function \code{\link{optim}} or \code{gosolnp} of the \code{Rsolnp} package.\cr
12Using optim \code{\link{optim}} initial values for the factors to be optimized over can be set via start.\cr
13The optimality of the solution depends critically on the starting parameters which is why it is recommended to use \sQuote{type="gosolnp"} although calculation takes a while.
14}
15\usage{
16optimum(fdo, constraints, steps = 25, type = "grid", start, ...)
17}
18\arguments{
19  \item{fdo}{
20  an object of class \code{\link{facDesign}} with \code{\link{fits}} and \code{\link{desires}} set.
21}
22  \item{constraints}{
23constraints for the factors such as list(A = c(-2,1), B = c(0, 0.8)).
24}
25  \item{steps}{
26number of grid points per factor if type = \dQuote{grid}.
27}
28  \item{type}{
29type of search. \dQuote{grid},\dQuote{optim} or \dQuote{gosolnp} are supported (see DESCRIPTION).
30}
31  \item{start}{
32numerical vector giving the initial values for the factors to be optimized over.
33}
34
35  \item{\dots}{
36further aguments.
37}
38}
39\details{
40It is recommened to use \sQuote{type="gosolnp"}. Derringer and Suich (1994) desirabilities do not have continuous first derivatives, more precisely they have points where their derivatives do not exist,\cr
41start should be defined in cases where \sQuote{type = "optim"} fails to calculate the best factor setting.
42}
43\value{
44\code{optimum} returns an object of class desOpt.
45}
46
47\author{
48Thomas Roth \email{thomas.roth@tu-berlin.de}
49}
50
51\note{
52 For a  example which shows the usage of \code{optimum()} in context please read the vignette for the package
53 \code{\link{qualityTools}} at \url{http://www.r-qualitytools.org/html/Improve.html}.
54}
55
56\seealso{
57\code{\link{optim}}\cr
58\code{\link{desirability}} \cr
59\code{\link{desires}}         \cr
60\code{\link[Rsolnp]{gosolnp}}    \cr
61\url{http://www.r-qualitytools.org/html/Improve.html}
62}
63\examples{
64#BEWARE BIG EXAMPLE --Simultaneous Optimization of Several Response Variables--
65#Source: DERRINGER, George; SUICH, Ronald: Simultaneous Optimization of Several
66#        Response Variables. Journal of Quality Technology Vol. 12, No. 4,
67#        p. 214-219
68
69#Define the response suface design as given in the paper and sort via
70#Standard Order
71fdo = rsmDesign(k = 3, alpha = 1.633, cc = 0, cs = 6)
72fdo = randomize(fdo, so = TRUE)
73
74#Attaching the 4 responses
75y1 = c(102,120,117,198,103,132,132,139,102,154,96,163,116,153,133,133,140,142,
76       145,142)
77y2 = c(900,860,800,2294,490,1289,1270,1090,770,1690,700,1540,2184,1784,1300,
78       1300,1145,1090,1260,1344)
79y3 = c(470,410,570,240,640,270,410,380,590,260,520,380,520,290,380,380,430,
80       430,390,390)
81y4 = c(67.5,65,77.5,74.5,62.5,67,78,70,76 ,70,63 ,75,65,71 ,70,68.5,68,68,69,
82       70)
83response(fdo) = data.frame(y1, y2, y3, y4)[c(5,2,3,8,1,6,7,4,9:20),]
84
85#setting names and real values of the factors
86names(fdo) = c("silica", "silan", "sulfur")
87highs(fdo) = c(1.7, 60, 2.8)
88lows(fdo) = c(0.7, 40, 1.8)
89
90#summary of the response surface design
91summary(fdo)
92
93#setting the desires
94desires(fdo) = desirability(y1, 120, 170, scale = c(1,1), target = "max")
95desires(fdo) = desirability(y2, 1000, 1300, target = "max")
96desires(fdo) = desirability(y3, 400, 600, target = 500)
97desires(fdo) = desirability(y4, 60, 75, target = 67.5)
98desires(fdo)
99
100#Have a look at some contourPlots
101par(mfrow = c(2,2))
102contourPlot(A, B, y1, data = fdo)
103contourPlot(A, B, y2, data = fdo)
104wirePlot(A, B, y1, data = fdo)
105wirePlot(A, B, y2, data = fdo)
106
107
108#setting the fits as in the paper
109fits(fdo) = lm(y1 ~ A + B + C + A:B + A:C + B:C + I(A^2) + I(B^2) + I(C^2),
110               data = fdo)
111fits(fdo) = lm(y2 ~ A + B + C + A:B + A:C + B:C + I(A^2) + I(B^2) + I(C^2),
112               data = fdo)
113fits(fdo) = lm(y3 ~ A + B + C + A:B + A:C + B:C + I(A^2) + I(B^2) + I(C^2),
114               data = fdo)
115fits(fdo) = lm(y4 ~ A + B + C + A:B + A:C + B:C + I(A^2) + I(B^2) + I(C^2),
116               data = fdo)
117#fits(fdo)
118
119#calculate the same best factor settings as in the paper using type = "optim"
120optimum(fdo, type = "optim")
121
122#calculate (nearly) the same best factor settings as in the paper using type = "grid"
123optimum(fdo, type = "grid")
124}