# Definindo o diretório de trabalho
setwd("C:/Users/aluno/Documents")
getwd()
## [1] "C:/Users/aluno/Documents"
# Pacotes que serão utilizados

library(agricolae)
## Warning: package 'agricolae' was built under R version 3.1.3
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 3.1.3
library(asbio)
## Warning: package 'asbio' was built under R version 3.1.3
## Loading required package: tcltk
# Teste Tukey de Aditividade

#Importando os dados

solucao<-read.table("solucao.txt",h=T)


# Verficando os dados

str(solucao)
## 'data.frame':    12 obs. of  3 variables:
##  $ sol: Factor w/ 3 levels "S1","S2","S3": 1 1 1 1 2 2 2 2 3 3 ...
##  $ dia: Factor w/ 4 levels "D1","D2","D3",..: 1 2 3 4 1 2 3 4 1 2 ...
##  $ y  : int  13 22 18 39 16 24 17 44 5 4 ...
summary(solucao)
##  sol    dia          y        
##  S1:4   D1:3   Min.   : 1.00  
##  S2:4   D2:3   1st Qu.:11.00  
##  S3:4   D3:3   Median :17.50  
##         D4:3   Mean   :18.75  
##                3rd Qu.:22.50  
##                Max.   :44.00
#Análise Gráfica de dados 

# Boxplot: yxsolucao

ggplot(solucao, aes(x= sol, y=y, fill=sol)) +geom_boxplot()

# Boxplot: yxdia

ggplot(solucao, aes(x=dia, y=y, fill=dia)) +geom_boxplot()

# Boxplot: yxsolucao

ggplot(solucao, aes(x=sol, y=y, fill=sol)) +geom_boxplot()

# Boxplot: yxdia

ggplot(solucao, aes(x=dia, y=y, fill=dia)) +geom_boxplot()

# Verificando interação entre Blocos e Níveis do Fato
(solucao)
##    sol dia  y
## 1   S1  D1 13
## 2   S1  D2 22
## 3   S1  D3 18
## 4   S1  D4 39
## 5   S2  D1 16
## 6   S2  D2 24
## 7   S2  D3 17
## 8   S2  D4 44
## 9   S3  D1  5
## 10  S3  D2  4
## 11  S3  D3  1
## 12  S3  D4 22
interaction.plot(solucao$dia, solucao$sol, solucao$y, fixed=TRUE)

# Teste de Aditividade de Tukey

# TEsta HO: Não há efeito interação

tukey.add.test(solucao$y, solucao$sol, solucao$dia)
## 
## Tukey's one df test for additivity 
## F = 2.7732343   Denom df = 5    p-value = 0.1567331
# Estimação do Modelo como se fosse ANAVA1 

mdic<-aov(y~sol,data=solucao)

# Exibe a Tabela da ANAVA

summary(mdic)
##             Df Sum Sq Mean Sq F value Pr(>F)
## sol          2  703.5   351.8   2.732  0.118
## Residuals    9 1158.7   128.7
#Estimação do Modelo com blocagem dos dias

mdbca<-aov(y ~ sol+dia, data=solucao)

summary(mdbca)
##             Df Sum Sq Mean Sq F value   Pr(>F)    
## sol          2  703.5   351.8   40.72 0.000323 ***
## dia          3 1106.9   369.0   42.71 0.000192 ***
## Residuals    6   51.8     8.6                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# cv do Pacote Agricolae

cv.model(mdbca)
## [1] 15.67573
# Análise Gráfica da Normalidade e Homogeneidade das variâncias

plot(mdbca, which=1) # Residuo dos xValores previstos

plot(mdbca, which=2) # grafico qqplot

#### Teste de Shapiro-Wil k s

shapiro.test(mdbca$residuals)
## 
##  Shapiro-Wilk normality test
## 
## data:  mdbca$residuals
## W = 0.9321, p-value = 0.4027

Teste de Bartlett

T e s t e de B a r t l e t t

bartlett.test(y~interaction(sol,dia),data=solucao)

Error inbartlett.test…deve haver ao menos duas observações em cada grupo

###Teste de Tukey Agricolae

HSD.test(mdbca,"sol", group=TRUE, console = TRUE)
## 
## Study: mdbca ~ "sol"
## 
## HSD Test for y 
## 
## Mean Square Error:  8.638889 
## 
## sol,  means
## 
##        y       std r Min Max
## S1 23.00 11.284207 4  13  39
## S2 25.25 12.996794 4  16  44
## S3  8.00  9.486833 4   1  22
## 
## alpha: 0.05 ; Df Error: 6 
## Critical Value of Studentized Range: 4.339195 
## 
## Honestly Significant Difference: 6.376879 
## 
## Means with the same letter are not significantly different.
## 
## Groups, Treatments and means
## a     S2      25.25 
## a     S1      23 
## b     S3      8
### Eficiência do DBCA x DIC

qmr.di=128.7

qmr.db=8.6

qmr.di/qmr.db
## [1] 14.96512
# Definindo Diretório de Trabalho

setwd("C:/Users/aluno/Documents")

# Pacotes que serão utilizados

library(agricolae)

library(ggplot2)

library(effects) # Gráfico de Efeitos
## Warning: package 'effects' was built under R version 3.1.3
library(car) # Teste
## Warning: package 'car' was built under R version 3.1.3
## 
## Attaching package: 'car'
## 
## The following object is masked from 'package:effects':
## 
##     Prestige
# Importando Dados

bateria<-read.table("bateria.txt" , h =T)
# Definindo Diretório de Trabalho

setwd("C:/Users/aluno/Documents")

# Pacotes que serão utilizados

library(agricolae)

library(ggplot2)

library(effects) # Gráfico de Efeitos

library(car) # Teste de Fligner???Killeen
# V e r i f i c a n d o o s dad o s

str (bateria)
## 'data.frame':    36 obs. of  3 variables:
##  $ y   : int  130 155 74 180 150 188 159 126 138 110 ...
##  $ mat : int  1 1 1 1 2 2 2 2 3 3 ...
##  $ temp: int  15 15 15 15 15 15 15 15 15 15 ...
summary(bateria)
##        y              mat         temp    
##  Min.   : 20.0   Min.   :1   Min.   : 15  
##  1st Qu.: 70.0   1st Qu.:1   1st Qu.: 15  
##  Median :108.0   Median :2   Median : 70  
##  Mean   :105.5   Mean   :2   Mean   : 70  
##  3rd Qu.:141.8   3rd Qu.:3   3rd Qu.:125  
##  Max.   :188.0   Max.   :3   Max.   :125
# Convertendo Material e Temperatura em Fatores

bateria$mat<-as.factor(bateria$mat)

bateria$temp<-as.factor(bateria$temp)

str(bateria)
## 'data.frame':    36 obs. of  3 variables:
##  $ y   : int  130 155 74 180 150 188 159 126 138 110 ...
##  $ mat : Factor w/ 3 levels "1","2","3": 1 1 1 1 2 2 2 2 3 3 ...
##  $ temp: Factor w/ 3 levels "15","70","125": 1 1 1 1 1 1 1 1 1 1 ...
# Análise Gráfica dos Dados

interaction.plot(bateria$temp, bateria$mat, bateria$y, type="b" , pch=19, fixed=T, xlab="Temperatura_(F)", ylab="Vida_Média_(em_h)" )

# Estimação do Modelo: Forma 1
bateria.aov<-aov(y~mat+temp+mat:temp,data=bateria)

#  Estimação do Modelo: : Forma 2
bateria.aov<-aov(y~mat*temp,data=bateria)

# Tabela da ANAVA
summary(bateria.aov)
##             Df Sum Sq Mean Sq F value   Pr(>F)    
## mat          2  10684    5342   7.911  0.00198 ** 
## temp         2  39119   19559  28.968 1.91e-07 ***
## mat:temp     4   9614    2403   3.560  0.01861 *  
## Residuals   27  18231     675                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Verufuca Normalidade e Variâncias Homogêneas

plot(bateria.aov, which=1) # Residuos x Valores previstos

plot(bateria.aov, which=2) #grafico qqnorm

#### Teste de Shapiro-Wilks: H0 : os dados tem dist. aprox. normal

shapiro.test(bateria.aov$residuals)
## 
##  Shapiro-Wilk normality test
## 
## data:  bateria.aov$residuals
## W = 0.9761, p-value = 0.6117
#### Teste de Fligner-Killeen : H0 : Variância dos resíduos

fligner.test(y~interaction(mat,temp), data=bateria)
## 
##  Fligner-Killeen test of homogeneity of variances
## 
## data:  y by interaction(mat, temp)
## Fligner-Killeen:med chi-squared = 5.667, df = 8, p-value = 0.6845
# Gráfico dos Efeitos R base

plot.design(y~mat*temp, data=bateria)

# Gráfico dos Efeitos Pacote effects

plot(allEffects(bateria.aov))

# Necessário para os testes com agricolae

inter <- with(bateria, interaction(mat, temp))

amod <- aov(y~inter, data=bateria)

HSD.test(amod, "inter", group=TRUE, console = TRUE)
## 
## Study: amod ~ "inter"
## 
## HSD Test for y 
## 
## Mean Square Error:  675.213 
## 
## inter,  means
## 
##            y      std r Min Max
## 1.125  57.50 26.85144 4  20  82
## 1.15  134.75 45.35324 4  74 180
## 1.70   57.25 23.59908 4  34  80
## 2.125  49.50 19.26136 4  25  70
## 2.15  155.75 25.61738 4 126 188
## 2.70  119.75 12.65899 4 106 136
## 3.125  85.50 19.27866 4  60 104
## 3.15  144.00 25.97435 4 110 168
## 3.70  145.75 22.54440 4 120 174
## 
## alpha: 0.05 ; Df Error: 27 
## Critical Value of Studentized Range: 4.7584 
## 
## Honestly Significant Difference: 61.82318 
## 
## Means with the same letter are not significantly different.
## 
## Groups, Treatments and means
## a     2.15    155.8 
## ab    3.70    145.8 
## ab    3.15    144 
## ab    1.15    134.8 
## ab    2.70    119.8 
## bc    3.125   85.5 
## c     1.125   57.5 
## c     1.70    57.25 
## c     2.125   49.5
library(pwr)
## Warning: package 'pwr' was built under R version 3.1.3
pwr.anova.test(k=5, f=.25, sig.level=.05, power=.8)
## 
##      Balanced one-way analysis of variance power calculation 
## 
##               k = 5
##               n = 39.1534
##               f = 0.25
##       sig.level = 0.05
##           power = 0.8
## 
## NOTE: n is number in each group