El objetivo de este capítulo es evaluar diferencias estadisticas entre grupos cuya distribución no es normal
================================================================================
| Parámetro | Muestra | Población |
|---|---|---|
| Proporción | \(\hat{p}\) | \(p\) |
| Media | \(\bar{x}\) | \(\mu\) |
| Desviación estandar | \(s\) | \(\sigma\) |
| Varianza | \(s^2\) | \(\sigma^2\) |
| \(H_0\) es verdadera | \(H_0\) es falsa | |
|---|---|---|
| Rechaza \(H_0\) | ERROR TIPO I (\(\alpha\)) | Decisión correcta |
| Acepta \(H_0\) | Decisión correcta | ERROR TIPO II (\(\beta\)) |
================================================================================
================================================================================
Las pruebas no paramétricas no necesitan que las poblaciones analizadas tengan una distribución normal.
| APLICACIÓN | PRUEBA PARAMÉTRICA | PRUEBA NO PARAMÉTRICA | CALIFICACIÓN DE EFICIENCIA |
|---|---|---|---|
| Pares relacionados de muestras | prueba t | Prueba del signo o prueba de rangos con signo | 0.63/0.95 |
| Dos muestras independites | prueba t | Prueba de la suma de rangos de Wilcoxon | 0.95 |
| Tres o más muestras independientes | ANOVA | Prueba de Kruskall-Wallis | 0.95 |
| Correlación | Correlación lineal | Prueba de correlación de rangos | 0.91 |
| Aleatoriedad | Sin prueba paramétrica | Prueba de rachas | NA |
Un rango es un número asignado a un elemnto muestral individual con su lugar en la lista ordenada. Un ejemplo
ej <- 1:15
ej.rango <- integer()
for (i in 1:15){
if(ej[i] == 1){
ej.rango[i] <- 1
} else if (ej[i] > 1 & ej[i] < 5){
ej.rango[i] <- 3
} else if (ej[i] >= 5 & ej[i] < 11){
ej.rango[i] <- 8
} else if (ej[i] >= 11 & ej[i] < 16){
ej.rango[i] <- 12
}
}
ej.rango
## [1] 1 3 3 3 8 8 8 8 8 8 12 12 12 12 12
================================================================================
Es una prueba no paramétrica que usa signos positivos y negativos para evaluar diferentes afirmaciones, entre las que se incluyen las siguientes
Son datos de muestras independientes.
\[z=\frac{(x+0.5)-(\frac{n}{2})}{\frac{\sqrt{n}}{2}}\]
# install.packages("BSDA", dependencies = T)
library(BSDA)
## Warning: package 'BSDA' was built under R version 4.0.3
## Loading required package: lattice
##
## Attaching package: 'BSDA'
## The following object is masked from 'package:datasets':
##
## Orange
x <- c(7.8, 6.6, 6.5, 7.4, 7.3, 7., 6.4, 7.1, 6.7, 7.6, 6.8)
SIGN.test(x, md = 6.5)
##
## One-sample Sign-Test
##
## data: x
## s = 9, p-value = 0.02148
## alternative hypothesis: true median is not equal to 6.5
## 95 percent confidence interval:
## 6.571273 7.457455
## sample estimates:
## median of x
## 7
##
## Achieved and Interpolated Confidence Intervals:
##
## Conf.Level L.E.pt U.E.pt
## Lower Achieved CI 0.9346 6.6000 7.4000
## Interpolated CI 0.9500 6.5713 7.4575
## Upper Achieved CI 0.9883 6.5000 7.6000
Usando otro análisis. Primero carguemos unas librerías
library(tidyverse)
## Warning: package 'tidyverse' was built under R version 4.0.3
## -- Attaching packages --------------------------------------- tidyverse 1.3.0 --
## v ggplot2 3.3.2 v purrr 0.3.4
## v tibble 3.0.3 v dplyr 1.0.2
## v tidyr 1.1.2 v stringr 1.4.0
## v readr 1.4.0 v forcats 0.5.0
## Warning: package 'readr' was built under R version 4.0.3
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(rstatix)
##
## Attaching package: 'rstatix'
## The following object is masked from 'package:stats':
##
## filter
library(ggpubr)
Carguemos una base de datos de un paquete
data("mice2", package = "datarium")
head(mice2, 3)
## id before after
## 1 1 187.2 429.5
## 2 2 194.2 404.4
## 3 3 231.7 405.6
Transformación de la tabla a 3 columnas para poder analizarlo posteriormente
data.long <- mice2 %>% gather(key = "group", value = "weight", before, after)
head(data.long)
## id group weight
## 1 1 before 187.2
## 2 2 before 194.2
## 3 3 before 231.7
## 4 4 before 200.5
## 5 5 before 201.7
## 6 6 before 235.0
Resumiendo los datos
data.long %>% group_by(group) %>% get_summary_stats(weight, type = "median_iqr")
## # A tibble: 2 x 5
## group variable n median iqr
## <chr> <chr> <dbl> <dbl> <dbl>
## 1 after weight 10 405 28.3
## 2 before weight 10 197. 19.2
Visualización de los datos
p <- ggpaired(data = data.long, x = "group", y = "weight", order = c("before","after"), ylab = "Weight", xlab = "Groups")
p
La pregunta de investigación sería si hay una diferencia negativa en la ganancia de peso dependiente del tratamiento.
stat.test <- data.long %>%
sign_test(weight ~ group) %>%
add_significance()
stat.test
## # A tibble: 1 x 9
## .y. group1 group2 n1 n2 statistic df p p.signif
## <chr> <chr> <chr> <int> <int> <dbl> <dbl> <dbl> <chr>
## 1 weight after before 10 10 10 10 0.00195 **
================================================================================
Es una prubea no paramétrica para las siguietnes aplicaciones:
library(MASS)
##
## Attaching package: 'MASS'
## The following object is masked from 'package:rstatix':
##
## select
## The following object is masked from 'package:dplyr':
##
## select
head(immer)
## Loc Var Y1 Y2
## 1 UF M 81.0 80.7
## 2 UF S 105.4 82.3
## 3 UF V 119.7 80.4
## 4 UF T 109.7 87.2
## 5 UF P 98.3 84.2
## 6 W M 146.6 100.4
wilcox.test(immer$Y1, immer$Y2, paired = T)
## Warning in wilcox.test.default(immer$Y1, immer$Y2, paired = T): cannot compute
## exact p-value with ties
##
## Wilcoxon signed rank test with continuity correction
##
## data: immer$Y1 and immer$Y2
## V = 368.5, p-value = 0.005318
## alternative hypothesis: true location shift is not equal to 0
Si \(n<30\) se usa la distribución T. Si \(n>30\) se usa la distribución de z.
\[\frac{n(n+1)}{4}\]