library(BSDA)
## Warning: package 'BSDA' was built under R version 4.5.2
## Cargando paquete requerido: lattice
## 
## Adjuntando el paquete: 'BSDA'
## The following object is masked from 'package:datasets':
## 
##     Orange
#DATOS ALEATORIOS
data=c(30,35,36,20,39,39,38,34,30,40,
       25,20,28,29,29,29,28,24,25,26,
       32,36,36,25,20,24,23,23,28,29) # años

# Prueba hipótesis de dobla cola
# HO: mu == 30
# Ha: mu != 30

#Valor crítico
Alpha=0.05
Zc=abs(qnorm(Alpha/2))
Zc
## [1] 1.959964
z.test(
  x=data,
  alternative = "two.sided",
  mu = 30,
  sigma.x = sd(data),
  conf.level = 0.95 # nivel de significancia: alpha
)
## 
##  One-sample z-Test
## 
## data:  data
## z = -0.60897, p-value = 0.5425
## alternative hypothesis: true mean is not equal to 30
## 95 percent confidence interval:
##  27.18767 31.47899
## sample estimates:
## mean of x 
##  29.33333
# Prueba hipótesis de cola izquierda
# HO: mu >= 50
# Ha: mu < 50

#Valor crítico
Alpha=0.05
Zc=qnorm(Alpha)
Zc
## [1] -1.644854
z.test(
  x=data,
  alternative = "less",
  mu =50,
  sigma.x = sd(data),
  conf.level = 0.95 # nivel de significancia: alpha
)
## 
##  One-sample z-Test
## 
## data:  data
## z = -18.878, p-value < 2.2e-16
## alternative hypothesis: true mean is less than 50
## 95 percent confidence interval:
##        NA 31.13403
## sample estimates:
## mean of x 
##  29.33333
# Prueba hipótesis de cola derecha
# HO: mu <= 30
# Ha: mu > 30

#Valor crítico
Alpha=0.05
Zc=abs(qnorm(Alpha))
Zc
## [1] 1.644854
z.test(
  x=data,
  alternative = "greater",
  mu =25,
  sigma.x = sd(data),
  conf.level = 0.95 # nivel de significancia: alpha
)
## 
##  One-sample z-Test
## 
## data:  data
## z = 3.9583, p-value = 3.774e-05
## alternative hypothesis: true mean is greater than 25
## 95 percent confidence interval:
##  27.53264       NA
## sample estimates:
## mean of x 
##  29.33333