Questão 1

1. Desenho do estudo, número de tratamentos, repetições, blocos;

É um estudo com delineamento em blocos completos casualizados, e, nesse caso, cada corredor é um bloco e cada trajeto para a “Second Base” é um tratamento. São três tratamentos, além de 22 repetições de cada um deles.

banco1 <- read_csv2("tarefa3_q1.csv")

kable(banco1)
Player Round-Out Narrow Angle Wide Angle
1 5.40 5.50 5.55
2 5.85 5.70 5.75
3 5.20 5.60 5.50
4 5.55 5.50 5.40
5 5.90 5.85 5.70
6 5.45 5.55 5.60
7 5.40 5.40 5.35
8 5.45 5.50 5.35
9 5.25 5.15 5.00
10 5.85 5.80 5.70
11 5.25 5.20 5.10
12 5.65 5.55 5.45
13 5.60 5.35 5.45
14 5.05 5.00 4.95
15 5.50 5.50 5.40
16 5.45 5.55 5.50
17 5.55 5.55 5.35
18 5.45 5.50 5.55
19 5.50 5.45 5.25
20 5.65 5.60 5.40
21 5.70 5.65 5.55
22 6.30 6.30 6.25

2. Análise descritiva dos dados

descritivas <- describe(banco1[,2:4])
descritivas <- descritivas[c("mean", "sd", "median", "min", "max", "range", "skew", "kurtosis")]
kable(descritivas)
mean sd median min max range skew kurtosis
Round-Out 5.543182 0.2718085 5.500 5.05 6.30 1.25 0.7313876 0.7627524
Narrow Angle 5.534091 0.2597555 5.525 5.00 6.30 1.30 0.6498997 1.7642598
Wide Angle 5.459091 0.2728319 5.450 4.95 6.25 1.30 0.5905425 1.4002740
banco1 <- banco1 %>%
  gather(coluna, valor)


ggplot(data = banco1[23:88, ], aes(x = coluna, y = valor, fill = coluna)) +
  geom_boxplot(color = "black") +
  stat_summary(geom = "point", fun = "mean", shape = 10, size = 3, color = "red") +
  labs(x = "Trajetos de corrida", y = "Tempo(s)", title = "Trajeto vs. Tempo") +
  theme_replace() + 
  geom_jitter() +  
  theme(plot.title = element_text(hjust = 0.5),
        axis.text.x = element_text(face = "bold"),
        axis.text.y = element_text(face = "bold")) +
  scale_fill_manual(values = brewer.pal(n = 3, name = "Accent")) +
  geom_errorbar(stat = "boxplot", 
                width = 0.2)

ggplot(data = banco1[23:88, ], aes(x = valor)) +
  geom_histogram(fill = "steelblue", color = "black") +
  geom_density(color = "red", fill = "red", alpha = 0.15) + 
  facet_wrap(~ coluna, scales = "free", strip.position = "bottom") +
  labs(x = "Tempo", y = "Frequência", title = "Histogramas de cada trajeto") +
  theme_replace() +
  theme(strip.placement = "outside",
        strip.text = element_text(hjust = 0.5),    
        plot.title = element_text(hjust = 0.5),
        axis.text.x = element_text(face = "bold"),
        axis.text.y = element_text(face = "bold")) 

3. Utilize o modelo adequado de ANOVA, descreva e interprete os resultados (considere α = 0,05)

banco_anova1 <- read.csv2("tarefa3_q1.csv")

banco_anova1 <- banco_anova1 %>%
  gather(trajeto, tempo, -Player) 

banco_anova1 <- banco_anova1 %>% arrange(sample(n()))
banco_anova1 <- banco_anova1 %>% arrange(Player)
banco_anova1$Player <- as.factor(banco_anova1$Player)

anova_1 <- aov(tempo ~ trajeto + Player, data = banco_anova1)
summary(anova_1)
##             Df Sum Sq Mean Sq F value  Pr(>F)    
## trajeto      2  0.094 0.04686   6.288 0.00408 ** 
## Player      21  4.219 0.20089  26.960 < 2e-16 ***
## Residuals   42  0.313 0.00745                    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Considerando um \(\alpha = 0.05\), ao realizar a ANOVA, podemos dizer que tanto o tratamento (diferentes trajetos), como também os blocos (cada corredor) tem um efeito significativo, com p-valor de \(0.004\) e < \(2 x 10^{-16}\), respectivamente. Dessa forma, podemos afirmar que existe uma diferença significativa entre as médias dos grupos.

lm_1 <- lm(tempo ~ trajeto + Player, banco_anova1)
summary(lm_1)
## 
## Call:
## lm(formula = tempo ~ trajeto + Player, data = banco_anova1)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.264394 -0.030303 -0.005303  0.036174  0.144697 
## 
## Coefficients:
##                     Estimate Std. Error t value Pr(>|t|)    
## (Intercept)        5.505e+00  5.205e-02 105.762  < 2e-16 ***
## trajetoRound.Out   9.091e-03  2.603e-02   0.349 0.728616    
## trajetoWide.Angle -7.500e-02  2.603e-02  -2.882 0.006208 ** 
## Player2            2.833e-01  7.048e-02   4.020 0.000237 ***
## Player3           -5.000e-02  7.048e-02  -0.709 0.481988    
## Player4            2.113e-15  7.048e-02   0.000 1.000000    
## Player5            3.333e-01  7.048e-02   4.729 2.55e-05 ***
## Player6            5.000e-02  7.048e-02   0.709 0.481988    
## Player7           -1.000e-01  7.048e-02  -1.419 0.163328    
## Player8           -5.000e-02  7.048e-02  -0.709 0.481988    
## Player9           -3.500e-01  7.048e-02  -4.966 1.19e-05 ***
## Player10           3.000e-01  7.048e-02   4.256 0.000114 ***
## Player11          -3.000e-01  7.048e-02  -4.256 0.000114 ***
## Player12           6.667e-02  7.048e-02   0.946 0.349618    
## Player13          -1.667e-02  7.048e-02  -0.236 0.814217    
## Player14          -4.833e-01  7.048e-02  -6.858 2.32e-08 ***
## Player15          -1.667e-02  7.048e-02  -0.236 0.814217    
## Player16           1.667e-02  7.048e-02   0.236 0.814217    
## Player17           1.718e-15  7.048e-02   0.000 1.000000    
## Player18           1.667e-02  7.048e-02   0.236 0.814217    
## Player19          -8.333e-02  7.048e-02  -1.182 0.243715    
## Player20           6.667e-02  7.048e-02   0.946 0.349618    
## Player21           1.500e-01  7.048e-02   2.128 0.039228 *  
## Player22           8.000e-01  7.048e-02  11.351 2.24e-14 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.08632 on 42 degrees of freedom
## Multiple R-squared:  0.9323, Adjusted R-squared:  0.8953 
## F-statistic: 25.16 on 23 and 42 DF,  p-value: < 2.2e-16
cv.model(anova_1)
## [1] 1.56602

Também podemos dizer que há um \(R^2\) bem alto de \(0.93\), além de coeficiente de variação de \(1.56\).

4. Avalie se os pressupostos do modelo foram atendidos.

Para que a ANOVA sejá válida, vamos checar seus pressupostos, tanto de normalidade dos resíduos, quanto de homogeneidade das variâncias como também da independência entre os erros.

plot(anova_1, which = 1)

Graficamente, não conseguimos encontrar um padrão de “funil”, que poderia indicar heterocedasticidade das variâncias dos resíduos.

leveneTest(tempo ~ trajeto, data = banco_anova1, center= mean)
## Levene's Test for Homogeneity of Variance (center = mean)
##       Df F value Pr(>F)
## group  2  0.1531 0.8584
##       63
leveneTest(tempo ~ trajeto, data = banco_anova1, center=median)
## Levene's Test for Homogeneity of Variance (center = median)
##       Df F value Pr(>F)
## group  2   0.117 0.8897
##       63

Podemos usar os testes de Levene e Brown-Forsythe. Ambos resultados indicam que não podemos rejeitar a hipótese nula de homogeneidade.

residuos <- resid(anova_1)

qqplot_1 <- ggplot(data.frame(residuos), aes(sample = residuos)) +
  stat_qq() +
  stat_qq_line() +
  labs(title = "Q-Q Plot", x = "Quantil teórico", y = "Quantil observado") + 
  theme_replace() +
  theme(  
        plot.title = element_text(hjust = 0.5),
        axis.text.x = element_text(face = "bold"),
        axis.text.y = element_text(face = "bold")) 

hist_1 <- ggplot(data.frame(residuos), aes(x = residuos)) +
  geom_histogram(fill = "lightblue", color = "black") +
  labs(x = "Resíduos", y = "Frequência", title = "Histograma dos Resíduos") + 
  geom_density(color = "red") +
  theme_replace() +
  theme(  
        plot.title = element_text(hjust = 0.5),
        axis.text.x = element_text(face = "bold"),
        axis.text.y = element_text(face = "bold"))

plot_grid(qqplot_1, hist_1)

Para a normalidade dos resíduos, graficamente podemos ver tanto pelo qqplot quanto pelo histograma que não parece haver uma normalidade dos resíduos.

shapiro.test(residuos)
## 
##  Shapiro-Wilk normality test
## 
## data:  residuos
## W = 0.95277, p-value = 0.01356

Pelo teste de Shapiro-Wilk, podemos afirmar que não há de fato normalidade. Mas, como é uma amostra relativamente pequena, podemos relevar uma flutuação pequena como essa.

dwtest(lm_1)
## 
##  Durbin-Watson test
## 
## data:  lm_1
## DW = 2.2885, p-value = 0.04235
## alternative hypothesis: true autocorrelation is greater than 0

Observamos que os erros são independentes.

5. Realize a complementação adequada.

LSD.test(anova_1, "trajeto", console=T, alpha = 0.05)
## 
## Study: anova_1 ~ "trajeto"
## 
## LSD t Test for tempo 
## 
## Mean Square Error:  0.007451299 
## 
## trajeto,  means and individual ( 95 %) CI
## 
##                 tempo       std  r      LCL      UCL  Min  Max
## Narrow.Angle 5.534091 0.2597555 22 5.496951 5.571231 5.00 6.30
## Round.Out    5.543182 0.2718085 22 5.506042 5.580322 5.05 6.30
## Wide.Angle   5.459091 0.2728319 22 5.421951 5.496231 4.95 6.25
## 
## Alpha: 0.05 ; DF Error: 42
## Critical Value of t: 2.018082 
## 
## least Significant Difference: 0.05252407 
## 
## Treatments with the same letter are not significantly different.
## 
##                 tempo groups
## Round.Out    5.543182      a
## Narrow.Angle 5.534091      a
## Wide.Angle   5.459091      b
HSD.test(anova_1, 'trajeto', alpha = 0.05, console = TRUE, group=F)
## 
## Study: anova_1 ~ "trajeto"
## 
## HSD Test for tempo 
## 
## Mean Square Error:  0.007451299 
## 
## trajeto,  means
## 
##                 tempo       std  r  Min  Max
## Narrow.Angle 5.534091 0.2597555 22 5.00 6.30
## Round.Out    5.543182 0.2718085 22 5.05 6.30
## Wide.Angle   5.459091 0.2728319 22 4.95 6.25
## 
## Alpha: 0.05 ; DF Error: 42 
## Critical Value of Studentized Range: 3.435823 
## 
## Comparison between treatments means
## 
##                             difference pvalue signif.         LCL        UCL
## Narrow.Angle - Round.Out  -0.009090909 0.9351         -0.07232269 0.05414087
## Narrow.Angle - Wide.Angle  0.075000000 0.0167       *  0.01176822 0.13823178
## Round.Out - Wide.Angle     0.084090909 0.0066      **  0.02085913 0.14732269
plot(TukeyHSD(anova_1, which = 1))

Para analisarmos qual grupo tem uma média significativamente diferente dos demais, analisamos o teste de LSD (Least Significant Difference), o de HSD (Honesty Significant Difference) e seu gráfico.

Pelos resultados, percebemos que a média de tempo entre os trajetos “Narrow Angle” e “Round Out” não possui uma diferença significativa. Isto fica claro pelo gráfico, cuja barra inclui o valor \(0\). Assim, podemos dizer que o trajeto “Wide Angle” demanda um tempo médio menor para ser feito.

6. Qual a sua recomendação para Woodward?

Questão 2

1. Desenho do estudo, número de tratamentos, repetições, blocos;

banco2 <- read_csv2("tarefa3_q2.csv")
kable(banco2)
Julgador Receita Nota
1 1 3
1 2 3
1 3 3
2 4 9
2 5 3
2 6 5
3 7 5
3 8 6
3 9 4
4 1 6
4 4 7
4 7 3
5 2 6
5 5 6
5 8 3
6 3 5
6 6 6
6 9 2
7 1 4
7 5 5
7 9 1
8 2 2
8 6 3
8 7 6
9 3 6
9 4 10
9 8 5

Este estudo tem um delineamento de bloco incompleto. Dividimos em 9 tratamentos, com 3 repetições, e cada repetição contém os 9 tratamentos. Os blocos são os 9 julgadores, dividindo estes 9 blocos nas 3 repetições.

2. Considerando a dimensão 𝜆 para cada par de tratamento, esse delineamento é balanceado ou parcialmente balanceado?

Esse delineamento é parcialmente balanceado, pois nem todos pares se repetem, ou seja, temos que \(\lambda\) é igual a 0 ou 1, dependendo do par. Por exemplo, o par 1 e 2 se repete uma vez, já o par 1 e 6 não aparece em nenhum bloco.

3. Análise descritiva dos dados

banco2$Julgador <- as.factor(banco2$Julgador)
banco2$Receita <- as.factor(banco2$Receita)
banco2$rept <- as.factor((c(rep(1, 9), rep(2, 9), rep(3, 9))))


descritivas2 <- describe(banco2$Nota)

descritivas2 <- descritivas2[c("mean", "sd", "median", "min", "max", "range", "skew", "kurtosis")]
kable(descritivas2)
mean sd median min max range skew kurtosis
X1 4.703704 2.090543 5 1 10 9 0.5257998 -0.0338321
ggplot(data = banco2, aes(x = Receita, y = Nota, fill = Receita))+
  geom_boxplot(color = "black") +
  stat_summary(geom = "point", fun = "mean", shape = 10, size = 3, color = "white") +
  labs(x = "Receitas", y = "Notas", title = "Nota x Receita") +
  theme_replace() + 
  geom_jitter() +  
  theme(plot.title = element_text(hjust = 0.5),
        axis.text.x = element_text(face = "bold"),
        axis.text.y = element_text(face = "bold")) +
  scale_fill_brewer(palette = "Paired") +
  geom_errorbar(stat = "boxplot", 
                width = 0.4)

4. Utilize o modelo adequado de ANOVA, descreva e interprete os resultados (considere α = 0,05) – Análise Intrabloco ou com recuperação interbloco?

lm_2 <- lm(terms(Nota ~ rept/Julgador + Receita, keep_order = TRUE), data = banco2)
summary(lm_2)
## 
## Call:
## lm(formula = terms(Nota ~ rept/Julgador + Receita, keep_order = TRUE), 
##     data = banco2)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.46296 -0.74074 -0.07407  0.48148  2.25926 
## 
## Coefficients: (18 not defined because of singularities)
##                 Estimate Std. Error t value Pr(>|t|)  
## (Intercept)       3.6852     1.1720   3.144   0.0104 *
## rept2             2.3333     1.3925   1.676   0.1247  
## rept3             3.2778     1.3925   2.354   0.0404 *
## Receita2         -1.1667     1.3925  -0.838   0.4217  
## Receita3         -0.8889     1.3925  -0.638   0.5376  
## Receita4          3.1667     1.3925   2.274   0.0462 *
## Receita5         -0.7222     1.3925  -0.519   0.6153  
## Receita6         -0.5000     1.4770  -0.339   0.7420  
## Receita7         -0.7222     1.3925  -0.519   0.6153  
## Receita8         -2.1667     1.4770  -1.467   0.1731  
## Receita9         -3.6667     1.3925  -2.633   0.0250 *
## rept1:Julgador2   1.3333     1.4770   0.903   0.3879  
## rept2:Julgador2       NA         NA      NA       NA  
## rept3:Julgador2       NA         NA      NA       NA  
## rept1:Julgador3   3.5000     1.4770   2.370   0.0393 *
## rept2:Julgador3       NA         NA      NA       NA  
## rept3:Julgador3       NA         NA      NA       NA  
## rept1:Julgador4       NA         NA      NA       NA  
## rept2:Julgador4  -1.5000     1.4770  -1.016   0.3338  
## rept3:Julgador4       NA         NA      NA       NA  
## rept1:Julgador5       NA         NA      NA       NA  
## rept2:Julgador5   0.3333     1.4770   0.226   0.8260  
## rept3:Julgador5       NA         NA      NA       NA  
## rept1:Julgador6       NA         NA      NA       NA  
## rept2:Julgador6       NA         NA      NA       NA  
## rept3:Julgador6       NA         NA      NA       NA  
## rept1:Julgador7       NA         NA      NA       NA  
## rept2:Julgador7       NA         NA      NA       NA  
## rept3:Julgador7  -2.1667     1.4770  -1.467   0.1731  
## rept1:Julgador8       NA         NA      NA       NA  
## rept2:Julgador8       NA         NA      NA       NA  
## rept3:Julgador8  -2.5000     1.4770  -1.693   0.1214  
## rept1:Julgador9       NA         NA      NA       NA  
## rept2:Julgador9       NA         NA      NA       NA  
## rept3:Julgador9       NA         NA      NA       NA  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.477 on 10 degrees of freedom
## Multiple R-squared:  0.808,  Adjusted R-squared:  0.5008 
## F-statistic: 2.631 on 16 and 10 DF,  p-value: 0.06238
anova(lm_2)
## Analysis of Variance Table
## 
## Response: Nota
##               Df Sum Sq Mean Sq F value  Pr(>F)  
## rept           2  0.519  0.2593  0.1188 0.88918  
## Receita        8 67.630  8.4537  3.8752 0.02458 *
## rept:Julgador  6 23.667  3.9444  1.8081 0.19454  
## Residuals     10 21.815  2.1815                  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Pela ANOVA, temos que há uma diferença significativa entre as receitas, considerando \(\alpha = 0.05\) (temos um p-valor de \(0.02458\)).

5. Assuma que os pressupostos do modelo foram atendidos, realize a complementação adequada.

lsmeans(lm_2, pairwise ~ Receita, adjust = ("tukey"), data = banco2)
## $lsmeans
##  Receita lsmean    SE df lower.CL upper.CL
##  1         5.44 0.985 10    3.250     7.64
##  2         4.28 0.985 10    2.084     6.47
##  3         4.56 0.985 10    2.362     6.75
##  4         8.61 0.985 10    6.417    10.81
##  5         4.72 0.985 10    2.528     6.92
##  6         4.94 0.985 10    2.750     7.14
##  7         4.72 0.985 10    2.528     6.92
##  8         3.28 0.985 10    1.084     5.47
##  9         1.78 0.985 10   -0.416     3.97
## 
## Results are averaged over the levels of: Julgador, rept 
## Confidence level used: 0.95 
## 
## $contrasts
##  contrast            estimate   SE df t.ratio p.value
##  Receita1 - Receita2    1.167 1.39 10   0.838  0.9921
##  Receita1 - Receita3    0.889 1.39 10   0.638  0.9987
##  Receita1 - Receita4   -3.167 1.39 10  -2.274  0.4315
##  Receita1 - Receita5    0.722 1.39 10   0.519  0.9997
##  Receita1 - Receita6    0.500 1.48 10   0.339  1.0000
##  Receita1 - Receita7    0.722 1.39 10   0.519  0.9997
##  Receita1 - Receita8    2.167 1.48 10   1.467  0.8478
##  Receita1 - Receita9    3.667 1.39 10   2.633  0.2799
##  Receita2 - Receita3   -0.278 1.39 10  -0.199  1.0000
##  Receita2 - Receita4   -4.333 1.48 10  -2.934  0.1878
##  Receita2 - Receita5   -0.444 1.39 10  -0.319  1.0000
##  Receita2 - Receita6   -0.667 1.39 10  -0.479  0.9998
##  Receita2 - Receita7   -0.444 1.39 10  -0.319  1.0000
##  Receita2 - Receita8    1.000 1.39 10   0.718  0.9971
##  Receita2 - Receita9    2.500 1.48 10   1.693  0.7399
##  Receita3 - Receita4   -4.056 1.39 10  -2.912  0.1934
##  Receita3 - Receita5   -0.167 1.48 10  -0.113  1.0000
##  Receita3 - Receita6   -0.389 1.39 10  -0.279  1.0000
##  Receita3 - Receita7   -0.167 1.48 10  -0.113  1.0000
##  Receita3 - Receita8    1.278 1.39 10   0.918  0.9862
##  Receita3 - Receita9    2.778 1.39 10   1.995  0.5763
##  Receita4 - Receita5    3.889 1.39 10   2.793  0.2272
##  Receita4 - Receita6    3.667 1.39 10   2.633  0.2799
##  Receita4 - Receita7    3.889 1.39 10   2.793  0.2272
##  Receita4 - Receita8    5.333 1.39 10   3.830  0.0523
##  Receita4 - Receita9    6.833 1.48 10   4.627  0.0166
##  Receita5 - Receita6   -0.222 1.39 10  -0.160  1.0000
##  Receita5 - Receita7    0.000 1.48 10   0.000  1.0000
##  Receita5 - Receita8    1.444 1.39 10   1.037  0.9719
##  Receita5 - Receita9    2.944 1.39 10   2.114  0.5122
##  Receita6 - Receita7    0.222 1.39 10   0.160  1.0000
##  Receita6 - Receita8    1.667 1.48 10   1.128  0.9556
##  Receita6 - Receita9    3.167 1.39 10   2.274  0.4315
##  Receita7 - Receita8    1.444 1.39 10   1.037  0.9719
##  Receita7 - Receita9    2.944 1.39 10   2.114  0.5122
##  Receita8 - Receita9    1.500 1.39 10   1.077  0.9654
## 
## Results are averaged over the levels of: Julgador, rept 
## P value adjustment: tukey method for comparing a family of 9 estimates

Usando a função “lsmeans”, que calcula médias dos mínimos quadrados para fatores em um modelo linear, assim como os contrastes entre eles. Para calcular os valores críticos e os p-valores, usamos o teste HSD de Tukey.

6. Qual a sua indicação de receita para maior aceitabilidade do alimento em questão?