Centro = read.csv("Centro.csv")
table(Centro$Estado) #Puebla es el 21
##
## 9 13 15 17 21 29
## 431 356 588 410 363 384
Puebla = subset(Centro,Centro$Estado==21) #Elige solo los de Puebla
PueblaUrbano = subset(Puebla, Puebla$localidad == "U")
PueblaRural = subset(Puebla, Puebla$localidad == "R")
table(Puebla$localidad)
##
## R U
## 109 254
# Se realiza con ingresos corrientes y como las muestras son grandes 109 (R) y 254 (U) se utiliza Z por el TLC.
library("BSDA")
## Cargando paquete requerido: lattice
##
## Adjuntando el paquete: 'BSDA'
## The following object is masked from 'package:datasets':
##
## Orange
z.test(PueblaUrbano$ing_cor, sigma.x = sd(PueblaUrbano$ing_cor))
##
## One-sample z-Test
##
## data: PueblaUrbano$ing_cor
## z = 23.639, p-value < 2.2e-16
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
## 47304.03 55857.48
## sample estimates:
## mean of x
## 51580.76
z.test(PueblaRural$ing_cor, sigma.x = sd(PueblaRural$ing_cor))
##
## One-sample z-Test
##
## data: PueblaRural$ing_cor
## z = 12.984, p-value < 2.2e-16
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
## 32703.14 44332.05
## sample estimates:
## mean of x
## 38517.59
IC = tapply(Puebla$ing_cor, list(Puebla$localidad), function(x) z.test(x, sigma.x = sd(x))$conf.int)
IC_df = data.frame(inferior = sapply(IC, function(x) x[1]), superior = sapply(IC, function(x) x[2]), names = c("R", "U"))
# R: rural, U: urbana
options(scipen=999)
plot(NA, xlim = c(0, 100000), ylim=c(1,7), ylab ="Zona", xlab = "Ingreso corriente", main="Ingreso Corriente en Zonas Rurales y Urbanas")
# Línea para zona rural
arrows(IC_df[1, 1], 2, IC_df[1, 2], 2, code = 3, angle = 90, col = "pink", lwd = 2, cex = 0.7)
# Línea para zona urbana
arrows(IC_df[2, 1], 5, IC_df[2, 2], 5, code = 3, angle = 90, col = "cyan", lwd = 2, cex = 0.7)
# Texto para cada línea
text(1, 2, "R", col = "pink", cex = 0.7)
text(1, 5, "U", col = "cyan", cex = 0.7)
### Prueba de Normalidad
shapiro.test(PueblaRural$ing_cor)
##
## Shapiro-Wilk normality test
##
## data: PueblaRural$ing_cor
## W = 0.70878, p-value = 0.0000000000002111
shapiro.test(PueblaUrbano$ing_cor)
##
## Shapiro-Wilk normality test
##
## data: PueblaUrbano$ing_cor
## W = 0.81107, p-value < 0.00000000000000022
MEXICO = read.csv("ENIGH2022_todomexico.csv")
SanPedroCholula = subset(MEXICO, ubica_geo == 21106)
SPC_Urbano = subset(SanPedroCholula, localidad == "U")
SPC_Rural = subset(SanPedroCholula, localidad == "R")
# Prueba de normalidad para zona urbana
shapiro.test(SPC_Urbano$ing_cor)
##
## Shapiro-Wilk normality test
##
## data: SPC_Urbano$ing_cor
## W = 0.95269, p-value = 0.3825
# Prueba de normalidad para zona rural
shapiro.test(SPC_Rural$ing_cor)
##
## Shapiro-Wilk normality test
##
## data: SPC_Rural$ing_cor
## W = 0.88117, p-value = 0.0005662
miu = mean(MEXICO$ing_cor, na.rm = TRUE) # Media nacional de ingreso
sd_urb = sd(SPC_Urbano$ing_cor, na.rm = TRUE)
sd_rur = sd(SPC_Rural$ing_cor, na.rm = TRUE)
library(BSDA)
z.test(SPC_Urbano$ing_cor,mu = miu, alternative = "greater", sigma.x = sd_urb)
##
## One-sample z-Test
##
## data: SPC_Urbano$ing_cor
## z = -10.847, p-value = 1
## alternative hypothesis: true mean is greater than 61489.96
## 95 percent confidence interval:
## 26786.01 NA
## sample estimates:
## mean of x
## 31355.52
z.test(SPC_Rural$ing_cor, mu = miu, alternative = "less", sigma.x = sd_rur)
##
## One-sample z-Test
##
## data: SPC_Rural$ing_cor
## z = -4.1292, p-value = 0.0000182
## alternative hypothesis: true mean is less than 61489.96
## 95 percent confidence interval:
## NA 50986.97
## sample estimates:
## mean of x
## 44033.2