1. Datos.

Los datos son tomados del libro Diseño y análisis de experimentos de Douglas Montgomery. Página 604.

\(x\): covariable.

\(y\): variable dependiente.

ma (máquina): tratamiento (variable categórica)

ma<-c(rep(1,5),rep(2,5),rep(3,5))
y<-c(36,41,39,42,49,40,48,39,45,44,35,37,42,34,32)
x<-c(20,25,24,25,32,22,28,22,30,28,21,23,26,21,15)
dato<-data.frame(ma,y,x);dato
##    ma  y  x
## 1   1 36 20
## 2   1 41 25
## 3   1 39 24
## 4   1 42 25
## 5   1 49 32
## 6   2 40 22
## 7   2 48 28
## 8   2 39 22
## 9   2 45 30
## 10  2 44 28
## 11  3 35 21
## 12  3 37 23
## 13  3 42 26
## 14  3 34 21
## 15  3 32 15

2. verificación de supuestos.

2.1. Homogeneidad de varianzas.

maq<-factor(ma)
doi<-data.frame(x,y,maq)
leveneTest(y,maq)
## Levene's Test for Homogeneity of Variance (center = median)
##       Df F value Pr(>F)
## group  2  0.0617 0.9405
##       12

2.2. Independencia entre la covariable y la variable categórica.

inde<-aov(x~ma)
summary(inde)
##             Df Sum Sq Mean Sq F value Pr(>F)
## ma           1   40.0   40.00   2.345   0.15
## Residuals   13  221.7   17.06
Anova(inde,type="III")
## Anova Table (Type III tests)
## 
## Response: x
##              Sum Sq Df F value    Pr(>F)    
## (Intercept) 1696.04  1 99.4370 1.859e-07 ***
## ma            40.00  1  2.3452    0.1496    
## Residuals    221.73 13                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

2.3. Homogeneidad de las pendientes de regresión.

homo<-aov(y~x*maq)
summary(homo)
##             Df Sum Sq Mean Sq F value   Pr(>F)    
## x            1 305.13  305.13 108.765 2.52e-06 ***
## maq          2  13.28    6.64   2.368    0.149    
## x:maq        2   2.74    1.37   0.488    0.629    
## Residuals    9  25.25    2.81                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

2.4. Linealidad.

scatterplot(y~x|maq,regLine=TRUE,smooth=FALSE)

3. Análisis de varianza.

anco<-ancova(y~x+maq,data=doi)
summary(anco)
##             Df Sum Sq Mean Sq F value   Pr(>F)    
## x            1 305.13  305.13 119.933 2.96e-07 ***
## maq          2  13.28    6.64   2.611    0.118    
## Residuals   11  27.99    2.54                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
anava<-aov(y~x+maq)
summary(anava)
##             Df Sum Sq Mean Sq F value   Pr(>F)    
## x            1 305.13  305.13 119.933 2.96e-07 ***
## maq          2  13.28    6.64   2.611    0.118    
## Residuals   11  27.99    2.54                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

4. Comparaciones múltiples.

compa<-TukeyHSD(anava)
## Warning in replications(paste("~", xx), data = mf): non-factors ignored: x
## Warning in TukeyHSD.aov(anava): 'which' specified some non-factors which will be
## dropped
compa
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = y ~ x + maq)
## 
## $maq
##           diff       lwr       upr     p adj
## 2-1  0.9362201 -1.788393 3.6608327 0.6346957
## 3-1 -1.0811004 -3.805713 1.6435123 0.5499734
## 3-2 -2.0173204 -4.741933 0.7072922 0.1582999

5. Predichos y residuos.

pre<-predict(anava);pre
##        1        2        3        4        5        6        7        8 
## 36.43926 41.20920 40.25521 41.20920 47.88712 39.38405 45.10798 39.38405 
##        9       10       11       12       13       14       15 
## 47.01595 45.10798 35.80920 37.71718 40.57914 35.80920 30.08528
error<-resid(anava);error
##          1          2          3          4          5          6          7 
## -0.4392638 -0.2092025 -1.2552147  0.7907975  1.1128834  0.6159509  2.8920245 
##          8          9         10         11         12         13         14 
## -0.3840491 -2.0159509 -1.1079755 -0.8092025 -0.7171779  1.4208589 -1.8092025 
##         15 
##  1.9147239
qqnorm(error)
qqline(error)

shapiro.test(error)
## 
##  Shapiro-Wilk normality test
## 
## data:  error
## W = 0.96159, p-value = 0.7201
plot(pre,error)
abline(h=0)

|—|

O.M.F.

|-|-|-|