library(tidyverse)
## -- Attaching packages -------------------------------------------- tidyverse 1.2.1 --
## v ggplot2 3.0.0 v purrr 0.2.5
## v tibble 1.4.2 v dplyr 0.7.6
## v tidyr 0.8.1 v stringr 1.3.1
## v readr 1.1.1 v forcats 0.3.0
## -- Conflicts ----------------------------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(lmPerm)
library(DescTools)
## # A tibble: 3 x 3
## group media mediana
## <fct> <dbl> <dbl>
## 1 G1 1.38 1.30
## 2 G2 0.674 0.768
## 3 G3 2.36 2.05
## [1] "Settings: unique SS "
## Component 1 :
## Df R Sum Sq R Mean Sq Iter Pr(Prob)
## e1$group 2 7.1354 3.5677 2189 0.07035 .
## Residuals 12 14.3153 1.1929
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## Df Sum Sq Mean Sq F value Pr(>F)
## e1$group 2 7.135 3.568 2.991 0.0883 .
## Residuals 12 14.315 1.193
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Resposta: Os resultados foram próximos, porém, como são feitas permutações, os resultados serão divergentes, a menos que sejam gerados pela mesma semente.
## # A tibble: 5 x 3
## altura_carro media mediana
## <fct> <dbl> <dbl>
## 1 1700 lb 672. 682.
## 2 2300 lb 988 1016
## 3 2800 lb 1093 1113
## 4 3200 lb 999. 998
## 5 3700 lb 977. 1132
## [1] "Settings: unique SS "
## Component 1 :
## Df R Sum Sq R Mean Sq Iter Pr(Prob)
## e2$altura_carro 4 739298 184824 473 0.4968
## Residuals 49 8842320 180456
## Df Sum Sq Mean Sq F value Pr(>F)
## e2$altura_carro 4 739298 184824 1.024 0.404
## Residuals 49 8842320 180456
## # A tibble: 5 x 2
## altura_carro normalidade_p_valor
## <fct> <dbl>
## 1 1700 lb 0.862
## 2 2300 lb 0.546
## 3 2800 lb 0.836
## 4 3200 lb 0.231
## 5 3700 lb 0.622
Resposta: O teste de normalidade de shapiro wilk tras evidencias de que os dados sao normais contudo, a amostra é pequena e o poder deste teste é fortemente influenciado pelo tamanho amostral. Sendo assim, o melhor observar algo mais empirico com um grafico ou utilizar os testes nao-parametricos.
##
## Kruskal-Wallis rank sum test
##
## data: e1$x by e1$group
## Kruskal-Wallis chi-squared = 5.78, df = 2, p-value = 0.05558
Resposta: O teste de Kruskal - wallis está mais proximo de rejeitar a hipotese nula de que nao ha diferença entre os grupos.
## tratamento x
## 1 T1 0
## 2 T1 2
## 3 T1 1
## 4 T1 3
## 5 T1 1
## 6 T1 1
## 7 T2 2
## 8 T2 0
## 9 T2 3
## 10 T2 1
## 11 T2 3
## 12 T2 4
## 13 T3 1
## 14 T3 3
## 15 T3 4
## 16 T3 2
## 17 T3 2
## 18 T3 1
## 19 T4 3
## 20 T4 4
## 21 T4 2
## 22 T4 5
## 23 T4 3
## 24 T4 4
##
## Kruskal-Wallis rank sum test
##
## data: e5$x by e5$tratamento
## Kruskal-Wallis chi-squared = 7.6301, df = 3, p-value = 0.05431
## # A tibble: 4 x 3
## tratamento media mediana
## <fct> <dbl> <dbl>
## 1 T1 1.33 1
## 2 T2 2.17 2.5
## 3 T3 2.17 2
## 4 T4 3.5 3.5
## # A tibble: 7 x 3
## type media mediana
## <fct> <dbl> <dbl>
## 1 compact 967. 1014
## 2 heavy 708. 546
## 3 light 1032. 994
## 4 medium 786. 722.
## 5 mpv 1165. 1148.
## 6 pickup 1072 1030.
## 7 van 1325. 1252.
##
## Nemenyi's test of multiple comparisons for independent samples (tukey)
##
## mean.rank.diff pval
## heavy-compact -14.7 0.6725
## light-compact 2.9 0.9999
## medium-compact -12.2 0.8329
## mpv-compact 11.5 0.8686
## pickup-compact 6.9 0.9887
## van-compact 14.7 0.6725
## light-heavy 17.6 0.4577
## medium-heavy 2.5 1.0000
## mpv-heavy 26.2 0.0609 .
## pickup-heavy 21.6 0.2099
## van-heavy 29.4 0.0211 *
## medium-light -15.1 0.6435
## mpv-light 8.6 0.9652
## pickup-light 4.0 0.9995
## van-light 11.8 0.8538
## mpv-medium 23.7 0.1246
## pickup-medium 19.1 0.3533
## van-medium 26.9 0.0490 *
## pickup-mpv -4.6 0.9988
## van-mpv 3.2 0.9999
## van-pickup 7.8 0.9787
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Dunn's test of multiple comparisons using rank sums : holm
##
## mean.rank.diff pval
## heavy-compact -14.7 1.0000
## light-compact 2.9 1.0000
## medium-compact -12.2 1.0000
## mpv-compact 11.5 1.0000
## pickup-compact 6.9 1.0000
## van-compact 14.7 1.0000
## light-heavy 17.6 0.7970
## medium-heavy 2.5 1.0000
## mpv-heavy 26.2 0.0758 .
## pickup-heavy 21.6 0.2996
## van-heavy 29.4 0.0260 *
## medium-light -15.1 1.0000
## mpv-light 8.6 1.0000
## pickup-light 4.0 1.0000
## van-light 11.8 1.0000
## mpv-medium 23.7 0.1658
## pickup-medium 19.1 0.5735
## van-medium 26.9 0.0624 .
## pickup-mpv -4.6 1.0000
## van-mpv 3.2 1.0000
## van-pickup 7.8 1.0000
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Resposta: Os grupos que apresentam diferencas entre si a um nível de 95% de confiança são van vs heavy e van vs medium.
## location x
## 1 1 26.5
## 2 1 15.0
## 3 1 18.2
## 4 1 19.5
## 5 1 23.1
## 6 1 17.3
## 7 2 16.5
## 8 2 15.8
## 9 2 14.1
## 10 2 30.2
## 11 2 25.1
## 12 2 17.4
## 13 3 19.2
## 14 3 21.4
## 15 3 26.0
## 16 3 21.6
## 17 3 35.0
## 18 3 28.9
## 19 4 26.7
## 20 4 37.3
## 21 4 28.0
## 22 4 30.1
## 23 4 33.5
## 24 4 26.3
##
## Kruskal-Wallis rank sum test
##
## data: x by location
## Kruskal-Wallis chi-squared = 10.287, df = 3, p-value = 0.01628
## # A tibble: 4 x 3
## location media mediana
## <fct> <dbl> <dbl>
## 1 1 19.9 18.8
## 2 2 19.8 17.0
## 3 3 25.4 23.8
## 4 4 30.3 29.0
##
## Dunn's test of multiple comparisons using rank sums : holm
##
## mean.rank.diff pval
## 2-1 -0.500000 0.9025
## 3-1 5.666667 0.5236
## 4-1 10.833333 0.0398 *
## 3-2 6.166667 0.5236
## 4-2 11.333333 0.0330 *
## 4-3 5.166667 0.5236
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Jonckheere-Terpstra test
##
## data: table3.4.1$x and table3.4.1$treatment
## JT = 145, p-value = 0.02991
## alternative hypothesis: increasing
##
## Kruskal-Wallis rank sum test
##
## data: table3.4.1$x and table3.4.1$treatment
## Kruskal-Wallis chi-squared = 3.46, df = 3, p-value = 0.326
##
## Wilcoxon rank sum test
##
## data: x by treatment
## W = 14, p-value = 0.5887
## alternative hypothesis: true location shift is not equal to 0
##
## Wilcoxon rank sum test
##
## data: x by treatment
## W = 12, p-value = 0.3939
## alternative hypothesis: true location shift is not equal to 0
##
## Wilcoxon rank sum test
##
## data: x by treatment
## W = 6, p-value = 0.06494
## alternative hypothesis: true location shift is not equal to 0
##
## Wilcoxon rank sum test
##
## data: x by treatment
## W = 14, p-value = 0.5887
## alternative hypothesis: true location shift is not equal to 0
##
## Wilcoxon rank sum test
##
## data: x by treatment
## W = 14, p-value = 0.5887
## alternative hypothesis: true location shift is not equal to 0
##
## Wilcoxon rank sum test
##
## data: x by treatment
## W = 11, p-value = 0.3095
## alternative hypothesis: true location shift is not equal to 0
## [1] 71
## altura_carro x
## 1 1700 lb 574
## 2 1700 lb 976
## 3 1700 lb 789
## 4 1700 lb 805
## 5 1700 lb 361
## 6 1700 lb 529
## 7 2300 lb 791
## 8 2300 lb 1146
## 9 2300 lb 394
## 10 2300 lb 767
## 11 2300 lb 1385
## 12 2300 lb 1021
## 13 2300 lb 2073
## 14 2300 lb 803
## 15 2300 lb 1263
## 16 2300 lb 1016
## 17 2300 lb 1101
## 18 2300 lb 945
## 19 2300 lb 139
## 20 2800 lb 865
## 21 2800 lb 775
## 22 2800 lb 729
## 23 2800 lb 1721
## 24 2800 lb 1113
## 25 2800 lb 820
## 26 2800 lb 1613
## 27 2800 lb 1404
## 28 2800 lb 1201
## 29 2800 lb 205
## 30 2800 lb 1380
## 31 2800 lb 580
## 32 2800 lb 1803
## 33 3200 lb 998
## 34 3200 lb 1049
## 35 3200 lb 736
## 36 3200 lb 782
## 37 3200 lb 730
## 38 3200 lb 742
## 39 3200 lb 1219
## 40 3200 lb 705
## 41 3200 lb 1260
## 42 3200 lb 611
## 43 3200 lb 1350
## 44 3200 lb 1657
## 45 3200 lb 1143
## 46 3700 lb 1154
## 47 3700 lb 541
## 48 3700 lb 406
## 49 3700 lb 1529
## 50 3700 lb 1132
## 51 3700 lb 767
## 52 3700 lb 1224
## 53 3700 lb 314
## 54 3700 lb 1728
##
## Jonckheere-Terpstra test
##
## data: e2$x and ordered(e2$altura_carro)
## JT = 629.5, p-value = 0.196
## alternative hypothesis: increasing
## Warning in JonckheereTerpstraTest.default(e2$x, ordered(e2$altura_carro), : Sample size > 100 or data with ties
## p-value based on normal approximation. Specify nperm for permutation p-value
##
## Jonckheere-Terpstra test
##
## data: e2$x and ordered(e2$altura_carro)
## JT = 629.5, p-value = 0.1933
## alternative hypothesis: increasing
Resposta: Mesmo com o teste de tendencia de Jonckheere-Terpstra, a hipotese de que nnada acontece com x a medida que aumenta o peso dos carros nao é rejeitada.
## Warning in JonckheereTerpstraTest.default(e10$x, e10$c, alternative = "increasing"): Sample size > 100 or data with ties
## p-value based on normal approximation. Specify nperm for permutation p-value
##
## Jonckheere-Terpstra test
##
## data: e10$x and e10$c
## JT = 4757, p-value = 0.0009565
## alternative hypothesis: increasing
##
## Kruskal-Wallis rank sum test
##
## data: e10$x and e10$c
## Kruskal-Wallis chi-squared = 10.191, df = 3, p-value = 0.01701
Eles controlam a taxa de erro ao nível de significância ?? para cada comparação dois a dois, mas não controlam a taxa de erro do experimento.
Se apenas um (ou alguns) dos tratamentos forem diferentes o método pode levar a muitas conclusões falsas de significância estatística, então o erro geral do tipo I não será bem controlado.
Por isso este método não é recomendado.