Exercícios de Experimento Fatorial

Prof. Fernando de Souza Bastos

10 de Novembro de 2018

Exercício 8.1

library("ExpDes.pt")
## 
## Attaching package: 'ExpDes.pt'
## The following object is masked from 'package:stats':
## 
##     ccf
#Experimento Fatorial - Exercício 8.1 da Apostila
(croqui = expand.grid(rep=1:3, Cal=c("Cal0","Cal1"),Irrig=c("Ir0","Ir1")))
##    rep  Cal Irrig
## 1    1 Cal0   Ir0
## 2    2 Cal0   Ir0
## 3    3 Cal0   Ir0
## 4    1 Cal1   Ir0
## 5    2 Cal1   Ir0
## 6    3 Cal1   Ir0
## 7    1 Cal0   Ir1
## 8    2 Cal0   Ir1
## 9    3 Cal0   Ir1
## 10   1 Cal1   Ir1
## 11   2 Cal1   Ir1
## 12   3 Cal1   Ir1
#Fator 1 - Irrigação
#Irrig<-gl(2,6,label=c(paste("A",0:1,sep="")))
#Fator 2 - Calagem
#Cal<-rep(gl(2,3,label=c(paste("B",0:1,sep=""))),2)
#Variável Resposta - Dados
Resp<-c(25,32,27,
         35,28,33,
         41,35,38,
         60,67,59)
#Tabela com os tratamentos e os dados
#tab<-data.frame(Irrig,Cal,dados)
(dados<-data.frame(croqui,Resp))
##    rep  Cal Irrig Resp
## 1    1 Cal0   Ir0   25
## 2    2 Cal0   Ir0   32
## 3    3 Cal0   Ir0   27
## 4    1 Cal1   Ir0   35
## 5    2 Cal1   Ir0   28
## 6    3 Cal1   Ir0   33
## 7    1 Cal0   Ir1   41
## 8    2 Cal0   Ir1   35
## 9    3 Cal0   Ir1   38
## 10   1 Cal1   Ir1   60
## 11   2 Cal1   Ir1   67
## 12   3 Cal1   Ir1   59
attach(dados)
## The following object is masked _by_ .GlobalEnv:
## 
##     Resp
(dados$trat = factor(rep(c('T1','T2','T3','T4'), each=3)))
##  [1] T1 T1 T1 T2 T2 T2 T3 T3 T3 T4 T4 T4
## Levels: T1 T2 T3 T4
# ou
(dados$Trat = with(dados, interaction(Irrig, Cal)))
##  [1] Ir0.Cal0 Ir0.Cal0 Ir0.Cal0 Ir0.Cal1 Ir0.Cal1 Ir0.Cal1 Ir1.Cal0
##  [8] Ir1.Cal0 Ir1.Cal0 Ir1.Cal1 Ir1.Cal1 Ir1.Cal1
## Levels: Ir0.Cal0 Ir1.Cal0 Ir0.Cal1 Ir1.Cal1
head(dados)
##   rep  Cal Irrig Resp trat     Trat
## 1   1 Cal0   Ir0   25   T1 Ir0.Cal0
## 2   2 Cal0   Ir0   32   T1 Ir0.Cal0
## 3   3 Cal0   Ir0   27   T1 Ir0.Cal0
## 4   1 Cal1   Ir0   35   T2 Ir0.Cal1
## 5   2 Cal1   Ir0   28   T2 Ir0.Cal1
## 6   3 Cal1   Ir0   33   T2 Ir0.Cal1
tail(dados)
##    rep  Cal Irrig Resp trat     Trat
## 7    1 Cal0   Ir1   41   T3 Ir1.Cal0
## 8    2 Cal0   Ir1   35   T3 Ir1.Cal0
## 9    3 Cal0   Ir1   38   T3 Ir1.Cal0
## 10   1 Cal1   Ir1   60   T4 Ir1.Cal1
## 11   2 Cal1   Ir1   67   T4 Ir1.Cal1
## 12   3 Cal1   Ir1   59   T4 Ir1.Cal1
str(dados)
## 'data.frame':    12 obs. of  6 variables:
##  $ rep  : int  1 2 3 1 2 3 1 2 3 1 ...
##  $ Cal  : Factor w/ 2 levels "Cal0","Cal1": 1 1 1 2 2 2 1 1 1 2 ...
##  $ Irrig: Factor w/ 2 levels "Ir0","Ir1": 1 1 1 1 1 1 2 2 2 2 ...
##  $ Resp : num  25 32 27 35 28 33 41 35 38 60 ...
##  $ trat : Factor w/ 4 levels "T1","T2","T3",..: 1 1 1 2 2 2 3 3 3 4 ...
##  $ Trat : Factor w/ 4 levels "Ir0.Cal0","Ir1.Cal0",..: 1 1 1 3 3 3 2 2 2 4 ...
#---------------------------
# Estatísticas descritivas -
#---------------------------
summary(dados)
##       rep      Cal    Irrig        Resp      trat         Trat  
##  Min.   :1   Cal0:6   Ir0:6   Min.   :25.0   T1:3   Ir0.Cal0:3  
##  1st Qu.:1   Cal1:6   Ir1:6   1st Qu.:31.0   T2:3   Ir1.Cal0:3  
##  Median :2                    Median :35.0   T3:3   Ir0.Cal1:3  
##  Mean   :2                    Mean   :40.0   T4:3   Ir1.Cal1:3  
##  3rd Qu.:3                    3rd Qu.:45.5                      
##  Max.   :3                    Max.   :67.0
(medias.trat = with(dados, tapply(Resp, trat, mean)))
## T1 T2 T3 T4 
## 28 32 38 62
(medias.Irrig = with(dados, tapply(Resp, Irrig, mean)))
## Ir0 Ir1 
##  30  50
(medias.Cal = with(dados, tapply(Resp, Cal, mean)))
## Cal0 Cal1 
##   33   47
(medias = with(dados, tapply(Resp, list(Irrig, Cal), mean)))
##     Cal0 Cal1
## Ir0   28   32
## Ir1   38   62
(variancias = with(dados, tapply(Resp, list(Irrig, Cal), var)))
##     Cal0 Cal1
## Ir0   13   13
## Ir1    9   19
(desvios = with(dados, tapply(Resp, list(Irrig, Cal), sd)))
##         Cal0     Cal1
## Ir0 3.605551 3.605551
## Ir1 3.000000 4.358899
#--------------------------------------------------------------
# Em experimentos fatoriais é importante verificar se existe  -
# interação entre os fatores. Inicialmente vamos fazer isto   -
# graficamente e mais a frente faremos um teste formal para   -
# presença de interação. Os comandos a seguir são usados para -
# produzir os gráficos.                                       -
#--------------------------------------------------------------
par(mai=c(1, 1, .2, .2))
with(dados, interaction.plot(Irrig, Cal, Resp, las=1, xlab='Irrigação',
                             ylab='Alturas médias (cm)', col=c('red','blue'), 
                             bty='l', trace.label=deparse(substitute(Calagem)), 
                             lwd=2.5))

with(dados, interaction.plot(Cal, Irrig, Resp, las=1, xlab='Calagem',
                             ylab='resp médias (cm)', col=c('red','blue'), 
                             bty='l', trace.label=deparse(substitute(Irrigação)), 
                             lwd=2.5))

#-----------------------------------------------------------------
# Seguindo o modelo adequado, o análise de variância para este   -
# experimento inteiramente casualizado em esquema fatorial pode  -
# ser obtida com o comando:                                      -
#-----------------------------------------------------------------
mod.1 = with(dados, aov(Resp ~ trat))
summary(mod.1)
##             Df Sum Sq Mean Sq F value   Pr(>F)    
## trat         3   2088   696.0   51.56 1.41e-05 ***
## Residuals    8    108    13.5                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
anova(mod.1)
## Analysis of Variance Table
## 
## Response: Resp
##           Df Sum Sq Mean Sq F value    Pr(>F)    
## trat       3   2088   696.0  51.556 1.411e-05 ***
## Residuals  8    108    13.5                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
mod.2 = with(dados, aov(Resp ~ Irrig + Cal + Irrig*Cal))
summary(mod.2)
##             Df Sum Sq Mean Sq F value   Pr(>F)    
## Irrig        1   1200  1200.0   88.89 1.32e-05 ***
## Cal          1    588   588.0   43.56 0.000169 ***
## Irrig:Cal    1    300   300.0   22.22 0.001514 ** 
## Residuals    8    108    13.5                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#--------------------------------------------------------------
# Entretanto o comando acima pode ser simplificado produzindo -
# os mesmos resultados com o comando:                         -
#--------------------------------------------------------------
mod.2 = with(dados, aov(Resp ~ Irrig*Cal))
summary(mod.2)
##             Df Sum Sq Mean Sq F value   Pr(>F)    
## Irrig        1   1200  1200.0   88.89 1.32e-05 ***
## Cal          1    588   588.0   43.56 0.000169 ***
## Irrig:Cal    1    300   300.0   22.22 0.001514 ** 
## Residuals    8    108    13.5                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(médias.fat = model.tables(mod.2, ty="means"))
## Tables of means
## Grand mean
##    
## 40 
## 
##  Irrig 
## Irrig
## Ir0 Ir1 
##  30  50 
## 
##  Cal 
## Cal
## Cal0 Cal1 
##   33   47 
## 
##  Irrig:Cal 
##      Cal
## Irrig Cal0 Cal1
##   Ir0 28   32  
##   Ir1 38   62
#------------------------------
# Verificação de pressupostos -
#------------------------------
#
# Normalidade dos erros
plot(mod.2, which=c(2:2), pch=19, col='red', las=1)

shapiro.test(mod.2$res)
## 
##  Shapiro-Wilk normality test
## 
## data:  mod.2$res
## W = 0.91171, p-value = 0.2244
# Homogeneidade das variâncias
with(dados, bartlett.test(mod.2$res ~ Trat))
## 
##  Bartlett test of homogeneity of variances
## 
## data:  mod.2$res by Trat
## Bartlett's K-squared = 0.23039, df = 3, p-value = 0.9725
# Independência dos erros
with(dados, plot(mod.2$res, las=1, pch=20, col='red', ylab='Resíduos'))

#Comando para rodar a Anova
fat2.dic(Cal,Irrig, Resp, quali = c(TRUE, TRUE), mcomp = "tukey", fac.names = c( "Cal","Irrig"), sigT = 0.05, sigF = 0.05)
## ------------------------------------------------------------------------
## Legenda:
## FATOR 1:  Cal 
## FATOR 2:  Irrig 
## ------------------------------------------------------------------------
## 
## 
## Quadro da analise de variancia
## ------------------------------------------------------------------------
##           GL   SQ     QM     Fc      Pr>Fc
## Cal        1  588  588.0 43.556 0.00016945
## Irrig      1 1200 1200.0 88.889 0.00001315
## Cal*Irrig  1  300  300.0 22.222 0.00151375
## Residuo    8  108   13.5                  
## Total     11 2196                         
## ------------------------------------------------------------------------
## CV = 9.19 %
## 
## ------------------------------------------------------------------------
## Teste de normalidade dos residuos (Shapiro-Wilk)
## valor-p:  0.2244004 
## De acordo com o teste de Shapiro-Wilk a 5% de significancia, os residuos podem ser considerados normais.
## ------------------------------------------------------------------------
## 
## 
## 
## Interacao significativa: desdobrando a interacao
## ------------------------------------------------------------------------
## 
## Desdobrando  Cal  dentro de cada nivel de  Irrig 
## ------------------------------------------------------------------------
## ------------------------------------------------------------------------
## Quadro da analise de variancia
## ------------------------------------------------------------------------
##               GL   SQ        QM      Fc  Pr.Fc
## Irrig          1 1200 1200.0000 88.8889      0
## Cal:Irrig Ir0  1   24   24.0000  1.7778 0.2191
## Cal:Irrig Ir1  1  864  864.0000      64      0
## Residuo        8  108   13.5000               
## Total         11 2196  199.6364               
## ------------------------------------------------------------------------
## 
## 
## 
##  Cal  dentro do nivel  Ir0  de  Irrig 
## 
## De acordo com o teste F, as medias desse fator sao estatisticamente iguais.
## ------------------------------------------------------------------------
##     Niveis     Medias
## 1        1         28
## 2        2         32
## ------------------------------------------------------------------------
## 
## 
##  Cal  dentro do nivel  Ir1  de  Irrig 
## ------------------------------------------------------------------------
## Teste de Tukey
## ------------------------------------------------------------------------
## Grupos Tratamentos Medias
## a     2   62 
##  b    1   38 
## ------------------------------------------------------------------------
## 
## 
## 
## Desdobrando  Irrig  dentro de cada nivel de  Cal 
## ------------------------------------------------------------------------
## ------------------------------------------------------------------------
## Quadro da analise de variancia
## ------------------------------------------------------------------------
##                GL   SQ        QM      Fc  Pr.Fc
## Cal             1  588  588.0000 43.5556  2e-04
## Irrig:Cal Cal0  1  150  150.0000 11.1111 0.0103
## Irrig:Cal Cal1  1 1350 1350.0000     100      0
## Residuo         8  108   13.5000               
## Total          11 2196  199.6364               
## ------------------------------------------------------------------------
## 
## 
## 
##  Irrig  dentro do nivel  Cal0  de  Cal 
## ------------------------------------------------------------------------
## Teste de Tukey
## ------------------------------------------------------------------------
## Grupos Tratamentos Medias
## a     2   38 
##  b    1   28 
## ------------------------------------------------------------------------
## 
## 
##  Irrig  dentro do nivel  Cal1  de  Cal 
## ------------------------------------------------------------------------
## Teste de Tukey
## ------------------------------------------------------------------------
## Grupos Tratamentos Medias
## a     2   62 
##  b    1   32 
## ------------------------------------------------------------------------

Exercício 8.2

library("ExpDes")
## 
## Attaching package: 'ExpDes'
## The following objects are masked from 'package:ExpDes.pt':
## 
##     anscombetukey, bartlett, ccboot, ccf, duncan, ginv, han,
##     lastC, layard, levene, lsd, lsdb, oneilldbc, oneillmathews,
##     order.group, order.stat.SNK, plotres, reg.nl, reg.poly,
##     samiuddin, scottknott, snk, tapply.stat, tukey
## The following object is masked from 'package:stats':
## 
##     ccf
#Experimento Fatorial - Exercício 8.2 da Apostila 
#Fator 1 - Nitrogênio
Nit<-gl(2,10,label=c(paste("N",0:1,sep="")))
#Fator 2 - Fósforo
Fos<-rep(gl(2,5,label=c(paste("P",0:1,sep=""))),2)
dados<-c(10.5,11,9.8,11.2,9.9,
         11.2,11,10.4,13.1,10.6,
         11.5,12.4,10.2,12.7,10.4,
         14,14.1,13.8,13.5,14.2)
#Tabela com os tratamentos e os dados
tab<-data.frame(Nit,Fos,dados)
#Comando para rodar a Anova
fat2.crd(Nit, Fos, dados, quali = c(TRUE, TRUE), mcomp = "tukey", fac.names = c("F1", "F2"), sigT = 0.05, sigF = 0.05)
## ------------------------------------------------------------------------
## Legend:
## FACTOR 1:  F1 
## FACTOR 2:  F2 
## ------------------------------------------------------------------------
## 
## 
## Analysis of Variance Table
## ------------------------------------------------------------------------
##           DF     SS      MS      Fc    Pr>Fc
## F1         1 16.380 16.3805 22.4775 0.000221
## F2         1 13.285 13.2845 18.2292 0.000587
## F1*F2      1  3.613  3.6125  4.9571 0.040699
## Residuals 16 11.660  0.7288                 
## Total     19 44.938                         
## ------------------------------------------------------------------------
## CV = 7.25 %
## 
## ------------------------------------------------------------------------
## Shapiro-Wilk normality test
## p-value:  0.7498233 
## According to Shapiro-Wilk normality test at 5% of significance, residuals can be considered normal.
## ------------------------------------------------------------------------
## 
## 
## 
## Significant interaction: analyzing the interaction
## ------------------------------------------------------------------------
## 
## Analyzing  F1  inside of each level of  F2 
## ------------------------------------------------------------------------
## ------------------------------------------------------------------------
## Analysis of Variance Table
## ------------------------------------------------------------------------
##           DF      SS      MS      Fc  Pr.Fc
## F2         1 13.2845 13.2845 18.2292  6e-04
## F1:F2 P0   1  2.3040   2.304  3.1616 0.0944
## F1:F2 P1   1 17.6890  17.689 24.2731  2e-04
## Residuals 16 11.6600 0.72875               
## Total     19 44.9375                       
## ------------------------------------------------------------------------
## 
## 
## 
##  F1  inside of the level  P0  of  F2 
## 
## According to the F test, the means of this factor are statistical equal.
## ------------------------------------------------------------------------
##     Levels     Means
## 1        1     10.48
## 2        2     11.44
## ------------------------------------------------------------------------
## 
## 
##  F1  inside of the level  P1  of  F2 
## ------------------------------------------------------------------------
## Tukey's test
## ------------------------------------------------------------------------
## Groups Treatments Means
## a     2   13.92 
##  b    1   11.26 
## ------------------------------------------------------------------------
## 
## 
## 
## Analyzing  F2  inside of each level of  F1 
## ------------------------------------------------------------------------
## ------------------------------------------------------------------------
## Analysis of Variance Table
## ------------------------------------------------------------------------
##           DF      SS      MS      Fc  Pr.Fc
## F1         1 16.3805 16.3805 22.4775  2e-04
## F2:F1 N0   1  1.5210   1.521  2.0871 0.1678
## F2:F1 N1   1 15.3760  15.376 21.0991  3e-04
## Residuals 16 11.6600 0.72875               
## Total     19 44.9375                       
## ------------------------------------------------------------------------
## 
## 
## 
##  F2  inside of the level  N0  of  F1 
## 
## According to the F test, the means of this factor are statistical equal.
## ------------------------------------------------------------------------
##     Levels     Means
## 1        1     10.48
## 2        2     11.26
## ------------------------------------------------------------------------
## 
## 
##  F2  inside of the level  N1  of  F1 
## ------------------------------------------------------------------------
## Tukey's test
## ------------------------------------------------------------------------
## Groups Treatments Means
## a     2   13.92 
##  b    1   11.44 
## ------------------------------------------------------------------------

Exercício 8.3

#Experimento Fatorial - Exercício 8.3 da Apostila 
#Fator 1 - Ração
racao<-gl(2,12,label=c(paste("R",0:1,sep="")))
#Fator 2 - Ambiente à noite
luz<-rep(gl(2,6,label=c(paste("L",0:1,sep=""))),2)
#Variável Resposta - Dados
dados<-c(50,52,48,54,52,50,
         49,52,50,48,46,45,
         42,44,46,43,44,45,
         40,40,38,39,41,43)
#Tabela com os tratamentos e os dados
tab<-data.frame(racao,luz,dados)
#Comando para rodar a Anova
fat2.crd(racao, luz, dados, quali = c(TRUE, TRUE), mcomp = "tukey", fac.names = c("F1", "F2"), sigT = 0.05, sigF = 0.05)
## ------------------------------------------------------------------------
## Legend:
## FACTOR 1:  F1 
## FACTOR 2:  F2 
## ------------------------------------------------------------------------
## 
## 
## Analysis of Variance Table
## ------------------------------------------------------------------------
##           DF     SS     MS     Fc   Pr>Fc
## F1         1 345.04 345.04 86.081 0.00000
## F2         1  63.38  63.38 15.811 0.00074
## F1*F2      1   2.04   2.04  0.509 0.48366
## Residuals 20  80.17   4.01               
## Total     23 490.63                      
## ------------------------------------------------------------------------
## CV = 4.36 %
## 
## ------------------------------------------------------------------------
## Shapiro-Wilk normality test
## p-value:  0.8826623 
## According to Shapiro-Wilk normality test at 5% of significance, residuals can be considered normal.
## ------------------------------------------------------------------------
## 
## No significant interaction: analyzing the simple effect
## ------------------------------------------------------------------------
## F1
## Tukey's test
## ------------------------------------------------------------------------
## Groups Treatments Means
## a     R0      49.66667 
##  b    R1      42.08333 
## ------------------------------------------------------------------------
## 
## F2
## Tukey's test
## ------------------------------------------------------------------------
## Groups Treatments Means
## a     L0      47.5 
##  b    L1      44.25 
## ------------------------------------------------------------------------

Exercício 8.10

#Experimento Fatorial - Exercício 8.10 da Apostila 
#Fator 1 - B
b<-gl(3,12,label=c(paste("B",1:3,sep="")))
#Fator 2 - A
a<-rep(gl(4,3,label=c(paste("A",1:4,sep=""))),3)
#Variável Resposta - Dados
dados<-c(12,14,16,
         15,17,18,20,21,23,23,24,26,
         18,17,20,22,23,23,25,26,28,29,30,32,
         22,21,20,30,31,32,29,32,32,34,35,37)
#Tabela com os tratamentos e os dados
tab<-data.frame(b,a,dados)
#Comando para rodar a Anova
fat2.crd(b, a, dados, quali = c(TRUE, TRUE), mcomp = "tukey", fac.names = c("F1", "F2"), sigT = 0.05, sigF = 0.05)
## ------------------------------------------------------------------------
## Legend:
## FACTOR 1:  F1 
## FACTOR 2:  F2 
## ------------------------------------------------------------------------
## 
## 
## Analysis of Variance Table
## ------------------------------------------------------------------------
##           DF      SS     MS      Fc    Pr>Fc
## F1         2  661.56 330.78 154.649 0.000000
## F2         3  714.97 238.32 111.424 0.000000
## F1*F2      6   46.44   7.74   3.619 0.010654
## Residuals 24   51.33   2.14                 
## Total     35 1474.31                        
## ------------------------------------------------------------------------
## CV = 6 %
## 
## ------------------------------------------------------------------------
## Shapiro-Wilk normality test
## p-value:  0.02773403 
## WARNING: at 5% of significance, residuals can not be considered normal!
## ------------------------------------------------------------------------
## 
## 
## 
## Significant interaction: analyzing the interaction
## ------------------------------------------------------------------------
## 
## Analyzing  F1  inside of each level of  F2 
## ------------------------------------------------------------------------
## ------------------------------------------------------------------------
## Analysis of Variance Table
## ------------------------------------------------------------------------
##           DF         SS        MS       Fc Pr.Fc
## F2         3  714.97222 238.32407 111.4242     0
## F1:F2 A1   2   74.88889  37.44444  17.5065     0
## F1:F2 A2   2  310.88889 155.44444  72.6753     0
## F1:F2 A3   2  140.22222  70.11111  32.7792     0
## F1:F2 A4   2  182.00000        91  42.5455     0
## Residuals 24   51.33333   2.13889               
## Total     35 1474.30556                         
## ------------------------------------------------------------------------
## 
## 
## 
##  F1  inside of the level  A1  of  F2 
## ------------------------------------------------------------------------
## Tukey's test
## ------------------------------------------------------------------------
## Groups Treatments Means
## a     3   21 
## a     2   18.33333 
##  b    1   14 
## ------------------------------------------------------------------------
## 
## 
##  F1  inside of the level  A2  of  F2 
## ------------------------------------------------------------------------
## Tukey's test
## ------------------------------------------------------------------------
## Groups Treatments Means
## a     3   31 
##  b    2   22.66667 
##   c   1   16.66667 
## ------------------------------------------------------------------------
## 
## 
##  F1  inside of the level  A3  of  F2 
## ------------------------------------------------------------------------
## Tukey's test
## ------------------------------------------------------------------------
## Groups Treatments Means
## a     3   31 
##  b    2   26.33333 
##   c   1   21.33333 
## ------------------------------------------------------------------------
## 
## 
##  F1  inside of the level  A4  of  F2 
## ------------------------------------------------------------------------
## Tukey's test
## ------------------------------------------------------------------------
## Groups Treatments Means
## a     3   35.33333 
##  b    2   30.33333 
##   c   1   24.33333 
## ------------------------------------------------------------------------
## 
## 
## 
## Analyzing  F2  inside of each level of  F1 
## ------------------------------------------------------------------------
## ------------------------------------------------------------------------
## Analysis of Variance Table
## ------------------------------------------------------------------------
##           DF         SS        MS       Fc Pr.Fc
## F1         2  661.55556 330.77778 154.6494     0
## F2:F1 B1   3  192.91667  64.30556  30.0649     0
## F2:F1 B2   3  236.25000     78.75  36.8182     0
## F2:F1 B3   3  332.25000    110.75  51.7792     0
## Residuals 24   51.33333   2.13889               
## Total     35 1474.30556                         
## ------------------------------------------------------------------------
## 
## 
## 
##  F2  inside of the level  B1  of  F1 
## ------------------------------------------------------------------------
## Tukey's test
## ------------------------------------------------------------------------
## Groups Treatments Means
## a     4   24.33333 
## a     3   21.33333 
##  b    2   16.66667 
##  b    1   14 
## ------------------------------------------------------------------------
## 
## 
##  F2  inside of the level  B2  of  F1 
## ------------------------------------------------------------------------
## Tukey's test
## ------------------------------------------------------------------------
## Groups Treatments Means
## a     4   30.33333 
##  b    3   26.33333 
##   c   2   22.66667 
##    d      1   18.33333 
## ------------------------------------------------------------------------
## 
## 
##  F2  inside of the level  B3  of  F1 
## ------------------------------------------------------------------------
## Tukey's test
## ------------------------------------------------------------------------
## Groups Treatments Means
## a     4   35.33333 
##  b    2   31 
##  b    3   31 
##   c   1   21 
## ------------------------------------------------------------------------

Exercício 8.17

#Experimento Fatorial - Exercício 8.17 da Apostila 
#Fator 1 - A
a<-gl(2,9,label=c(paste("A",1:2,sep="")))
#Fator 2 - B
b<-rep(gl(3,3,label=c(paste("B",1:3,sep=""))),2)
#Variável resposta - dados
dados<-c(12,14,16,15,17,18,12,11,13,
         14,13,16,11,12,11,12,12,13)
#Comando para rodar a Anova
fat2.crd(a, b, dados, quali = c(TRUE, TRUE), mcomp = "tukey", fac.names = c("F1", "F2"), sigT = 0.05, sigF = 0.05)
## ------------------------------------------------------------------------
## Legend:
## FACTOR 1:  F1 
## FACTOR 2:  F2 
## ------------------------------------------------------------------------
## 
## 
## Analysis of Variance Table
## ------------------------------------------------------------------------
##           DF     SS      MS     Fc    Pr>Fc
## F1         1 10.889 10.8889 6.3226 0.027184
## F2         2 14.778  7.3889 4.2903 0.039295
## F1*F2      2 32.111 16.0556 9.3226 0.003605
## Residuals 12 20.667  1.7222                
## Total     17 78.444                        
## ------------------------------------------------------------------------
## CV = 9.76 %
## 
## ------------------------------------------------------------------------
## Shapiro-Wilk normality test
## p-value:  0.8243212 
## According to Shapiro-Wilk normality test at 5% of significance, residuals can be considered normal.
## ------------------------------------------------------------------------
## 
## 
## 
## Significant interaction: analyzing the interaction
## ------------------------------------------------------------------------
## 
## Analyzing  F1  inside of each level of  F2 
## ------------------------------------------------------------------------
## ------------------------------------------------------------------------
## Analysis of Variance Table
## ------------------------------------------------------------------------
##           DF       SS       MS      Fc  Pr.Fc
## F2         2 14.77778  7.38889  4.2903 0.0393
## F1:F2 B1   1  0.16667  0.16667  0.0968 0.7611
## F1:F2 B2   1 42.66667 42.66667 24.7742  3e-04
## F1:F2 B3   1  0.16667  0.16667  0.0968 0.7611
## Residuals 12 20.66667  1.72222               
## Total     17 78.44444                        
## ------------------------------------------------------------------------
## 
## 
## 
##  F1  inside of the level  B1  of  F2 
## 
## According to the F test, the means of this factor are statistical equal.
## ------------------------------------------------------------------------
##     Levels     Means
## 1        1  14.00000
## 2        2  14.33333
## ------------------------------------------------------------------------
## 
## 
##  F1  inside of the level  B2  of  F2 
## ------------------------------------------------------------------------
## Tukey's test
## ------------------------------------------------------------------------
## Groups Treatments Means
## a     1   16.66667 
##  b    2   11.33333 
## ------------------------------------------------------------------------
## 
## 
##  F1  inside of the level  B3  of  F2 
## 
## According to the F test, the means of this factor are statistical equal.
## ------------------------------------------------------------------------
##     Levels     Means
## 1        1  12.00000
## 2        2  12.33333
## ------------------------------------------------------------------------
## 
## 
## 
## Analyzing  F2  inside of each level of  F1 
## ------------------------------------------------------------------------
## ------------------------------------------------------------------------
## Analysis of Variance Table
## ------------------------------------------------------------------------
##           DF       SS       MS     Fc  Pr.Fc
## F1         1 10.88889 10.88889 6.3226 0.0272
## F2:F1 A1   2 32.88889 16.44444 9.5484 0.0033
## F2:F1 A2   2 14.00000        7 4.0645 0.0449
## Residuals 12 20.66667  1.72222              
## Total     17 78.44444                       
## ------------------------------------------------------------------------
## 
## 
## 
##  F2  inside of the level  A1  of  F1 
## ------------------------------------------------------------------------
## Tukey's test
## ------------------------------------------------------------------------
## Groups Treatments Means
## a     2   16.66667 
## ab    1   14 
##  b    3   12 
## ------------------------------------------------------------------------
## 
## 
##  F2  inside of the level  A2  of  F1 
## ------------------------------------------------------------------------
## Tukey's test
## ------------------------------------------------------------------------
## Groups Treatments Means
## a     1   14.33333 
## ab    3   12.33333 
##  b    2   11.33333 
## ------------------------------------------------------------------------

Exercício 8.19

#Experimento Fatorial - Exercício 8.19 da Apostila 
#Fator 1 - Tipos de Colhetadeira
t<-gl(2,15,label=c(paste("T",1:2,sep="")))
#Fator 2 - Horários de Colheita
h<-rep(gl(3,5,label=c(paste("H",1:3,sep=""))),2)
#Variável Resposta - dados
dados<-c(35,40,45,49,39,
         43,41,47,38,48,
         52,57,58,56,59,
         54,58,56,61,59,
         67,59,62,65,64,
         71,73,74,77,75)
#Tabela com os niveis dos fatores e os dados
tab<-data.frame(t,h,dados)
#Comando para rodar a Anova
fat2.crd(t, h, dados, quali = c(TRUE, TRUE), mcomp = "tukey", fac.names = c("F1", "F2"), sigT = 0.05, sigF = 0.05)
## ------------------------------------------------------------------------
## Legend:
## FACTOR 1:  F1 
## FACTOR 2:  F2 
## ------------------------------------------------------------------------
## 
## 
## Analysis of Variance Table
## ------------------------------------------------------------------------
##           DF     SS      MS      Fc   Pr>Fc
## F1         1 2394.1 2394.13 189.011 0.00000
## F2         2 1323.5  661.73  52.242 0.00000
## F1*F2      2   20.3   10.13   0.800 0.46095
## Residuals 24  304.0   12.67                
## Total     29 4041.9                        
## ------------------------------------------------------------------------
## CV = 6.35 %
## 
## ------------------------------------------------------------------------
## Shapiro-Wilk normality test
## p-value:  0.9874 
## According to Shapiro-Wilk normality test at 5% of significance, residuals can be considered normal.
## ------------------------------------------------------------------------
## 
## No significant interaction: analyzing the simple effect
## ------------------------------------------------------------------------
## F1
## Tukey's test
## ------------------------------------------------------------------------
## Groups Treatments Means
## a     T2      65 
##  b    T1      47.13333 
## ------------------------------------------------------------------------
## 
## F2
## Tukey's test
## ------------------------------------------------------------------------
## Groups Treatments Means
## a     H3      65.2 
##  b    H2      53.4 
##  b    H1      49.6 
## ------------------------------------------------------------------------

Exercício 8.23

#Experimento Fatorial - Exercício 8.23 da Apostila 
#Fator 1 - Suplementos Minerais
a<-gl(3,8,label=c(paste("A",1:3,sep="")))
#Fator 2 - Suplementos Vegetais
b<-rep(gl(2,4,label=c(paste("B",1:2,sep=""))),3)
#Variável Resposta - dados
dados<-c(35.2,36,35,35.4,
         32.8,34.6,36.7,35.2,
         34.7,36.3,35.1,36.4,
         28.6,31.1,29,28.6,
         33.8,29.4,28.8,29.2,
         30.8,31.4,32.8,31.3)
#Tabela com os niveis dos fatores e os dados
tab<-data.frame(a,b,dados)
#Comando para rodar a Anova
fat2.crd(a, b, dados, quali = c(TRUE, TRUE), mcomp = "tukey", fac.names = c("F1", "F2"), sigT = 0.05, sigF = 0.05)
## ------------------------------------------------------------------------
## Legend:
## FACTOR 1:  F1 
## FACTOR 2:  F2 
## ------------------------------------------------------------------------
## 
## 
## Analysis of Variance Table
## ------------------------------------------------------------------------
##           DF      SS     MS     Fc     Pr>Fc
## F1         2  71.336 35.668 19.113 0.0000353
## F2         1  20.907 20.907 11.203 0.0035876
## F1*F2      2  62.386 31.193 16.715 0.0000788
## Residuals 18  33.590  1.866                 
## Total     23 188.218                        
## ------------------------------------------------------------------------
## CV = 4.16 %
## 
## ------------------------------------------------------------------------
## Shapiro-Wilk normality test
## p-value:  0.07782912 
## According to Shapiro-Wilk normality test at 5% of significance, residuals can be considered normal.
## ------------------------------------------------------------------------
## 
## 
## 
## Significant interaction: analyzing the interaction
## ------------------------------------------------------------------------
## 
## Analyzing  F1  inside of each level of  F2 
## ------------------------------------------------------------------------
## ------------------------------------------------------------------------
## Analysis of Variance Table
## ------------------------------------------------------------------------
##           DF        SS       MS      Fc  Pr.Fc
## F2         1  20.90667 20.90667 11.2033 0.0036
## F1:F2 B1   2  72.55500  36.2775 19.4402      0
## F1:F2 B2   2  61.16667 30.58333 16.3888  1e-04
## Residuals 18  33.59000  1.86611               
## Total     23 188.21833                        
## ------------------------------------------------------------------------
## 
## 
## 
##  F1  inside of the level  B1  of  F2 
## ------------------------------------------------------------------------
## Tukey's test
## ------------------------------------------------------------------------
## Groups Treatments Means
## a     2   35.625 
## a     1   35.4 
##  b    3   30.3 
## ------------------------------------------------------------------------
## 
## 
##  F1  inside of the level  B2  of  F2 
## ------------------------------------------------------------------------
## Tukey's test
## ------------------------------------------------------------------------
## Groups Treatments Means
## a     1   34.825 
##  b    3   31.575 
##  b    2   29.325 
## ------------------------------------------------------------------------
## 
## 
## 
## Analyzing  F2  inside of each level of  F1 
## ------------------------------------------------------------------------
## ------------------------------------------------------------------------
## Analysis of Variance Table
## ------------------------------------------------------------------------
##           DF        SS       MS      Fc  Pr.Fc
## F1         2  71.33583 35.66792 19.1135      0
## F2:F1 A1   1   0.66125  0.66125  0.3543 0.5591
## F2:F1 A2   1  79.38000    79.38 42.5377      0
## F2:F1 A3   1   3.25125  3.25125  1.7423 0.2034
## Residuals 18  33.59000  1.86611               
## Total     23 188.21833                        
## ------------------------------------------------------------------------
## 
## 
## 
##  F2  inside of the level  A1  of  F1 
## 
## According to the F test, the means of this factor are statistical equal.
## ------------------------------------------------------------------------
##     Levels     Means
## 1        1    35.400
## 2        2    34.825
## ------------------------------------------------------------------------
## 
## 
##  F2  inside of the level  A2  of  F1 
## ------------------------------------------------------------------------
## Tukey's test
## ------------------------------------------------------------------------
## Groups Treatments Means
## a     1   35.625 
##  b    2   29.325 
## ------------------------------------------------------------------------
## 
## 
##  F2  inside of the level  A3  of  F1 
## 
## According to the F test, the means of this factor are statistical equal.
## ------------------------------------------------------------------------
##     Levels     Means
## 1        1    30.300
## 2        2    31.575
## ------------------------------------------------------------------------

Exercício 8.25

#Experimento Fatorial - Exercício 8.25 da Apostila 
#Fator 1 - Recipiente
rec<-gl(3,8,label=c(paste("R",1:3,sep="")))
#Fator 2 - Espécie
esp<-rep(gl(2,4,label=c(paste("E",1:2))),3)
#Variável Resposta - dados
dados<-c(26.2,26,25,25.4,
         24.8,24.6,26.7,25.2,
         25.7,26.3,25.1,26.4,
         19.6,21.1,19,18.6,
         22.8,19.4,18.8,19.2,
         19.8,21.4,22.8,21.3)
#Tabela com os niveis dos fatores e os dados
tab<-data.frame(rec,esp,dados)
#Comando para rodar a Anova
fat2.crd(rec, esp, dados, quali = c(TRUE, TRUE), mcomp = "tukey", fac.names = c("F1", "F2"), sigT = 0.05, sigF = 0.05)
## ------------------------------------------------------------------------
## Legend:
## FACTOR 1:  F1 
## FACTOR 2:  F2 
## ------------------------------------------------------------------------
## 
## 
## Analysis of Variance Table
## ------------------------------------------------------------------------
##           DF      SS     MS     Fc      Pr>Fc
## F1         2  92.861 46.430 36.195 0.00000049
## F2         1  19.082 19.082 14.875 0.00115535
## F1*F2      2  63.761 31.880 24.853 0.00000664
## Residuals 18  23.090  1.283                  
## Total     23 198.793                         
## ------------------------------------------------------------------------
## CV = 4.93 %
## 
## ------------------------------------------------------------------------
## Shapiro-Wilk normality test
## p-value:  0.09401682 
## According to Shapiro-Wilk normality test at 5% of significance, residuals can be considered normal.
## ------------------------------------------------------------------------
## 
## 
## 
## Significant interaction: analyzing the interaction
## ------------------------------------------------------------------------
## 
## Analyzing  F1  inside of each level of  F2 
## ------------------------------------------------------------------------
## ------------------------------------------------------------------------
## Analysis of Variance Table
## ------------------------------------------------------------------------
##           DF        SS       MS      Fc  Pr.Fc
## F2         1  19.08167 19.08167 14.8753 0.0012
## F1:F2 E 1  2  87.12167 43.56083 33.9582      0
## F1:F2 E 2  2  69.50000    34.75 27.0896      0
## Residuals 18  23.09000  1.28278               
## Total     23 198.79333                        
## ------------------------------------------------------------------------
## 
## 
## 
##  F1  inside of the level  E 1  of  F2 
## ------------------------------------------------------------------------
## Tukey's test
## ------------------------------------------------------------------------
## Groups Treatments Means
## a     2   25.875 
## a     1   25.65 
##  b    3   20.05 
## ------------------------------------------------------------------------
## 
## 
##  F1  inside of the level  E 2  of  F2 
## ------------------------------------------------------------------------
## Tukey's test
## ------------------------------------------------------------------------
## Groups Treatments Means
## a     1   25.325 
##  b    3   21.325 
##  b    2   19.575 
## ------------------------------------------------------------------------
## 
## 
## 
## Analyzing  F2  inside of each level of  F1 
## ------------------------------------------------------------------------
## ------------------------------------------------------------------------
## Analysis of Variance Table
## ------------------------------------------------------------------------
##           DF        SS       MS      Fc  Pr.Fc
## F1         2  92.86083 46.43042 36.1952      0
## F2:F1 R1   1   0.21125  0.21125  0.1647 0.6897
## F2:F1 R2   1  79.38000    79.38 61.8813      0
## F2:F1 R3   1   3.25125  3.25125  2.5345 0.1288
## Residuals 18  23.09000  1.28278               
## Total     23 198.79333                        
## ------------------------------------------------------------------------
## 
## 
## 
##  F2  inside of the level  R1  of  F1 
## 
## According to the F test, the means of this factor are statistical equal.
## ------------------------------------------------------------------------
##     Levels     Means
## 1        1    25.650
## 2        2    25.325
## ------------------------------------------------------------------------
## 
## 
##  F2  inside of the level  R2  of  F1 
## ------------------------------------------------------------------------
## Tukey's test
## ------------------------------------------------------------------------
## Groups Treatments Means
## a     1   25.875 
##  b    2   19.575 
## ------------------------------------------------------------------------
## 
## 
##  F2  inside of the level  R3  of  F1 
## 
## According to the F test, the means of this factor are statistical equal.
## ------------------------------------------------------------------------
##     Levels     Means
## 1        1    20.050
## 2        2    21.325
## ------------------------------------------------------------------------