n = 40
x = 3
p = x/n
alpha = 0.05
prop.test(x, n, p = 0.05, alternative = "greater")
## Warning in prop.test(x, n, p = 0.05, alternative = "greater"): Chi-squared
## approximation may be incorrect
##
## 1-sample proportions test with continuity correction
##
## data: x out of n, null probability 0.05
## X-squared = 0.13158, df = 1, p-value = 0.3584
## alternative hypothesis: true p is greater than 0.05
## 95 percent confidence interval:
## 0.02328168 1.00000000
## sample estimates:
## p
## 0.075
c2="#6666FF" # AZUL
c3="#4CBFBA" # VERDE CLARO
g1 = c(6.2, 5.0, 6.9, 7.5, 8.6, 9.0, 7.0, 6.3, 9.9, 7.2, 8.1, 6.3, 5.2, 7.7, 5.7, 7.1, 6.4, 7.1, 8.3, 8.2, 6.4, 7.0, 7.8, 6.9, 8.5, 7.7, 8.2, 5.9, 9.8, 5.9, 6.7, 6.3, 6.7, 5.4, 7.2, 6.4)
g2 = c(8.2, 6.7, 7.6, 8.3, 9.4, 7.3, 6.7, 7.2, 9.8, 9.6, 8.9, 7.3, 9.7, 7.9, 9.1, 9.0, 9.2, 7.4, 8.3, 8.6, 8.5, 9.2, 7.0, 6.6, 8.4, 8.3, 7.5, 6.8, 7.0, 7.3, 8.9, 6.2, 7.1, 8.5, 9.1, 7.9, 8.1, 8.6, 6.8, 9.0)
par(mfrow = c(1, 2))
boxplot(g1, las=1, col = c2, ylim=c(0,10))
boxplot(g2, las=1, col = c3, ylim=c(0,10))
shapiro.test(g1)
##
## Shapiro-Wilk normality test
##
## data: g1
## W = 0.9728, p-value = 0.5069
shapiro.test(g2)
##
## Shapiro-Wilk normality test
##
## data: g2
## W = 0.95887, p-value = 0.1533
var.test(g1,g2)
##
## F test to compare two variances
##
## data: g1 and g2
## F = 1.4447, num df = 35, denom df = 39, p-value = 0.2643
## alternative hypothesis: true ratio of variances is not equal to 1
## 95 percent confidence interval:
## 0.7545004 2.7989666
## sample estimates:
## ratio of variances
## 1.444723
c2="#6666FF" # AZUL
c3="#4CBFBA" # VERDE CLARO
FB=c(41.8, 41.6, 31.5, 48.7, 40.8, 31.2, 36.5, 36.2, 32.8, 36.3, 38.6, 30.5)
KT=c(40.5, 38.4, 44.0, 34.9, 44.0, 44.7, 44.0, 47.1, 39.8, 43.9, 38.5, 40.2)
par(mfrow = c(1, 2))
boxplot(FB, las=1, col = c2, ylim=c(0,50))
boxplot(KT, las=1, col = c3, ylim=c(0,50))
var.test(FB,KT)
##
## F test to compare two variances
##
## data: FB and KT
## F = 2.417, num df = 11, denom df = 11, p-value = 0.1589
## alternative hypothesis: true ratio of variances is not equal to 1
## 95 percent confidence interval:
## 0.6957897 8.3958061
## sample estimates:
## ratio of variances
## 2.416964
t.test(FB,KT, # variables
paired=FALSE, # grupos independientes
var.equal=TRUE, # varianzas iguales
conf.level=0.95) # alpha = 0.05
##
## Two Sample t-test
##
## data: FB and KT
## t = -2.398, df = 22, p-value = 0.0254
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -8.3139995 -0.6026672
## sample estimates:
## mean of x mean of y
## 37.20833 41.66667
t.test(FB,KT, # variables
paired=FALSE, # grupos independientes
var.equal=TRUE, # varianzas iguales
conf.level=0.95, # alpha = 0.05
alternative = "less" )
##
## Two Sample t-test
##
## data: FB and KT
## t = -2.398, df = 22, p-value = 0.0127
## alternative hypothesis: true difference in means is less than 0
## 95 percent confidence interval:
## -Inf -1.265884
## sample estimates:
## mean of x mean of y
## 37.20833 41.66667
estandar = c(32, 37, 35, 28, 41, 44, 35, 31, 34)
nuevo = c(35, 31, 29, 25, 34, 40, 27, 32, 31)
t.test(estandar, nuevo, alternative = "less")
##
## Welch Two Sample t-test
##
## data: estandar and nuevo
## t = 1.6495, df = 15.844, p-value = 0.9406
## alternative hypothesis: true difference in means is less than 0
## 95 percent confidence interval:
## -Inf 7.549969
## sample estimates:
## mean of x mean of y
## 35.22222 31.55556
Emplee y realice las pruebas de hipótesis a un nivel de significancia del 0.01 para determinar si el programa que ofrece el nuevo instructor es eficaz. Suponga que la variable peso se distribuye aproximadamente normal.
x1 = c(104, 89, 84, 106, 90, 96, 79, 90, 85, 76, 91, 82, 100, 89, 121, 72)
x2 = c(98, 85, 85, 103, 88, 95, 79, 90, 82, 76, 89, 81, 99, 86, 111, 70)
t.test(x1, x2, paired = TRUE, alternative = "less", mu = 0, conf.level = 0.99)
##
## Paired t-test
##
## data: x1 and x2
## t = 3.4246, df = 15, p-value = 0.9981
## alternative hypothesis: true mean difference is less than 0
## 99 percent confidence interval:
## -Inf 4.069877
## sample estimates:
## mean difference
## 2.3125
c2="#6666FF"
c3="#4CBFBA"
lec.nue=c(35, 40, 36, 42, 41, 52, 36, 41, 49, 41, 45, 38, 31, 54, 37, 47, 38, 34, 46, 39, 45, 44, 41, 42, 36, 43, 35, 31, 38, 38, 41, 41, 44, 44, 35, 44, 38, 33, 38, 49, 45, 45, 38, 46, 28, 40, 41, 47, 43, 50, 39, 36, 39, 38, 37, 37, 47, 37, 41, 40, 35)
lec.act=c(41, 33, 22, 27, 31, 25, 28, 36, 29, 32, 25, 31, 31, 30, 31, 36, 26, 29, 29, 26, 27, 27, 30, 34, 26, 30, 23, 22, 29, 31, 37, 32, 34, 25, 25, 36, 32, 30, 23, 31, 33, 27, 27, 29, 35, 36, 27, 29, 25, 34, 27, 25, 32, 37, 31, 33, 27, 31, 26, 25, 24)
par(mfrow = c(1, 2))
boxplot(lec.nue, las=1, col = c2, ylim=c(0,60))
boxplot(lec.act, las=1, col = c3, ylim=c(0,60))
shapiro.test(lec.nue)
##
## Shapiro-Wilk normality test
##
## data: lec.nue
## W = 0.98691, p-value = 0.76
shapiro.test(lec.act)
##
## Shapiro-Wilk normality test
##
## data: lec.act
## W = 0.97442, p-value = 0.2296
var.test(lec.nue, lec.act)
##
## F test to compare two variances
##
## data: lec.nue and lec.act
## F = 1.5412, num df = 60, denom df = 60, p-value = 0.09654
## alternative hypothesis: true ratio of variances is not equal to 1
## 95 percent confidence interval:
## 0.9246342 2.5688108
## sample estimates:
## ratio of variances
## 1.541172
t.test(lec.nue,lec.act, paired=FALSE, var.equal=TRUE, conf.level=0.95, alternative = "greater")
##
## Two Sample t-test
##
## data: lec.nue and lec.act
## t = 12.801, df = 120, p-value < 2.2e-16
## alternative hypothesis: true difference in means is greater than 0
## 95 percent confidence interval:
## 9.547053 Inf
## sample estimates:
## mean of x mean of y
## 40.50820 29.54098
g1 <- c(75, 76, 74, 80, 72, 78, 76, 73, 72, 75)
g2 <- c(86, 78, 86, 84, 81, 79, 78, 84, 88, 80)
t.test(g1, g2, alternative = "less", var.equal = FALSE, conf.level = 0.95)
##
## Welch Two Sample t-test
##
## data: g1 and g2
## t = -5.1719, df = 16.105, p-value = 4.539e-05
## alternative hypothesis: true difference in means is less than 0
## 95 percent confidence interval:
## -Inf -4.83674
## sample estimates:
## mean of x mean of y
## 75.1 82.4
n = 200
p1 = 0.20
p2 = 0.22
prop.test(c(n * p1, n * p2), c(n, n), alternative = "two.sided", conf.level = 0.95)
##
## 2-sample test for equality of proportions with continuity correction
##
## data: c(n * p1, n * p2) out of c(n, n)
## X-squared = 0.13562, df = 1, p-value = 0.7127
## alternative hypothesis: two.sided
## 95 percent confidence interval:
## -0.10480688 0.06480688
## sample estimates:
## prop 1 prop 2
## 0.20 0.22
A = c(45, 73, 46, 124, 30, 57, 83, 34, 26, 17)
D = c(36, 60, 44, 119, 35, 51, 77, 29, 24, 11)
t.test(D, A, paired = TRUE, alternative = "less", conf.level = 0.95)
##
## Paired t-test
##
## data: D and A
## t = -3.2796, df = 9, p-value = 0.004767
## alternative hypothesis: true mean difference is less than 0
## 95 percent confidence interval:
## -Inf -2.161215
## sample estimates:
## mean difference
## -4.9
colores_web = c("café", "amarillo", "rojo", "azul", "naranja", "verde")
porcentajes_web = c(13, 14, 13, 24, 20, 16)
colores_bolsa = c("café", "amarillo", "rojo", "azul", "naranja", "verde")
cantidad_bolsa = c(70, 72, 61, 118, 108, 85)
porcentajes_obs = cantidad_bolsa / sum(cantidad_bolsa) * 100
diff_porcentajes = abs(porcentajes_web - porcentajes_obs)
tolerancia = 5
diferencias_aceptables = diff_porcentajes = tolerancia
print(data.frame(Colores = colores_web, Esperados = porcentajes_web, Observados = porcentajes_obs, Diferencia = diff_porcentajes, Aceptable = diferencias_aceptables))
## Colores Esperados Observados Diferencia Aceptable
## 1 café 13 13.61868 5 5
## 2 amarillo 14 14.00778 5 5
## 3 rojo 13 11.86770 5 5
## 4 azul 24 22.95720 5 5
## 5 naranja 20 21.01167 5 5
## 6 verde 16 16.53696 5 5
secuencia = c("D", "D", "N", "N", "N", "N", "D", "N", "N", "D", "D", "N", "N", "N", "N", "N",
"D", "D", "D", "D", "N", "N", "D", "N", "N", "N", "D", "N", "D", "N", "N", "N", "N", "N", "D",
"N", "N", "N", "D", "D", "N", "N", "N", "N", "D", "D", "D", "D", "D", "D", "D", "D", "N", "N",
"N", "N", "N", "D", "N", "D", "N", "N", "N", "N", "D", "D", "D", "D", "D", "N", "D", "D", "N",
"N", "N", "N", "N", "N", "D", "D", "D", "D", "D", "D", "D", "D", "D", "N", "N", "N", "N", "N",
"D", "D", "D", "D", "D", "N", "N", "N", "N", "N", "D", "D", "N")
tabla_contingencia = table(secuencia)
resultado = chisq.test(tabla_contingencia)
estadistico_prueba = resultado$statistic
valor_p = resultado$p.value
alpha = 0.05
if (valor_p < alpha) {
conclusion <- "Se rechaza la hipótesis nula. Los datos no presentan un patrón aleatorio."} else {conclusion <- "No se rechaza la hipótesis nula. Los datos presentan un patrón aleatorio y la generación de artículos defectuosos se debe al azar."}
print(resultado)
##
## Chi-squared test for given probabilities
##
## data: tabla_contingencia
## X-squared = 0.77143, df = 1, p-value = 0.3798
cat("\n")
cat("Conclusión:", conclusion)
## Conclusión: No se rechaza la hipótesis nula. Los datos presentan un patrón aleatorio y la generación de artículos defectuosos se debe al azar.
matriz = matrix(c(470, 191, 42, 445, 171, 28, 257, 129, 17), nrow = 3, byrow = TRUE)
rownames(matriz) = c("Alta", "Moderada", "Baja")
colnames(matriz) = c("Dia", "Tarde", "Noche")
resultado = chisq.test(matriz)
estadistico_prueba = resultado$statistic
valor_p = resultado$p.value
alpha = 0.05
if (valor_p < alpha) {
conclusion = "Se rechaza la hipótesis nula. Existe una relación significativa entre la calidad de las soldaduras y los turnos."} else {conclusion <- "No se rechaza la hipótesis nula. No se encontró evidencia suficiente para concluir que la calidad de las soldaduras varía con los turnos."}
print(resultado)
##
## Pearson's Chi-squared test
##
## data: matriz
## X-squared = 6.4001, df = 4, p-value = 0.1712
cat("\n")
cat("Conclusión:", conclusion)
## Conclusión: No se rechaza la hipótesis nula. No se encontró evidencia suficiente para concluir que la calidad de las soldaduras varía con los turnos.
# Datos
notas = c(3.4, 2.8, 4.2, 2.1, 2.8, 2.4, 3.5, 4.2, 3.1, 4.1, 2.4, 3.4, 4.1, 4.0, 2.4, 4.1, 3.4, 4.4, 3.8, 3.7, 2.2, 3.6, 2.3, 3.7, 2.8, 4.1, 2.3, 4.6, 4.6, 5.2, 2.4, 2.4, 2.7, 3.8, 4.6, 4.4, 4.2, 4.4, 2.4, 3.3, 3.8, 2.9, 3.1, 2.7, 3.6, 3.8, 4.4, 3.9, 2.8, 3.7)
resultado_normalidad = shapiro.test(notas)
estadistico_prueba = resultado_normalidad$statistic
valor_p = resultado_normalidad$p.value
alpha = 0.05
if (valor_p < alpha) {conclusion_normalidad = "Se rechaza la hipótesis nula. Los datos no proceden de una distribución normal."} else {conclusion_normalidad = "No se rechaza la hipótesis nula. Los datos proceden de una distribución normal."}
media_hipotesis = 3.3
resultado_hipotesis = t.test(notas, alternative = "greater", mu = media_hipotesis)
estadistico_prueba_hipotesis = resultado_hipotesis$statistic
valor_p_hipotesis = resultado_hipotesis$p.value
if (valor_p_hipotesis < alpha) {conclusion_hipotesis <- "Se rechaza la hipótesis nula. Hay evidencia para concluir que la media de la nota es mayor a 3.3."} else {conclusion_hipotesis = "No se rechaza la hipótesis nula. No hay suficiente evidencia para concluir que la media de la nota es mayor a 3.3."}
print(resultado_normalidad)
##
## Shapiro-Wilk normality test
##
## data: notas
## W = 0.95071, p-value = 0.03649
cat("\n")
cat("Conclusión sobre normalidad:", conclusion_normalidad)
## Conclusión sobre normalidad: Se rechaza la hipótesis nula. Los datos no proceden de una distribución normal.
cat("\n\n")
print(resultado_hipotesis)
##
## One Sample t-test
##
## data: notas
## t = 1.416, df = 49, p-value = 0.08155
## alternative hypothesis: true mean is greater than 3.3
## 95 percent confidence interval:
## 3.270562 Inf
## sample estimates:
## mean of x
## 3.46
cat("\n")
cat("Conclusión sobre hipótesis:", conclusion_hipotesis)
## Conclusión sobre hipótesis: No se rechaza la hipótesis nula. No hay suficiente evidencia para concluir que la media de la nota es mayor a 3.3.