19.2 Contrastes

19.2.1 Una muestra

Obtenemos un intervalo de confianza de satisfac

t.test(hatco$satisfac)  # with(hatco, t.test(satisfac))
## 
##  One Sample t-test
## 
## data:  hatco$satisfac
## t = 55.301, df = 98, p-value < 2.2e-16
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  4.603406 4.946089
## sample estimates:
## mean of x 
##  4.774747

Contrastamos si es razonable suponer que la media es 5

t.test(hatco$satisfac, mu=5)
## 
##  One Sample t-test
## 
## data:  hatco$satisfac
## t = -2.6089, df = 98, p-value = 0.01051
## alternative hypothesis: true mean is not equal to 5
## 95 percent confidence interval:
##  4.603406 4.946089
## sample estimates:
## mean of x 
##  4.774747

Utilizando una confianza del 99%

t.test(hatco$satisfac, mu=5, conf.level=0.99)
## 
##  One Sample t-test
## 
## data:  hatco$satisfac
## t = -2.6089, df = 98, p-value = 0.01051
## alternative hypothesis: true mean is not equal to 5
## 99 percent confidence interval:
##  4.547935 5.001560
## sample estimates:
## mean of x 
##  4.774747

Veamos si podemos afirmar que la media es menor que 5

t.test(hatco$satisfac, mu=5, alternative = 'less')
## 
##  One Sample t-test
## 
## data:  hatco$satisfac
## t = -2.6089, df = 98, p-value = 0.005253
## alternative hypothesis: true mean is less than 5
## 95 percent confidence interval:
##      -Inf 4.918122
## sample estimates:
## mean of x 
##  4.774747

¿Y mayor que 4.65?

t.test(hatco$satisfac, mu=4.65, alternative = 'greater')
## 
##  One Sample t-test
## 
## data:  hatco$satisfac
## t = 1.4448, df = 98, p-value = 0.07585
## alternative hypothesis: true mean is greater than 4.65
## 95 percent confidence interval:
##  4.631373      Inf
## sample estimates:
## mean of x 
##  4.774747

El test de los rangos con signo de Wilcoxon es un contraste no paramétrico (exige que la distribución sea simétrica) que se puede utilizar como alternativa al contraste t de Student

with(hatco, wilcox.test(satisfac, mu=5))
## 
##  Wilcoxon signed rank test with continuity correction
## 
## data:  satisfac
## V = 1574, p-value = 0.01303
## alternative hypothesis: true location is not equal to 5

19.2.2 Dos muestras

Disponemos de dos muestras independientes, el porcentaje de compra en las empresas con nivel de satisfacción bajo y alto, y asumimos que las varianzas son iguales

t.test(fidelida ~ nsatisfa, data = hatco, var.equal=TRUE)
## 
##  Two Sample t-test
## 
## data:  fidelida by nsatisfa
## t = -6.5833, df = 97, p-value = 2.363e-09
## alternative hypothesis: true difference in means between group bajo and group alto is not equal to 0
## 95 percent confidence interval:
##  -12.915013  -6.931653
## sample estimates:
## mean in group bajo mean in group alto 
##           41.72778           51.65111

Si no se asume igualdad de varianzas, se calcula la variante Welch del test t

t.test(fidelida ~ nsatisfa, data = hatco)
## 
##  Welch Two Sample t-test
## 
## data:  fidelida by nsatisfa
## t = -6.6901, df = 96.995, p-value = 1.437e-09
## alternative hypothesis: true difference in means between group bajo and group alto is not equal to 0
## 95 percent confidence interval:
##  -12.86727  -6.97940
## sample estimates:
## mean in group bajo mean in group alto 
##           41.72778           51.65111

Comparemos visualmente las varianzas

boxplot(fidelida ~ nsatisfa, data = hatco)

La comparación de las varianzas puede hacerse con el test F

var.test(fidelida ~ nsatisfa, data = hatco)
## 
##  F test to compare two variances
## 
## data:  fidelida by nsatisfa
## F = 1.4248, num df = 53, denom df = 44, p-value = 0.2292
## alternative hypothesis: true ratio of variances is not equal to 1
## 95 percent confidence interval:
##  0.797925 2.505462
## sample estimates:
## ratio of variances 
##           1.424804

Una alternativa no paramétrica

bartlett.test(fidelida ~ nsatisfa, data = hatco)
## 
##  Bartlett test of homogeneity of variances
## 
## data:  fidelida by nsatisfa
## Bartlett's K-squared = 1.4675, df = 1, p-value = 0.2257

También puede utilizarse el test de Wilcoxon como alternativa al test t

wilcox.test(fidelida ~ nsatisfa, data = hatco)
## 
##  Wilcoxon rank sum test with continuity correction
## 
## data:  fidelida by nsatisfa
## W = 430.5, p-value = 3.504e-08
## alternative hypothesis: true location shift is not equal to 0

Si disponemos de datos apareados, por ejemplo nivel de precios e imagen de fuerza de ventas

with(hatco, t.test(precio, imgfvent, paired = TRUE))
## 
##  Paired t-test
## 
## data:  precio and imgfvent
## t = -2.2347, df = 98, p-value = 0.02771
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.55114759 -0.03269079
## sample estimates:
## mean of the differences 
##              -0.2919192

Y la correspondiente alternativa no paramétrica

with(hatco, wilcox.test(precio, imgfvent, paired = TRUE))
## 
##  Wilcoxon signed rank test with continuity correction
## 
## data:  precio and imgfvent
## V = 1789.5, p-value = 0.02431
## alternative hypothesis: true location shift is not equal to 0