Vous êtes sur la page 1sur 22

taller capitulo 6

Castillo Fabircio
30 de enero de 2018

UNIVERSIDAD DE LAS FUERZAS ARMADAS - ESPE

Departamento de Ciencias de la Vida y de la agricultura

Carrera de Ingeniería en Biotecnología

NRC 3281

Fecha: 25/01 /2018

Ejercicio 7

#Introduccion de la BdD (Base de datos)


A<-c(-1,1,-1,1,-1,1,-1,1)
B<-c(-1,-1,1,1,-1,-1,1,1)
C<-c(-1,-1,-1,-1,1,1,1,1)
Porc<-c(76.65,76.6,80.7,78.75,84.5,84.6,82.95,84.85)
A<-as.factor(A)
B<-as.factor(B)
C<-as.factor(C)
#Regresion
a<-lm(Porc~A*B*C)
eje7<-aov(a)
summary(eje7)

## Df Sum Sq Mean Sq
## A 1 0.00 0.00
## B 1 3.00 3.00
## C 1 73.21 73.21
## A:B 1 0.00 0.00
## A:C 1 2.00 2.00
## B:C 1 7.03 7.03
## A:B:C 1 1.71 1.71
#grafica de efectos principales

library(FrF2)

## Loading required package: DoE.base


## Loading required package: grid
## Loading required package: conf.design
##
## Attaching package: 'DoE.base'

1
## The following objects are masked from 'package:stats':
##
## aov, lm
## The following object is masked from 'package:graphics':
##
## plot.design
## The following object is masked from 'package:base':
##
## lengths
MEPlot(eje7)

Main effects plot for Porc


A B C
85
84
83
82
Porc

81
80
79
78

−1 1 −1 1 −1 1

#grafica de interacciones
interaction.plot( A,C,Porc, xlab = "Temperatura", ylab = "Tamaño de particula",
main="Efecto de interaccion AC para fabricación de dientes")

2
Efecto de interaccion AC para fabricación de dientes
78 79 80 81 82 83 84 85

C
1
Tamaño de particula

−1

−1 1

Temperatura

interaction.plot( A,B,Porc, xlab = "Temperatura", ylab = "Tiempo",


main="Efecto de interaccion AB para fabricación de dientes")

3
Efecto de interaccion AB para fabricación de dientes
81.8

B
1
−1
81.4
Tiempo

81.0
80.6

−1 1

Temperatura

interaction.plot( B,C,Porc, xlab = "Tiempo", ylab = "Tamaño de particula",


main="Efecto de interaccion BC para fabricación de dientes")

4
Efecto de interaccion BC para fabricación de dientes

C
84

1
Tamaño de particula

−1
82
80
78

−1 1

Tiempo

Ejercicio 8

Datos<-read.csv("Ejerc8.csv",sep=";",dec=",")
names(Datos)

## [1] "ingA" "ingB" "ingC" "viscosidad"


attach(Datos)
ingA<-as.factor(ingA)
ingB<-as.factor(ingB)
ingC<-as.factor(ingC)

#regresion
b<-lm(viscosidad~ingA*ingB*ingC)
eje8<-aov(b)
summary(eje8)

## Df Sum Sq Mean Sq F value Pr(>F)


## ingA 1 0.05 0.05 0.802 0.396647
## ingB 1 5.64 5.64 89.356 1.29e-05 ***
## ingC 1 33.35 33.35 528.327 1.36e-08 ***
## ingA:ingB 1 1.05 1.05 16.644 0.003536 **
## ingA:ingC 1 0.03 0.03 0.485 0.505830
## ingB:ingC 1 2.48 2.48 39.297 0.000241 ***
## ingA:ingB:ingC 1 6.38 6.38 101.000 8.18e-06 ***

5
## Residuals 8 0.50 0.06
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#grafica de efectos principales
library(FrF2)
MEPlot(eje8)

Main effects plot for viscosidad


ingA ingB ingC
17.5
17
16.5
16
viscosidad

15.5
15
14.5
14

−1 1 −1 1 −1 1

#grafica de interacciones
interaction.plot( ingA,ingC,viscosidad, xlab = "Ingrediente A", ylab = "Ingrediente C",
main="Efecto de interaccion AC para viscosidad de bebida de chocolate")

6
Efecto de interaccion AC para viscosidad de bebida de chocolate

ingC

1
16.5

−1
Ingrediente C

15.5
14.5

−1 1

Ingrediente A

interaction.plot( ingA,ingB,viscosidad, xlab = "Ingrediente A", ylab = "Ingrediente B",


main="Efecto de interaccion AB para viscosidad de bebida de chocolate")

7
Efecto de interaccion AB para viscosidad de bebida de chocolate
16.5

ingB

1
−1
Ingrediente B

16.0
15.5
15.0

−1 1

Ingrediente A

interaction.plot( ingB,ingC,viscosidad, xlab = "Ingrediente B", ylab = "Ingrediente C",


main="Efecto de interaccion BC para viscosidad de bebida de chocolate")

8
Efecto de interaccion BC para viscosidad de bebida de chocolate
18

ingC

1
−1
17
Ingrediente C

16
15
14

−1 1

Ingrediente B

#verificacion de los supuestos


plot(eje8)

9
Residuals vs Fitted
0.3

9
0.1
Residuals

−0.1

14
−0.3

14 15 16 17 18 19

Fitted values
aov.default(b)

10
Normal Q−Q
2

9
Standardized residuals

1
0
−1

14

−2 −1 0 1 2

Theoretical Quantiles
aov.default(b)

11
Scale−Location
9
1
0.0 0.2 0.4 0.6 0.8 1.0 1.2
Standardized residuals

14

14 15 16 17 18 19

Fitted values
aov.default(b)

12
Constant Leverage:
Residuals vs Factor Levels
2

9
Standardized residuals

1
0
−1

14

1
−2

ingA :
−1 1

Factor Level Combinations

EJERCICIO 9

ejer_9 <- read.csv(file="Ejerc9.csv",header=T, sep=";", na.strings="NA", dec=",",strip.white=TRUE)


> ejer_9
factorA factorB factorC factorD y1 y2
1 -1 -1 -1 -1 61 88
2 1 -1 -1 -1 105 78
3 -1 1 -1 -1 61 82
4 1 1 -1 -1 104 73
5 -1 -1 1 -1 0 88
6 1 -1 1 -1 35 84
7 -1 1 1 -1 50 89
8 1 1 1 -1 57 79
9 -1 -1 -1 1 12 77
10 1 -1 -1 1 60 66
11 -1 1 -1 1 9 84
12 1 1 -1 1 72 93
13 -1 -1 1 1 0 86
14 1 -1 1 1 10 76
15 -1 1 1 1 3 84
16 1 1 1 1 15 75
17 -1 -1 -1 -1 50 50
18 1 -1 -1 -1 98 98
19 -1 1 -1 -1 40 40
20 1 1 -1 -1 145 145

13
21 -1 -1 1 -1 35 35
22 1 -1 1 -1 22 22
23 -1 1 1 -1 37 37
24 1 1 1 -1 71 71
25 -1 -1 -1 1 19 19
26 1 -1 -1 1 57 57
27 -1 1 -1 1 19 19
28 1 1 -1 1 61 61
29 -1 -1 1 1 0 0
30 1 -1 1 1 1 1
31 -1 1 1 1 7 7
32 1 1 1 1 15 15
> ejer_9$A <-factor(ejer_9$factorA)
> ejer_9$B <-factor(ejer_9$factorB)
> ejer_9$C <-factor(ejer_9$factorC)
> ejer_9$D <-factor(ejer_9$factorD)
> ejer_9$Replicas <-factor(ejer_9$y2)
> str(ejer_9)
'data.frame': 32 obs. of 11 variables:
$ factorA : int -1 1 -1 1 -1 1 -1 1 -1 1 ...
$ factorB : int -1 -1 1 1 -1 -1 1 1 -1 -1 ...
$ factorC : int -1 -1 -1 -1 1 1 1 1 -1 -1 ...
$ factorD : int -1 -1 -1 -1 -1 -1 -1 -1 1 1 ...
$ y1 : int 61 105 61 104 0 35 50 57 12 60 ...
$ y2 : int 88 78 82 73 88 84 89 79 77 66 ...
$ A : Factor w/ 2 levels "-1","1": 1 2 1 2 1 2 1 2 1 2 ...
$ B : Factor w/ 2 levels "-1","1": 1 1 2 2 1 1 2 2 1 1 ...
$ C : Factor w/ 2 levels "-1","1": 1 1 1 1 2 2 2 2 1 1 ...
$ D : Factor w/ 2 levels "-1","1": 1 1 1 1 1 1 1 1 2 2 ...
$ Replicas: Factor w/ 28 levels "0","1","7","15",..: 24 19 21 15 24 22 25 20 18 13 ...
> ejer_9.lm=lm(ejer_9$y1~Replicas+A*B*C*D,data=ejer_9)
> a<-anova(ejer_9.lm)
Warning message:
In anova.lm(ejer_9.lm) :
ANOVA F-tests on an essentially perfect fit are unreliable
> a
Analysis of Variance Table

Response: ejer_9$y1
Df Sum Sq Mean Sq F value Pr(>F)
Replicas 27 38615 1430.17
A 1 561 560.67
B 1 0 0.00
C 1 1122 1122.25
B:C 1 756 756.25
Residuals 0 0
> attach(ejer_9)
The following objects are masked from ejer_9 (pos = 3):

A, B, C, D, factorA, factorB, factorC, factorD,


Replicas, y1, y2

The following objects are masked from ejer_9 (pos = 4):

14
A, B, C, D, factorA, factorB, factorC, factorD,
Replicas, y1, y2

The following objects are masked from ejer_9 (pos = 12):

A, B, C, D, factorA, factorB, factorC, factorD,


Replicas, y1, y2

> modelo<-lm(y1~A*B*C*D,data=ejer_9)
> library(pid)
> param_orig<-par(col.lab="black",pch=16,col="blue")
> paretoPlot(modelo,xlab="Efecto",ylab="Escala original",main="Gr?fica de Pareto")
> interaction.plot(ejer_9$A,ejer_9$C,ejer_9$Rendimiento1)
Error in tapply(response, list(x.factor, trace.factor), fun) :
arguments must have same length
> anova<-aov(ejer_9.lm)
> TukeyHSD(anova)
Tukey multiple comparisons of means
95% family-wise confidence level

Fit: aov.default(formula = ejer_9.lm)

$Replicas
diff lwr upr p adj
1-0 1.000000e+00 NaN NaN NaN
7-0 7.000000e+00 NaN NaN NaN
15-0 1.500000e+01 NaN NaN NaN
19-0 1.900000e+01 NaN NaN NaN
22-0 2.200000e+01 NaN NaN NaN
35-0 3.500000e+01 NaN NaN NaN
37-0 3.700000e+01 NaN NaN NaN
40-0 4.000000e+01 NaN NaN NaN
50-0 5.000000e+01 NaN NaN NaN
57-0 5.700000e+01 NaN NaN NaN
61-0 6.100000e+01 NaN NaN NaN
66-0 6.000000e+01 NaN NaN NaN
71-0 7.100000e+01 NaN NaN NaN
73-0 1.040000e+02 NaN NaN NaN
75-0 1.500000e+01 NaN NaN NaN
76-0 1.000000e+01 NaN NaN NaN
77-0 1.200000e+01 NaN NaN NaN
78-0 1.050000e+02 NaN NaN NaN
79-0 5.700000e+01 NaN NaN NaN
82-0 6.100000e+01 NaN NaN NaN
84-0 1.566667e+01 NaN NaN NaN
86-0 -1.136868e-13 NaN NaN NaN
88-0 3.050000e+01 NaN NaN NaN
89-0 5.000000e+01 NaN NaN NaN
93-0 7.200000e+01 NaN NaN NaN
98-0 9.800000e+01 NaN NaN NaN
145-0 1.450000e+02 NaN NaN NaN
7-1 6.000000e+00 NaN NaN NaN
15-1 1.400000e+01 NaN NaN NaN
19-1 1.800000e+01 NaN NaN NaN

15
22-1 2.100000e+01 NaN NaN NaN
35-1 3.400000e+01 NaN NaN NaN
37-1 3.600000e+01 NaN NaN NaN
40-1 3.900000e+01 NaN NaN NaN
50-1 4.900000e+01 NaN NaN NaN
57-1 5.600000e+01 NaN NaN NaN
61-1 6.000000e+01 NaN NaN NaN
66-1 5.900000e+01 NaN NaN NaN
71-1 7.000000e+01 NaN NaN NaN
73-1 1.030000e+02 NaN NaN NaN
75-1 1.400000e+01 NaN NaN NaN
76-1 9.000000e+00 NaN NaN NaN
77-1 1.100000e+01 NaN NaN NaN
78-1 1.040000e+02 NaN NaN NaN
79-1 5.600000e+01 NaN NaN NaN
82-1 6.000000e+01 NaN NaN NaN
84-1 1.466667e+01 NaN NaN NaN
86-1 -1.000000e+00 NaN NaN NaN

[ reached getOption("max.print") -- omitted 128 rows ]

$A
diff lwr upr p adj
1--1 2.416667 NaN NaN NaN

$B
diff lwr upr p adj
1--1 0 NaN NaN NaN

$C
diff lwr upr p adj
1--1 -4.1875 NaN NaN NaN

$`B:C`
diff lwr upr p adj
1:-1--1:-1 -3.4375 NaN NaN NaN
-1:1--1:-1 -7.6250 NaN NaN NaN
1:1--1:-1 -4.1875 NaN NaN NaN
-1:1-1:-1 -4.1875 NaN NaN NaN
1:1-1:-1 -0.7500 NaN NaN NaN
1:1--1:1 3.4375 NaN NaN NaN

Warning messages:
1: In qtukey(conf.level, length(means), x$df.residual) : NaNs produced
2: In qtukey(conf.level, length(means), x$df.residual) : NaNs produced
3: In qtukey(conf.level, length(means), x$df.residual) : NaNs produced
4: In qtukey(conf.level, length(means), x$df.residual) : NaNs produced
5: In qtukey(conf.level, length(means), x$df.residual) : NaNs produced
> ejer_9_2.lm=lm(ejer_9$y2~Replicas+A*B*C*D,data=ejer_9)
> a<-anova(ejer_9_2.lm)
Warning message:
In anova.lm(ejer_9_2.lm) :
ANOVA F-tests on an essentially perfect fit are unreliable
> a

16
Analysis of Variance Table

Response: ejer_9$y2
Df Sum Sq Mean Sq F value Pr(>F)
Replicas 27 35112 1300.5
A 1 0 0.0
B 1 0 0.0
C 1 0 0.0
B:C 1 0 0.0
Residuals 0 0
> anova<-aov(ejer_9_2.lm)
> TukeyHSD(anova)
Tukey multiple comparisons of means
95% family-wise confidence level

Fit: aov.default(formula = ejer_9_2.lm)

$Replicas
diff lwr upr p adj
1-0 1 NaN NaN NaN
7-0 7 NaN NaN NaN
15-0 15 NaN NaN NaN
19-0 19 NaN NaN NaN

[ reached getOption("max.print") -- omitted 128 rows ]

$A
diff lwr upr p adj
1--1 0 NaN NaN NaN

$B
diff lwr upr p adj
1--1 -7.105427e-15 NaN NaN NaN

$C
diff lwr upr p adj
1--1 -7.105427e-15 NaN NaN NaN

$`B:C`
diff lwr upr p adj
1:-1--1:-1 -1.421085e-14 NaN NaN NaN
-1:1--1:-1 -1.421085e-14 NaN NaN NaN
1:1--1:-1 -1.421085e-14 NaN NaN NaN
-1:1-1:-1 0.000000e+00 NaN NaN NaN
1:1-1:-1 0.000000e+00 NaN NaN NaN
1:1--1:1 0.000000e+00 NaN NaN NaN

Warning messages:
1: In qtukey(conf.level, length(means), x$df.residual) : NaNs produced
2: In qtukey(conf.level, length(means), x$df.residual) : NaNs produced
3: In qtukey(conf.level, length(means), x$df.residual) : NaNs produced
4: In qtukey(conf.level, length(means), x$df.residual) : NaNs produced
5: In qtukey(conf.level, length(means), x$df.residual) : NaNs produced
> R1=(38840-2197)*100/38840

17
> R1
[1] 94.34346
> R2=(1316.2-531.97)*100/1316.2
> R2
[1] 59.58289
> residuos <- rstandard(ejer_9.lm)

EJERCICIO 10

Datos10<-read.csv("Ejerc10.csv",sep=";",dec=",") #cambiar la direccion a donde se encuentra el archivo


Datos10

## x1 x2 x3 resistencia
## 1 -1 -1 -1 3.8
## 2 1 -1 -1 6.6
## 3 -1 1 -1 3.4
## 4 1 1 -1 6.8
## 5 -1 -1 1 2.3
## 6 1 -1 1 4.7
## 7 -1 1 1 2.1
## 8 1 1 1 4.2
## 9 -1 -1 -1 3.1
## 10 1 -1 -1 8.0
## 11 -1 1 -1 1.7
## 12 1 1 -1 8.2
## 13 -1 -1 1 3.1
## 14 1 -1 1 3.5
## 15 -1 1 1 1.1
## 16 1 1 1 4.7
## 17 -1 -1 -1 2.2
## 18 1 -1 -1 6.8
## 19 -1 1 -1 3.8
## 20 1 1 -1 6.0
## 21 -1 -1 1 0.7
## 22 1 -1 1 4.4
## 23 -1 1 1 3.6
## 24 1 1 1 2.9
names(Datos10)

## [1] "x1" "x2" "x3" "resistencia"


attach(Datos10)
x1<-as.factor(x1)
x2<-as.factor(x2)
x3<-as.factor(x3)

regresion

a<-lm(resistencia~x1*x2*x3)
eje10<-aov(a)
summary(eje10)

18
## Df Sum Sq Mean Sq F value Pr(>F)
## x1 1 53.70 53.70 53.500 1.74e-06 ***
## x2 1 0.02 0.02 0.020 0.888371
## x3 1 22.23 22.23 22.151 0.000238 ***
## x1:x2 1 0.12 0.12 0.120 0.733583
## x1:x3 1 6.93 6.93 6.908 0.018260 *
## x2:x3 1 0.01 0.01 0.010 0.920125
## x1:x2:x3 1 0.07 0.07 0.070 0.794495
## Residuals 16 16.06 1.00
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

grafica de efectos principales

library(FrF2)
MEPlot(eje10)

Main effects plot for resistencia


x1 x2 x3
2.5 3 3.5 4 4.5 5 5.5 6
resistencia

−1 1 −1 1 −1 1

grafica de interacciones

interaction.plot( x1,x3,resistencia, xlab = "Papel", ylab = "Direccion del rasgu?o",


main="Efecto de interaccion AC para la resistencia al rasgamiento")

19
Efecto de interaccion AC para la resistencia al rasgamiento
7

x3
Direccion del rasgu?o

−1
6

1
5
4
3
2

−1 1

Papel

interaction.plot( x1,x2,resistencia, xlab = "Papel", ylab = "Humedad",


main="Efecto de interaccion AB para la resistencia al rasgamiento")

Efecto de interaccion AB para la resistencia al rasgamiento


5.5

x2
−1
1
4.5
Humedad

3.5
2.5

−1 1

Papel

interaction.plot( x2,x3,resistencia, xlab = "Humedad", ylab = "Direccion del rasgu?o",


main="Efecto de interaccion BC para la resistencia al rasgamiento")

20
Efecto de interaccion BC para la resistencia al rasgamiento
5.0

x3
Direccion del rasgu?o

−1
4.5

1
4.0
3.5

−1 1

Humedad

plot(eje10)

Residuals vs Fitted Normal Q−Q


1.5

23 23
1.5
Standardized residuals
0.5
Residuals

0.5
−0.5

−0.5
−1.5

11
−1.5

21
21 11

2 3 4 5 6 7 −2 −1 0 1 2

Fitted values Theoretical Quantiles


aov.default(a) aov.default(a)

21
Constant Leverage:
Scale−Location Residuals vs Factor Levels

2
21
23
11
1.2

23
Standardized residuals

Standardized residuals

1
0.8

0
0.4

−1
21 11
0.0

−2
x1 :
2 3 4 5 6 7 −1 1

Fitted values Factor Level Combinations


aov.default(a)

22

Vous aimerez peut-être aussi