El archivo de este link tiene diversas variables.
Lo han contratado para una investigación. La institucion que lo ha contratado supone que:
No olvide controlar sus modelos inferenciales multivariados.
ANTES LEAMOS LA DATA
link="https://docs.google.com/spreadsheets/d/e/2PACX-1vQqvZB7R0-kwCSmaGIT6ETjJbjbJY-iJ75rUx2SQGktaL8xnwQe6CyAUUvaXl7b-A/pub?gid=492868216&single=true&output=csv"
newDATA=read.csv(link, stringsAsFactors = F)
Usando la data, responda:
newDATA$difvotos=newDATA$PPK-newDATA$FP
head(aggregate(difvotos ~ prov, data = newDATA, sum),20)
## prov difvotos
## 1 ABANCAY 137
## 2 ACOBAMBA 577
## 3 ACOMAYO 4646
## 4 AIJA -397
## 5 ALTO AMAZONAS 13871
## 6 AMBO -2903
## 7 ANDAHUAYLAS -513
## 8 ANGARAES 2866
## 9 ANTA 9633
## 10 ANTABAMBA 135
## 11 ANTONIO RAYMONDI 1681
## 12 AREQUIPA 274149
## 13 ASCOPE -18314
## 14 ASUNCION 330
## 15 ATALAYA -7635
## 16 AYABACA 1627
## 17 AYMARAES -1337
## 18 AZANGARO 29420
## 19 BAGUA 2064
## 20 BARRANCA -20134
Entonces, si pido un summary y veo negativos, sabre que no ganó en todas las provincias:
dataProv=aggregate(difvotos ~ prov, data = newDATA, sum)
summary(dataProv$difvotos)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -79776.0 -6174.5 -364.0 309.7 3609.5 274149.0
Aquí se en cuales:
dataProv[dataProv$difvotos>0,'prov']
## [1] "ABANCAY" "ACOBAMBA"
## [3] "ACOMAYO" "ALTO AMAZONAS"
## [5] "ANGARAES" "ANTA"
## [7] "ANTABAMBA" "ANTONIO RAYMONDI"
## [9] "AREQUIPA" "ASUNCION"
## [11] "AYABACA" "AZANGARO"
## [13] "BAGUA" "CALCA"
## [15] "CALLAO" "CAMANA"
## [17] "CANAS" "CANCHIS"
## [19] "CANDARAVE" "CANGALLO"
## [21] "CARABAYA" "CARLOS FERMIN FITZCARRALD"
## [23] "CASTILLA" "CAYLLOMA"
## [25] "CELENDIN" "CHACHAPOYAS"
## [27] "CHINCHA" "CHINCHEROS"
## [29] "CHOTA" "CHUCUITO"
## [31] "CHUMBIVILCAS" "CHUPACA"
## [33] "CONDESUYOS" "CONDORCANQUI"
## [35] "COTABAMBAS" "CUSCO"
## [37] "CUTERVO" "DANIEL A. CARRION"
## [39] "DATEM DEL MARANON" "DOS DE MAYO"
## [41] "EL COLLAO" "ESPINAR"
## [43] "GENERAL SANCHEZ CERRO" "GRAU"
## [45] "HUACAYBAMBA" "HUALGAYOC"
## [47] "HUAMALIES" "HUAMANGA"
## [49] "HUANCA SANCOS" "HUANCANE"
## [51] "HUANCAVELICA" "HUANCAYO"
## [53] "HUARAZ" "HUARI"
## [55] "ILO" "ISLAY"
## [57] "JAEN" "JORGE BASADRE"
## [59] "JUNIN" "LA UNION"
## [61] "LAMPA" "LAURICOCHA"
## [63] "LIMA" "MARANON"
## [65] "MARISCAL LUZURIAGA" "MARISCAL NIETO"
## [67] "MAYNAS" "MELGAR"
## [69] "MOHO" "PALLASCA"
## [71] "PARURO" "PASCO"
## [73] "PAUCARTAMBO" "POMABAMBA"
## [75] "PUNO" "QUISPICANCHI"
## [77] "RECUAY" "RODRIGUEZ DE MENDOZA"
## [79] "SAN IGNACIO" "SAN MARTIN"
## [81] "SAN PABLO" "SAN ROMAN"
## [83] "SANTA" "SIHUAS"
## [85] "TACNA" "TALARA"
## [87] "TARATA" "TAYACAJA"
## [89] "URUBAMBA" "VICTOR FAJARDO"
## [91] "YAROWILCA" "YAULI"
## [93] "YUNGUYO"
Aqui se cuantas:
length(dataProv[dataProv$difvotos>=0,'prov'])
## [1] 93
dataDepa=aggregate(difvotos ~ depa, data = newDATA, sum)
summary(dataDepa$difvotos)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -217134 -27094 -6609 2415 23266 294889
cuantos ganó?
length(dataDepa[dataDepa$difvotos>0,"depa"])
## [1] 12
shapiro.test(newDATA$difvotos)
##
## Shapiro-Wilk normality test
##
## data: newDATA$difvotos
## W = 0.46253, p-value < 2.2e-16
De ahí que voy por Spearman:
cor.test(newDATA$difvotos,newDATA$percapitaf, method = "spearman")
## Warning in cor.test.default(newDATA$difvotos, newDATA$percapitaf, method =
## "spearman"): Cannot compute exact p-value with ties
##
## Spearman's rank correlation rho
##
## data: newDATA$difvotos and newDATA$percapitaf
## S = 1112796710, p-value = 0.0004149
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
## rho
## -0.08235373
Graficamente:
library(ggpubr)
## Loading required package: ggplot2
## Loading required package: magrittr
preg2=ggscatter(data=newDATA,
x = "difvotos", y = "percapitaf",
cor.coef = TRUE,
cor.method = "spearman")
preg2
Para las siguientes preguntas, hacemos una regresión…
todasLasHipoyControl=lm(difvotos~accesoedu+esperanza+percapitaf+pobla, data=newDATA)
summary(todasLasHipoyControl)
##
## Call:
## lm(formula = difvotos ~ accesoedu + esperanza + percapitaf +
## pobla, data = newDATA)
##
## Residuals:
## Min 1Q Median 3Q Max
## -36426 -1276 75 1143 74927
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 3.553e+03 1.739e+03 2.044 0.04111 *
## accesoedu 2.640e+02 9.807e+01 2.692 0.00716 **
## esperanza -9.462e+01 2.413e+01 -3.921 9.13e-05 ***
## percapitaf 5.003e+00 7.962e-01 6.283 4.13e-10 ***
## pobla -2.494e-02 2.596e-03 -9.607 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 5182 on 1829 degrees of freedom
## Multiple R-squared: 0.09786, Adjusted R-squared: 0.09589
## F-statistic: 49.6 on 4 and 1829 DF, p-value: < 2.2e-16
H1:PPK tuvo más apoyo que FP mientras mejor acceso a la educación.
H2:PPK tuvo más apoyo que FP mientras mayor era a la esperanza de vida.
H3:PPK tuvo menos apoyo que FP mientras mayores ingresos.
Columna donde 1 es gana y 0 es no gana:
newDATA$ganaPPK=as.numeric(newDATA$difvotos>0)
Calculo el promedio por grupo:
aggregate(percapitaf~ganaPPK, data = newDATA, mean)
## ganaPPK percapitaf
## 1 0 386.2901
## 2 1 399.6531
El promedio parece mayor, pero veamos errores:
library(ggpubr)
ggerrorplot(data=newDATA, x = "ganaPPK",
y = "percapitaf",
desc_stat = "mean_ci"
)
Como los errores se intersectan, hago prueba de contrastes:
shapiro.test(newDATA$percapitaf)
##
## Shapiro-Wilk normality test
##
## data: newDATA$percapitaf
## W = 0.85858, p-value < 2.2e-16
kruskal.test(percapitaf~ganaPPK,data=newDATA)
##
## Kruskal-Wallis rank sum test
##
## data: percapitaf by ganaPPK
## Kruskal-Wallis chi-squared = 4.7159, df = 1, p-value = 0.02989
Con ese p-valor (0.02989) debo rechazar que las medias sean iguales. Eso contradice el gráfico anterior. Veamos el boxplot:
ggplot(data=newDATA, aes(x=as.factor(ganaPPK), y=percapitaf)) + geom_boxplot(notch = T)
La presencia de atipicos confunde a la U de Mann Whitney, de hecho la mediana de Keiko es mas alta. En conclusión, por ambos gráficos podemos decir que la diferencia de promedios no es significativa.