Los datos son tomados del libro Diseño y análisis de experimentos de Douglas Montgomery. Página 219.
A<-c(rep(-1,3),rep(1,3),rep(-1,3),rep(1,3))
B<-c(rep(-1,6),rep(1,6))
rendimiento<-c(28,25,27,36,32,32,18,19,23,31,30,29)
D<-data.frame(A,B,rendimiento)
interaction.plot(A,B,rendimiento,legend = T)
lineal<-lm(rendimiento~A+B+A*B)
summary(lineal)
##
## Call:
## lm(formula = rendimiento ~ A + B + A * B)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.000 -1.333 -0.500 1.083 3.000
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 27.5000 0.5713 48.135 3.84e-11 ***
## A 4.1667 0.5713 7.293 8.44e-05 ***
## B -2.5000 0.5713 -4.376 0.00236 **
## A:B 0.8333 0.5713 1.459 0.18278
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.979 on 8 degrees of freedom
## Multiple R-squared: 0.903, Adjusted R-squared: 0.8666
## F-statistic: 24.82 on 3 and 8 DF, p-value: 0.0002093
mi<-coefficients(lineal);mi
## (Intercept) A B A:B
## 27.5000000 4.1666667 -2.5000000 0.8333333
Efectos<-mi[-1];Efectos
## A B A:B
## 4.1666667 -2.5000000 0.8333333
andeva<-aov(rendimiento~A+B+A*B)
summary(andeva)
## Df Sum Sq Mean Sq F value Pr(>F)
## A 1 208.33 208.33 53.191 8.44e-05 ***
## B 1 75.00 75.00 19.149 0.00236 **
## A:B 1 8.33 8.33 2.128 0.18278
## Residuals 8 31.33 3.92
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
pred<-predict(lineal)
pred
## 1 2 3 4 5 6 7 8
## 26.66667 26.66667 26.66667 33.33333 33.33333 33.33333 20.00000 20.00000
## 9 10 11 12
## 20.00000 30.00000 30.00000 30.00000
error<-resid(lineal);error
## 1 2 3 4 5
## 1.333333e+00 -1.666667e+00 3.333333e-01 2.666667e+00 -1.333333e+00
## 6 7 8 9 10
## -1.333333e+00 -2.000000e+00 -1.000000e+00 3.000000e+00 1.000000e+00
## 11 12
## -2.775558e-16 -1.000000e+00
qqnorm(error)
qqline(error)
plot(pred,error)
abline(h=0)
x<-seq(-1,1,length=50)
y<-x
f<-function(x,y){
f<-mi[1]+mi[2]*x+mi[3]*y+mi[4]*x*y
}
z<-outer(x,y,f)
persp(x,y,z,theta=45,phi=45)
contour(x,y,z)