T=read.csv("Centro.csv")
table(T$Estado)
## 
##   9  13  15  17  21  29 
## 431 356 588 410 363 384
tlaxcala=subset(T,T$Estado==29)#Elige solo los de Tlaxcala
tlaxcala_urbano=subset(tlaxcala,tlaxcala$localidad=="U") 
tlaxcala_rural=subset(tlaxcala,tlaxcala$localidad=="R")

Pregunta 1: En Tlaxcala, ¿Se podría inferir que las medias poblacionales de los ingresos corrientes trimestrales por familia en zonas rurales y urbanas son diferentes?

library("BSDA")
## Cargando paquete requerido: lattice
## 
## Adjuntando el paquete: 'BSDA'
## The following object is masked from 'package:datasets':
## 
##     Orange
z.test(tlaxcala_urbano$ing_cor, sigma.x=sd(tlaxcala_urbano$ing_cor))
## 
##  One-sample z-Test
## 
## data:  tlaxcala_urbano$ing_cor
## z = 24.803, p-value < 2.2e-16
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  45018.94 52744.25
## sample estimates:
## mean of x 
##   48881.6
z.test(tlaxcala_rural$ing_cor,sigma.x=sd(tlaxcala_rural$ing_cor))
## 
##  One-sample z-Test
## 
## data:  tlaxcala_rural$ing_cor
## z = 11.509, p-value < 2.2e-16
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  36803.59 51911.86
## sample estimates:
## mean of x 
##  44357.72

Gráfica 1: Para hacer una tabla con los límites del intervalo de confianza de manera más automatizada

T=read.csv("Centro.csv")
tlaxcala=subset(T,T$Estado==29) 
library("BSDA")
IC=tapply(tlaxcala$ing_cor,list(tlaxcala$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")
  ) 
options(scipen=999)
plot(NA, xlim = c(0, 100000), ylim=c(1,7), ylab ="ZONA", xlab = "INGRESO CORRIENTE") 
arrows(IC_df[1,1], 2, IC_df[1,2], 2, code = 3, angle=90, col = "green", lwd = 1, cex=0.9) 
arrows(IC_df[2,1], 5, IC_df[2,2], 5, code = 3, angle=90, col = "red", lwd = 1, cex=0.9)
text(1,2,"R",col="green", cex=0.7)
text(1,5,"U",col="red",cex=0.7) 

## Prueba de normalidad de Shapiro-Wilk

shapiro.test(tlaxcala_rural$ing_cor)
## 
##  Shapiro-Wilk normality test
## 
## data:  tlaxcala_rural$ing_cor
## W = 0.73785, p-value = 0.00000000005115
shapiro.test(tlaxcala_urbano$ing_cor)
## 
##  Shapiro-Wilk normality test
## 
## data:  tlaxcala_urbano$ing_cor
## W = 0.83907, p-value < 0.00000000000000022

Pregunta 2: En Tlaxcala, ¿se puede inferir que la media poblacional del ingreso corriente trimestral por familia en las zonas rural y urbana es mayor al salario mínimo trimestral de $25,092?

T=read.csv("Centro.csv")
tlaxcala=subset(T,T$Estado==29)#Elige solo los de Tlaxcala
tlaxcala_urbano=subset(tlaxcala,tlaxcala$localidad=="U") 
tlaxcala_rural=subset(tlaxcala,tlaxcala$localidad=="R") 

#Salario Mínimo Trimestral de Tlaxcala Calculado 
library(BSDA)
miu = 25092

#Desviación estándar de la muestra 
sTlaxcalaingu=sd(tlaxcala_urbano$ing_cor)
sTlaxcalaingr=sd(tlaxcala_rural$ing_cor)

#Zona Urbana
z.test(tlaxcala_urbano$ing_cor, mu=miu, alternative = "greater", sigma.x=sTlaxcalaingu)
## 
##  One-sample z-Test
## 
## data:  tlaxcala_urbano$ing_cor
## z = 12.071, p-value < 0.00000000000000022
## alternative hypothesis: true mean is greater than 25092
## 95 percent confidence interval:
##  45639.96       NA
## sample estimates:
## mean of x 
##   48881.6
#Zona Rural 
z.test(tlaxcala_rural$ing_cor, mu=miu, alternative = "greater", sigma.x = sTlaxcalaingr)
## 
##  One-sample z-Test
## 
## data:  tlaxcala_rural$ing_cor
## z = 4.9986, p-value = 0.0000002887
## alternative hypothesis: true mean is greater than 25092
## 95 percent confidence interval:
##  38018.09       NA
## sample estimates:
## mean of x 
##  44357.72