antes <- c(5,4,7,3,5,8,5,6)
despues <- c(6,6,7,4,3,9,7,6)
diferencia <- antes - despues
# EDA:
hist(diferencia, col='blue', ylim=c(0,10))

boxplot(diferencia, col='green', horizontal = T)

summary(diferencia)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -2.000 -1.250 -1.000 -0.625 0.000 2.000
x_dif <- mean(diferencia)
sd_dif <- sd(diferencia)
print(sd_dif)
## [1] 1.30247
n <- length(diferencia)
print(n)
## [1] 8
# PRUEBAS DE NORMALIDAD:
shapiro.test(diferencia)
##
## Shapiro-Wilk normality test
##
## data: diferencia
## W = 0.87745, p-value = 0.178
# INTERVALO DE CONFIANZA:
t_critico <- qt(0.975, n-1)
t_observado <- sd_dif/sqrt(n)
err_estandar <- t_critico*t_observado
lim_inf <- x_dif - err_estandar
lim_sup <- x_dif + err_estandar
print(lim_inf)
## [1] -1.713892
print(lim_sup)
## [1] 0.4638923
t.test(diferencia)
##
## One Sample t-test
##
## data: diferencia
## t = -1.3572, df = 7, p-value = 0.2168
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
## -1.7138923 0.4638923
## sample estimates:
## mean of x
## -0.625