rm(list = ls())
library(rio)
## Warning: package 'rio' was built under R version 4.3.3
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.2     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.0
## ✔ ggplot2   3.4.3     ✔ tibble    3.2.1
## ✔ lubridate 1.9.2     ✔ tidyr     1.3.0
## ✔ purrr     1.0.2     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
setwd("C:/Users/moren/OneDrive/2024-2/ESTADÍSTICA 2/PCS")
data=import("dataPeru.xlsx")
str(data)
## 'data.frame':    25 obs. of  8 variables:
##  $ DEPARTAMENTO       : chr  "AMAZONAS" "ÁNCASH" "APURÍMAC" "AREQUIPA" ...
##  $ UBIGEO             : chr  "010000" "020000" "030000" "040000" ...
##  $ buenEstado         : num  18.6 13.9 8.7 27.4 17 18 33.8 11.9 10.1 15.6 ...
##  $ contribuyentesSunat: num  75035 302906 103981 585628 151191 ...
##  $ peaOcupada         : num  130019 387976 140341 645001 235857 ...
##  $ pobUrbana          : num  205976 806065 243354 1383694 444473 ...
##  $ PobRural           : num  211389 333050 180905 76739 206467 ...
##  $ pobTotal           : num  417365 1139115 424259 1460433 650940 ...

HIPÓTESIS: El buen estado de los locales escolares depende del porcentaje de la poblacion que contribuye a la SUNAT; y del porcentaje de la PEA que está laborando; se llega a comprobar que (con una significancia del 0.05):

Varible dependiente: Buen Estado Variables independientes: Sunat y PEA

summary(data$buenEstado)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    7.70   13.90   17.30   18.61   21.80   40.50
library(DescTools)

allStats=c(summary(data$buenEstado),
  sd=sd(data$buenEstado),
  skew=Skew(data$buenEstado),
  kurt=Kurt(data$buenEstado),
  cv=CoefVar(data$buenEstado))
allStats
##       Min.    1st Qu.     Median       Mean    3rd Qu.       Max.         sd 
##  7.7000000 13.9000000 17.3000000 18.6120000 21.8000000 40.5000000  8.2596065 
##       skew       kurt         cv 
##  0.9008641  0.2026850  0.4437786

GRAFICAMOS:

library(ggplot2)

base=ggplot(data=data,
            aes(x=buenEstado))
histogram= base + geom_histogram(aes(y = after_stat(density)),
                 colour = 1, fill = "white",bins=10) +  
    stat_function(fun = dnorm,
                  args = list(mean = allStats['Mean'],
                              sd = allStats['sd']),col='red')
    
histogram

base=ggplot(data=data,
            aes(y=buenEstado))
boxplot=base + geom_boxplot()

boxplot

Análisis con la PEA:

str(data)
## 'data.frame':    25 obs. of  8 variables:
##  $ DEPARTAMENTO       : chr  "AMAZONAS" "ÁNCASH" "APURÍMAC" "AREQUIPA" ...
##  $ UBIGEO             : chr  "010000" "020000" "030000" "040000" ...
##  $ buenEstado         : num  18.6 13.9 8.7 27.4 17 18 33.8 11.9 10.1 15.6 ...
##  $ contribuyentesSunat: num  75035 302906 103981 585628 151191 ...
##  $ peaOcupada         : num  130019 387976 140341 645001 235857 ...
##  $ pobUrbana          : num  205976 806065 243354 1383694 444473 ...
##  $ PobRural           : num  211389 333050 180905 76739 206467 ...
##  $ pobTotal           : num  417365 1139115 424259 1460433 650940 ...
summary(data$peaOcupada)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   64206  140341  321613  492229  461312 4536507
library(ggrepel)
base=ggplot(data=data, aes(x=peaOcupada, y=buenEstado))
scatter = base + geom_point()
scatterText = scatter + geom_text_repel(aes(label=DEPARTAMENTO),size=2)
scatterText

Indices de correlación:

f1=formula(~peaOcupada + buenEstado)
pearsonf1=cor.test(f1, data=data)[c('estimate', 'p.value')]
pearsonf1
## $estimate
##       cor 
## 0.3567442 
## 
## $p.value
## [1] 0.08002776
spearmanf1=cor.test(f1,data=data,method='spearman',exact=F)[c('estimate','p.value')]
spearmanf1
## $estimate
##       rho 
## 0.2785151 
## 
## $p.value
## [1] 0.1776146

REGRESIÓN LINEAL:

modelo1=lm(buenEstado~peaOcupada+contribuyentesSunat, data=data)
summary(modelo1)
## 
## Call:
## lm(formula = buenEstado ~ peaOcupada + contribuyentesSunat, data = data)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -10.589  -3.966  -1.347   1.907  21.518 
## 
## Coefficients:
##                       Estimate Std. Error t value Pr(>|t|)    
## (Intercept)          1.865e+01  2.694e+00   6.922 5.98e-07 ***
## peaOcupada          -1.596e-05  2.241e-05  -0.712    0.484    
## contribuyentesSunat  1.786e-05  2.060e-05   0.867    0.395    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 7.925 on 22 degrees of freedom
## Multiple R-squared:  0.1561, Adjusted R-squared:  0.07939 
## F-statistic: 2.035 on 2 and 22 DF,  p-value: 0.1546
modelo2=formula(buenEstado~peaOcupada + contribuyentesSunat)
regre2=lm(modelo2,data = data)
summary(regre2)
## 
## Call:
## lm(formula = modelo2, data = data)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -10.589  -3.966  -1.347   1.907  21.518 
## 
## Coefficients:
##                       Estimate Std. Error t value Pr(>|t|)    
## (Intercept)          1.865e+01  2.694e+00   6.922 5.98e-07 ***
## peaOcupada          -1.596e-05  2.241e-05  -0.712    0.484    
## contribuyentesSunat  1.786e-05  2.060e-05   0.867    0.395    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 7.925 on 22 degrees of freedom
## Multiple R-squared:  0.1561, Adjusted R-squared:  0.07939 
## F-statistic: 2.035 on 2 and 22 DF,  p-value: 0.1546

H2: La cantidad de PEA ocupada dependen de la cantidad de contribuyentes a la SUNAT ; y del porcentaje de locales escolares en buen estado; se llega a comprobar que (con una significancia del 0.05):

modelo3=lm(peaOcupada~contribuyentesSunat+buenEstado, data=data)
summary(modelo3)
## 
## Call:
## lm(formula = peaOcupada ~ contribuyentesSunat + buenEstado, data = data)
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -91867 -58573 -11166  46174 155851 
## 
## Coefficients:
##                       Estimate Std. Error t value Pr(>|t|)    
## (Intercept)          1.155e+05  3.787e+04   3.049  0.00588 ** 
## contribuyentesSunat  9.206e-01  1.741e-02  52.872  < 2e-16 ***
## buenEstado          -1.412e+03  1.983e+03  -0.712  0.48395    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 74540 on 22 degrees of freedom
## Multiple R-squared:  0.9932, Adjusted R-squared:  0.9926 
## F-statistic:  1603 on 2 and 22 DF,  p-value: < 2.2e-16
modelo4=formula(peaOcupada~contribuyentesSunat+buenEstado)
regre3=lm(modelo3,data = data)
summary(regre3)
## 
## Call:
## lm(formula = modelo3, data = data)
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -91867 -58573 -11166  46174 155851 
## 
## Coefficients:
##                       Estimate Std. Error t value Pr(>|t|)    
## (Intercept)          1.155e+05  3.787e+04   3.049  0.00588 ** 
## contribuyentesSunat  9.206e-01  1.741e-02  52.872  < 2e-16 ***
## buenEstado          -1.412e+03  1.983e+03  -0.712  0.48395    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 74540 on 22 degrees of freedom
## Multiple R-squared:  0.9932, Adjusted R-squared:  0.9926 
## F-statistic:  1603 on 2 and 22 DF,  p-value: < 2.2e-16