12/10/2016
prop.test(22, 30)
## ## 1-sample proportions test with continuity correction ## ## data: 22 out of 30, null probability 0.5 ## X-squared = 5.6333, df = 1, p-value = 0.01762 ## alternative hypothesis: true p is not equal to 0.5 ## 95 percent confidence interval: ## 0.5382722 0.8702456 ## sample estimates: ## p ## 0.7333333
Os testes eventualmente podem levar a conclusƵes erradas:
masc <- survey %>% filter(Sex == 'Male') fem <- survey %>% filter(Sex == 'Female') # OBS.: conf.level = 1 - alfa. O padrão é 0.95 t.test(masc$Height, fem$Height, conf.level = 0.95)
## ## Welch Two Sample t-test ## ## data: masc$Height and fem$Height ## t = 12.924, df = 192.7, p-value < 2.2e-16 ## alternative hypothesis: true difference in means is not equal to 0 ## 95 percent confidence interval: ## 11.13420 15.14454 ## sample estimates: ## mean of x mean of y ## 178.8260 165.6867
Teste T pode ser pensado como uma hipótese sobre a relação entre uma variĆ”vel numĆ©rica e uma variĆ”vel binĆ”ria (categórica com 2 valores possĆveis):
t.test(survey$Height ~ survey$Sex)
## ## Welch Two Sample t-test ## ## data: survey$Height by survey$Sex ## t = -12.924, df = 192.7, p-value < 2.2e-16 ## alternative hypothesis: true difference in means is not equal to 0 ## 95 percent confidence interval: ## -15.14454 -11.13420 ## sample estimates: ## mean in group Female mean in group Male ## 165.6867 178.8260
?MASS::survey)shapiro.test e ks.test (ou graficamente com um histograma ou um Q-Q plot)var.test (ou graficamente com um Q-Q plot)H0: população possui distribuição normal
shapiro.test(masc$Height)
## ## Shapiro-Wilk normality test ## ## data: masc$Height ## W = 0.99175, p-value = 0.7719
shapiro.test(fem$Height)
## ## Shapiro-Wilk normality test ## ## data: fem$Height ## W = 0.98027, p-value = 0.1313
hist(masc$Height)
hist(fem$Height)
qqnorm(masc$Height) qqline(masc$Height)
qqnorm(fem$Height) qqline(fem$Height)
var.test(masc$Height, fem$Height)
## ## F test to compare two variances ## ## data: masc$Height and fem$Height ## F = 1.8557, num df = 105, denom df = 101, p-value = 0.001951 ## alternative hypothesis: true ratio of variances is not equal to 1 ## 95 percent confidence interval: ## 1.257430 2.734627 ## sample estimates: ## ratio of variances ## 1.855722
t.test do R usa o teste T de Welch
Note a linha: "Welch Two Sample t-test"
t.test(survey$Height ~ survey$Sex)
## ## Welch Two Sample t-test ## ## data: survey$Height by survey$Sex ## t = -12.924, df = 192.7, p-value < 2.2e-16 ## alternative hypothesis: true difference in means is not equal to 0 ## 95 percent confidence interval: ## -15.14454 -11.13420 ## sample estimates: ## mean in group Female mean in group Male ## 165.6867 178.8260
Exemplo: a mĆ£o que escreve (Wr.Hnd) e a outra mĆ£o (NW.Hnd) possuem tamanhos diferentes, medidos da ponta do polegar Ć ponta do dedo mĆnimo?
hist(survey$Wr.Hnd - survey$NW.Hnd)
shapiro.test(survey$Wr.Hnd - survey$NW.Hnd)
## ## Shapiro-Wilk normality test ## ## data: survey$Wr.Hnd - survey$NW.Hnd ## W = 0.8757, p-value = 5.786e-13
A mĆ£o que escreve (Wr.Hnd) e a outra mĆ£o (NW.Hnd) possuem tamanhos diferentes, medidos da ponta do polegar Ć ponta do dedo mĆnimo?
(OBS.: nesse caso não devemos usar o teste T pois não atendemos ao pressuposto de normalidade!)
t.test(survey$Wr.Hnd, survey$NW.Hnd, paired=TRUE)
## ## Paired t-test ## ## data: survey$Wr.Hnd and survey$NW.Hnd ## t = 2.1268, df = 235, p-value = 0.03448 ## alternative hypothesis: true difference in means is not equal to 0 ## 95 percent confidence interval: ## 0.006367389 0.166513967 ## sample estimates: ## mean of the differences ## 0.08644068
NĆŗmero de testes executados Ć© diferente comparando projetos em Java e em Ruby?
boxplot(builds100$tr_tests_run ~ builds100$gh_lang)
wilcox.test(builds100$tr_tests_run ~ builds100$gh_lang)
## Warning in wilcox.test.default(x = c(0L, 3L, 1148L, 136L, 179L, 147L), y = ## c(718L, : cannot compute exact p-value with ties
## ## Wilcoxon rank sum test with continuity correction ## ## data: builds100$tr_tests_run by builds100$gh_lang ## W = 68, p-value = 0.09294 ## alternative hypothesis: true location shift is not equal to 0
Existe diferença entre o número de arquivos adicionados e o número de arquivos removidos em cada build?
boxplot(1+builds100$gh_files_added, 1+builds100$gh_files_modified, log="y")
wilcox.test(builds100$gh_files_added, builds100$gh_files_modified, paired=T)
## ## Wilcoxon signed rank test with continuity correction ## ## data: builds100$gh_files_added and builds100$gh_files_modified ## V = 105.5, p-value = 7.472e-16 ## alternative hypothesis: true location shift is not equal to 0
| paramétrico | não-paramétrico | |
|---|---|---|
| independentes | Teste T | Teste U (Mann-Whitney) |
| pareados | Teste T pareado | Teste de Wilcoxon pareado |
ObservaƧƵes:
| paramétrico | não-paramétrico | |
|---|---|---|
| independentes | t.test(...) |
wilcox.test(...) |
| pareados | t.test(..., paired=T) |
wilcox.test(..., paired=T) |
Resultado estatisticamente significativo nem sempre Ć© significativo:
compute.es do R)A taxa de batimentos cardĆacos depende da frequĆŖncia de exercĆcio dos alunos (frequente, algum, nenhum)?
summary(aov(survey$Pulse ~ survey$Exer))
## Df Sum Sq Mean Sq F value Pr(>F) ## survey$Exer 2 900 450.2 3.378 0.0362 * ## Residuals 189 25188 133.3 ## --- ## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 ## 45 observations deleted due to missingness
Considere os bugs de um projeto de software, que podem ser classificados quanto à severidade (severo ou não-severo) e prioridade (prioritÔrio e não-prioritÔrio). Podemos sumarizar os dados através de uma tabela de contingência 2x2:
bugs2 <- bugs %>% mutate(prioritario = priority %in% c('P1', 'P2'),
severo = severity %in% c('blocker', 'critical', 'major'))
tab <- xtabs(~ prioritario + severo, data=bugs2)
tab
## severo ## prioritario FALSE TRUE ## FALSE 3471 16908 ## TRUE 511 6529
As duas variÔveis (severidade e prioridade) são nomais. SerÔ que elas são independentes? Podemos visualizar com um mosaic plot:
mosaicplot(tab, shade=T)
A distribuição dos status das builds depende da linguagem de programação? Status = canceled, errored, failed, passed ou started; linguagem = Java ou Ruby.
tab <- xtabs(~ gh_lang + tr_status, data=builds) tab
## tr_status ## gh_lang canceled errored failed passed started ## java 78 3197 4191 17733 2 ## ruby 885 11114 17732 74831 0
A distribuição dos status das builds depende da linguagem de programação? Status = canceled, errored, failed, passed ou started; linguagem = Java ou Ruby.
tab <- xtabs(~ gh_lang + tr_status, data=builds) chisq.test(tab)
## Warning in chisq.test(tab): Chi-squared approximation may be incorrect
## ## Pearson's Chi-squared test ## ## data: tab ## X-squared = 170.46, df = 4, p-value < 2.2e-16
Existe dependência entre as variÔveis binÔrias prioridade e severidade em bugs?
tab <- xtabs(~ prioritario + severo, data=bugs2) chisq.test(tab)
## ## Pearson's Chi-squared test with Yates' continuity correction ## ## data: tab ## X-squared = 401.86, df = 1, p-value < 2.2e-16
https://marcoarmello.wordpress.com/2012/05/17/qualteste/