Un laboratorio produce biodiésel por transesterificación alcalina de aceite de palma refinado con metanol, catalizada por hidróxido de potasio (KOH). Se desea encontrar la temperatura y la concentración de catalizador que maximizan el rendimiento en ésteres metílicos de ácidos grasos (FAME).
Durante todos los ensayos se mantuvieron constantes:
El rendimiento se determinó por cromatografía de gases según la norma EN 14103 y se expresa en % m/m.
Se estudiaron dos factores con un diseño central compuesto rotable (\(\alpha = \sqrt{2} \approx 1{,}414\)): 4 puntos factoriales, 4 puntos axiales y 5 réplicas en el punto central, es decir, 13 corridas realizadas en orden aleatorio.
Las variables codificadas se definen como:
\[ x_1 = \frac{T - 55{,}0\ ^{\circ}\mathrm{C}}{6{,}0\ ^{\circ}\mathrm{C}} \qquad\qquad x_2 = \frac{\mathrm{KOH} - 1{,}00\,\%}{0{,}35\,\%} \]
La temperatura máxima (63,5 °C) se mantiene por debajo del punto de ebullición del metanol (64,7 °C).
Nota. Los datos son didácticos: se simularon a partir de un modelo cuadrático conocido más un error experimental realista (DE ≈ 0,35 %).
library(rsm)
## Warning: package 'rsm' was built under R version 4.5.3
alfa <- sqrt(2)
biodiesel <- data.frame(
Corrida = 1:13,
Tipo = c(rep("Factorial", 4), rep("Axial", 4), rep("Centro", 5)),
x1 = c(-1, 1, -1, 1, -alfa, alfa, 0, 0, 0, 0, 0, 0, 0),
x2 = c(-1, -1, 1, 1, 0, 0, -alfa, alfa, 0, 0, 0, 0, 0),
y = c(83.6, 89.8, 88.5, 90.5, 86.8, 91.7, 85.8, 90.1,
94.0, 93.6, 93.7, 93.9, 93.5)
)
# Conversión de variables codificadas a unidades reales
biodiesel$Temperatura <- 55.0 + 6.0 * biodiesel$x1 # °C
biodiesel$KOH <- 1.00 + 0.35 * biodiesel$x2 # % m/m
# Orden de columnas para presentación
biodiesel <- biodiesel[, c("Corrida", "Tipo", "x1", "x2",
"Temperatura", "KOH", "y")]
biodiesel
## Corrida Tipo x1 x2 Temperatura KOH y
## 1 1 Factorial -1.000000 -1.000000 49.00000 0.6500000 83.6
## 2 2 Factorial 1.000000 -1.000000 61.00000 0.6500000 89.8
## 3 3 Factorial -1.000000 1.000000 49.00000 1.3500000 88.5
## 4 4 Factorial 1.000000 1.000000 61.00000 1.3500000 90.5
## 5 5 Axial -1.414214 0.000000 46.51472 1.0000000 86.8
## 6 6 Axial 1.414214 0.000000 63.48528 1.0000000 91.7
## 7 7 Axial 0.000000 -1.414214 55.00000 0.5050253 85.8
## 8 8 Axial 0.000000 1.414214 55.00000 1.4949747 90.1
## 9 9 Centro 0.000000 0.000000 55.00000 1.0000000 94.0
## 10 10 Centro 0.000000 0.000000 55.00000 1.0000000 93.6
## 11 11 Centro 0.000000 0.000000 55.00000 1.0000000 93.7
## 12 12 Centro 0.000000 0.000000 55.00000 1.0000000 93.9
## 13 13 Centro 0.000000 0.000000 55.00000 1.0000000 93.5
CR <- coded.data(biodiesel,
x1 ~ (Temperatura - 55)/6,
x2 ~ (KOH - 1.00)/0.35)
CR
## Corrida Tipo Temperatura KOH Temperatura KOH y
## 1 1 Factorial 49.00000 0.6500000 -1.000000 -1.000000 83.6
## 2 2 Factorial 61.00000 0.6500000 1.000000 -1.000000 89.8
## 3 3 Factorial 49.00000 1.3500000 -1.000000 1.000000 88.5
## 4 4 Factorial 61.00000 1.3500000 1.000000 1.000000 90.5
## 5 5 Axial 46.51472 1.0000000 -1.414214 0.000000 86.8
## 6 6 Axial 63.48528 1.0000000 1.414214 0.000000 91.7
## 7 7 Axial 55.00000 0.5050253 0.000000 -1.414214 85.8
## 8 8 Axial 55.00000 1.4949747 0.000000 1.414214 90.1
## 9 9 Centro 55.00000 1.0000000 0.000000 0.000000 94.0
## 10 10 Centro 55.00000 1.0000000 0.000000 0.000000 93.6
## 11 11 Centro 55.00000 1.0000000 0.000000 0.000000 93.7
## 12 12 Centro 55.00000 1.0000000 0.000000 0.000000 93.9
## 13 13 Centro 55.00000 1.0000000 0.000000 0.000000 93.5
##
## Data are stored in coded form using these coding formulas ...
## x1 ~ (Temperatura - 55)/6
## x2 ~ (KOH - 1)/0.35
#Variabilidad de la varianza de predicción
varfcn(biodiesel, ~SO(x1, x2), main = "Varianza de predicción")
#GRÁFICA DE CONTORNO
varfcn(biodiesel, ~ SO(x1, x2), contour = TRUE, main = "Contornos")
COMPARACIÓN DE PRIMER Y SEGUNDO ORDEN
m2a <- rsm(y ~FO(x1, x2), data = CR)
summary(m2a)
##
## Call:
## rsm(formula = y ~ FO(x1, x2), data = CR)
##
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 90.4231 0.8611 105.0090 <2e-16 ***
## x1 1.8912 1.0977 1.7229 0.1156
## x2 1.4601 1.0977 1.3302 0.2130
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Multiple R-squared: 0.3215, Adjusted R-squared: 0.1858
## F-statistic: 2.369 on 2 and 10 DF, p-value: 0.1438
##
## Analysis of Variance Table
##
## Response: y
## Df Sum Sq Mean Sq F value Pr(>F)
## FO(x1, x2) 2 45.669 22.8347 2.3689 0.1438
## Residuals 10 96.394 9.6394
## Lack of fit 6 96.222 16.0370 372.9525 1.906e-05
## Pure error 4 0.172 0.0430
##
## Direction of steepest ascent (at radius 1):
## x1 x2
## 0.7915374 0.6111208
##
## Corresponding increment in original units:
## Temperatura KOH
## 4.7492241 0.2138923
m2b <- rsm(y ~SO(x1, x2), data = biodiesel)
summary(m2b)
##
## Call:
## rsm(formula = y ~ SO(x1, x2), data = biodiesel)
##
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 93.74000 0.16059 583.710 < 2.2e-16 ***
## x1 1.89121 0.12696 14.896 1.473e-06 ***
## x2 1.46014 0.12696 11.501 8.452e-06 ***
## x1:x2 -1.05000 0.17955 -5.848 0.0006319 ***
## x1^2 -2.37000 0.13615 -17.407 5.079e-07 ***
## x2^2 -3.02000 0.13615 -22.181 9.567e-08 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Multiple R-squared: 0.9936, Adjusted R-squared: 0.9891
## F-statistic: 218.9 on 5 and 7 DF, p-value: 1.575e-07
##
## Analysis of Variance Table
##
## Response: y
## Df Sum Sq Mean Sq F value Pr(>F)
## FO(x1, x2) 2 45.669 22.835 177.080 1.014e-06
## TWI(x1, x2) 1 4.410 4.410 34.199 0.0006319
## PQ(x1, x2) 2 91.081 45.541 353.161 9.361e-08
## Residuals 7 0.903 0.129
## Lack of fit 3 0.731 0.244 5.664 0.0635869
## Pure error 4 0.172 0.043
##
## Stationary point of response surface:
## x1 x2
## 0.3592727 0.1792886
##
## Eigenanalysis:
## eigen() decomposition
## $values
## [1] -2.077546 -3.312454
##
## $vectors
## [,1] [,2]
## x1 -0.8736002 0.4866443
## x2 0.4866443 0.8736002
anova(m2a, m2b)
## Analysis of Variance Table
##
## Model 1: y ~ FO(x1, x2)
## Model 2: y ~ FO(x1, x2) + TWI(x1, x2) + PQ(x1, x2)
## Res.Df RSS Df Sum of Sq F Pr(>F)
## 1 10 96.394
## 2 7 0.903 3 95.491 246.84 1.843e-07 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
“CALCULO DE LA VARIABLE CANONICA”
can <- canonical(m2b)
can$xs
## x1 x2
## 0.3592727 0.1792886
#PUNTOS OPTIMOS
code2val(can$xs, codings(CR))
## Temperatura KOH
## 57.155636 1.062751
#RENDIMIENTO EN ESE PUNTO ESPECIFICO
nd <- data.frame(t(can$xs), Block = "B1")
predict(m2b, newdata = nd)
## 1
## 94.21062
contour(m2b, ~ x1 + x2, image = TRUE, at = summary(m2b)$can$xs,
main = "Contornos del rendimiento")
contour(m2b, ~ x1 + x2, image = TRUE, at = summary(m2b)$can$xs,
main = "Contornos del rendimiento")
persp(m2b, ~ x1 + x2, at = summary(m2b)$canonical$xs, col = terrain.colors(50),
contours = "colors", zlab = "Rendimiento", theta = -40, phi = 25,
main = "Superficie de respuesta")
par(mfrow=c(2,1))
par(mfrow=c(1,3))
plot(fitted(m2b), resid(m2b), pch = 19, xlab = "Ajustados", ylab = "Residuos"); abline(h = 0, lty = 2)
qqnorm(resid(m2b), pch = 19)
qqline(resid(m2b))
plot(resid(m2b), type = "b", pch = 19, xlab = "Orden", ylab = "Residuos"); abline(h = 0, lty = 2)
shapiro.test(resid(m2b))
##
## Shapiro-Wilk normality test
##
## data: resid(m2b)
## W = 0.98726, p-value = 0.9983
library(rsm)
packageVersion("rsm")
## [1] '2.10.6'
Temp=c(40, 70, 40, 70, 40, 70, 40, 70, 55, 55, 55, 55, 55, 55, 55)
EtOH=c(40, 40, 80, 80, 60, 60, 60, 60, 40, 80, 40, 80, 60, 60, 60)
t=c(60, 60, 60, 60, 30, 30, 90, 90, 30, 30, 90, 90, 60, 60, 60)
Rend=c(54.6, 60.8, 65.2, 76.1, 59.1, 71.4, 66.4, 72.0, 56.5, 67.6, 62.0, 74.3, 72.3, 72.1, 71.6)
Degr=c(2.57, 4.77, 2.61, 5.41, 2.33, 3.64, 2.97, 6.25, 2.29, 2.91, 3.75, 4.73, 3.02, 2.83, 3.19)
data=data.frame(Temp=Temp,EtOH=EtOH,t=t,Rend=Rend,Degr=Degr)
datos=coded.data(data, x1 ~ (Temp - 55)/15, x2 ~ (EtOH - 60)/20,x3~(t-60)/30)
datos
## Temp EtOH t Rend Degr
## 1 40 40 60 54.6 2.57
## 2 70 40 60 60.8 4.77
## 3 40 80 60 65.2 2.61
## 4 70 80 60 76.1 5.41
## 5 40 60 30 59.1 2.33
## 6 70 60 30 71.4 3.64
## 7 40 60 90 66.4 2.97
## 8 70 60 90 72.0 6.25
## 9 55 40 30 56.5 2.29
## 10 55 80 30 67.6 2.91
## 11 55 40 90 62.0 3.75
## 12 55 80 90 74.3 4.73
## 13 55 60 60 72.3 3.02
## 14 55 60 60 72.1 2.83
## 15 55 60 60 71.6 3.19
##
## Data are stored in coded form using these coding formulas ...
## x1 ~ (Temp - 55)/15
## x2 ~ (EtOH - 60)/20
## x3 ~ (t - 60)/30
mR <- rsm(Rend ~ SO(x1, x2, x3), data = datos)
summary(mR)
##
## Call:
## rsm(formula = Rend ~ SO(x1, x2, x3), data = datos)
##
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 72.00000 0.47837 150.5126 2.456e-10 ***
## x1 4.37500 0.29294 14.9349 2.436e-05 ***
## x2 6.16250 0.29294 21.0369 4.497e-06 ***
## x3 2.51250 0.29294 8.5769 0.0003551 ***
## x1:x2 1.17500 0.41428 2.8363 0.0364055 *
## x1:x3 -1.67500 0.41428 -4.0432 0.0098915 **
## x2:x3 0.30000 0.41428 0.7242 0.5014242
## x1^2 -2.85000 0.43119 -6.6096 0.0011924 **
## x2^2 -4.97500 0.43119 -11.5378 8.578e-05 ***
## x3^2 -1.92500 0.43119 -4.4644 0.0066137 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Multiple R-squared: 0.9947, Adjusted R-squared: 0.9852
## F-statistic: 104.5 on 9 and 5 DF, p-value: 3.74e-05
##
## Analysis of Variance Table
##
## Response: Rend
## Df Sum Sq Mean Sq F value Pr(>F)
## FO(x1, x2, x3) 3 507.44 169.146 246.3887 7.52e-06
## TWI(x1, x2, x3) 3 17.10 5.702 8.3054 0.0218270
## PQ(x1, x2, x3) 3 120.97 40.322 58.7351 0.0002551
## Residuals 5 3.43 0.687
## Lack of fit 3 3.17 1.058 8.1346 0.1114403
## Pure error 2 0.26 0.130
##
## Stationary point of response surface:
## x1 x2 x3
## 0.8127177 0.7260422 0.3555871
##
## Stationary point in original units:
## Temp EtOH t
## 67.19077 74.52084 70.66761
##
## Eigenanalysis:
## eigen() decomposition
## $values
## [1] -1.422282 -3.159234 -5.168484
##
## $vectors
## [,1] [,2] [,3]
## x1 -0.52059527 0.8053543 -0.2835226
## x2 -0.05010244 0.3026821 0.9517738
## x3 0.85233228 0.5096941 -0.1172246
mD <- rsm(Degr ~ SO(x1, x2, x3), data = datos)
summary(mD)
##
## Call:
## rsm(formula = Degr ~ SO(x1, x2, x3), data = datos)
##
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 3.013333 0.113076 26.6488 1.391e-06 ***
## x1 1.198750 0.069244 17.3119 1.178e-05 ***
## x2 0.285000 0.069244 4.1159 0.009211 **
## x3 0.816250 0.069244 11.7880 7.730e-05 ***
## x1:x2 0.150000 0.097926 1.5318 0.186148
## x1:x3 0.492500 0.097926 5.0293 0.004003 **
## x2:x3 0.090000 0.097926 0.9191 0.400231
## x1^2 0.602083 0.101925 5.9071 0.001979 **
## x2^2 0.224583 0.101925 2.2034 0.078754 .
## x3^2 0.182083 0.101925 1.7864 0.134078
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Multiple R-squared: 0.9905, Adjusted R-squared: 0.9735
## F-statistic: 58.17 on 9 and 5 DF, p-value: 0.0001583
##
## Analysis of Variance Table
##
## Response: Degr
## Df Sum Sq Mean Sq F value Pr(>F)
## FO(x1, x2, x3) 3 17.4759 5.8253 151.8655 2.492e-05
## TWI(x1, x2, x3) 3 1.0926 0.3642 9.4949 0.016587
## PQ(x1, x2, x3) 3 1.5130 0.5043 13.1482 0.008292
## Residuals 5 0.1918 0.0384
## Lack of fit 3 0.1269 0.0423 1.3045 0.461636
## Pure error 2 0.0649 0.0324
##
## Stationary point of response surface:
## x1 x2 x3
## -0.1665959 -0.1840148 -1.9706367
##
## Stationary point in original units:
## Temp EtOH t
## 52.5010618 56.3197040 0.8808992
##
## Eigenanalysis:
## eigen() decomposition
## $values
## [1] 0.73066180 0.21025255 0.06783565
##
## $vectors
## [,1] [,2] [,3]
## x1 0.8938534 0.18102247 0.41019136
## x2 0.1693809 -0.98341201 0.06489158
## x3 0.4151339 0.01147503 -0.90968793
csR <- canonical(mR)
csR$xs
## x1 x2 x3
## 0.8127177 0.7260422 0.3555871
code2val(csR$xs, codings(datos))
## Temp EtOH t
## 67.19077 74.52084 70.66761
#punto canonico óptimo
predict(mR, newdata = data.frame(t(csR$xs)))
## 1
## 76.46164
predict(mD, newdata = data.frame(t(csR$xs)))
## 1
## 5.277914
#steepest(mD, dist = seq(0, 1.5, by = 0.25), descent = TRUE)
csD <- canonical(mD)
## Near-stationary-ridge situation detected -- stationary point altered
## Change 'threshold' if this is not what you intend
csD$xs
## x1 x2 x3
## -0.8690023 -0.2951343 -0.4128987
code2val(csD$xs, codings(datos))
## Temp EtOH t
## 41.96497 54.09731 47.61304
#punto canonico óptimo
predict(mD, newdata = data.frame(t(csD$xs)))
## 1
## 2.281904
predict(mR, newdata = data.frame(t(csD$xs)))
## 1
## 62.1651
steps=function(cr,cd,ds){
xs1=cr[1];
ys1=cr[2];
xs2=cd[1];
ys2=cd[2];
xs=seq(xs1,xs2,length.out = 15);
ys=seq(ys1,ys2,length.out = 15)
p1=predict(mR, newdata = data.frame(x1=xs,x2=ys,x3=0));
p2=predict(mD, newdata = data.frame(x1=xs,x2=ys,x3=0));
plot(p1,p2);
}
#p=steepest(mD, dist = seq(0, 4.5, by = 0.1), descent = TRUE)
#q=steepest(mR, dist = seq(0, 4.5, by = 0.1), descent = FALSE)
#par(mfrow=c(2,1))
#plot(p$dist,p$yhat)
#plot(q$dist,q$yhat)
steps(csD$xs,csR$xs,0.1)
# Calcular los puntos estacionarios
canR <- canonical(mR)
canD <- canonical(mD)
## Near-stationary-ridge situation detected -- stationary point altered
## Change 'threshold' if this is not what you intend
# Configurar dos gráficos en una misma ventana
par(mfrow = c(1, 2))
# Superficie de respuesta del Rendimiento
persp(mR, ~ x1 + x2,
at = list(x3 = 0),
col = terrain.colors(50),
contours = "colors",
zlab = "Rendimiento",
theta = -40,
phi = 25,
main = "Superficie de respuesta del Rendimiento")
# Superficie de respuesta de la Degradación
persp(mD, ~ x1 + x2,
at = list(x3 = 0),
col = terrain.colors(50),
contours = "colors",
zlab = "Degradación",
theta = -40,
phi = 25,
main = "Superficie de respuesta de la Degradación")
# Restablecer la configuración gráfica
par(mfrow = c(1, 1))