library(rio)
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 3.5.0 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.1
## ✔ 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
library(dplyr)
library(ggplot2)
library(sjPlot)
library(ggfortify)
library(forcats)
library(lsr)
library(scales)
##
## Attaching package: 'scales'
##
## The following object is masked from 'package:purrr':
##
## discard
##
## The following object is masked from 'package:readr':
##
## col_factor
library(DescTools)
library(magrittr)
##
## Attaching package: 'magrittr'
##
## The following object is masked from 'package:purrr':
##
## set_names
##
## The following object is masked from 'package:tidyr':
##
## extract
library(margins)
library(knitr)
library(jtools)
##
## Attaching package: 'jtools'
##
## The following object is masked from 'package:DescTools':
##
## %nin%
library(stargazer)
##
## Please cite as:
##
## Hlavac, Marek (2022). stargazer: Well-Formatted Regression and Summary Statistics Tables.
## R package version 5.2.3. https://CRAN.R-project.org/package=stargazer
library(lmtest)
## Loading required package: zoo
##
## Attaching package: 'zoo'
##
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
library(kableExtra)
##
## Attaching package: 'kableExtra'
##
## The following object is masked from 'package:dplyr':
##
## group_rows
library(car)
## Loading required package: carData
##
## Attaching package: 'car'
##
## The following object is masked from 'package:DescTools':
##
## Recode
##
## The following object is masked from 'package:dplyr':
##
## recode
##
## The following object is masked from 'package:purrr':
##
## some
library(summarytools)
##
## Attaching package: 'summarytools'
##
## The following object is masked from 'package:tibble':
##
## view
library(cvms)
library(survminer)
## Loading required package: ggpubr
##
## Attaching package: 'ggpubr'
##
## The following object is masked from 'package:cvms':
##
## font
library(survival)
##
## Attaching package: 'survival'
##
## The following object is masked from 'package:survminer':
##
## myeloma
library(modelsummary)
## `modelsummary` 2.0.0 now uses `tinytable` as its default table-drawing
## backend. Learn more at: https://vincentarelbundock.github.io/tinytable/
##
## Revert to `kableExtra` for one session:
##
## options(modelsummary_factory_default = 'kableExtra')
## options(modelsummary_factory_latex = 'kableExtra')
## options(modelsummary_factory_html = 'kableExtra')
##
## Silence this message forever:
##
## config_modelsummary(startup_message = FALSE)
##
## Attaching package: 'modelsummary'
##
## The following objects are masked from 'package:DescTools':
##
## Format, Mean, Median, N, SD, Var
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 ...
data$contribuyentesSunat_pct <- (data$contribuyentesSunat / data$pobTotal) * 100
data$peaOcupada_pct <- (data$peaOcupada / data$pobTotal) * 100
hipotesis1 = formula(data$buenEstado~data$contribuyentesSunat_pct+data$peaOcupada_pct)
regresion1=glm(hipotesis1, data=data,family = gaussian)
summary(regresion1)
##
## Call:
## glm(formula = hipotesis1, family = gaussian, data = data)
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -22.6095 15.9617 -1.416 0.171
## data$contribuyentesSunat_pct 0.1003 0.3121 0.321 0.751
## data$peaOcupada_pct 1.0218 0.6424 1.590 0.126
##
## (Dispersion parameter for gaussian family taken to be 39.67738)
##
## Null deviance: 1637.3 on 24 degrees of freedom
## Residual deviance: 872.9 on 22 degrees of freedom
## AIC: 167.77
##
## Number of Fisher Scoring iterations: 2
hipotesis2 = formula(data$peaOcupada~data$contribuyentesSunat+data$buenEstado)
regresion2 = glm(hipotesis2, data = data, family = poisson)
summary(regresion2)
##
## Call:
## glm(formula = hipotesis2, family = poisson, data = data)
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 1.238e+01 9.007e-04 13744.7 <2e-16 ***
## data$contribuyentesSunat 5.575e-07 1.786e-10 3121.7 <2e-16 ***
## data$buenEstado 7.924e-03 4.530e-05 174.9 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for poisson family taken to be 1)
##
## Null deviance: 16555865 on 24 degrees of freedom
## Residual deviance: 2148535 on 22 degrees of freedom
## AIC: 2148901
##
## Number of Fisher Scoring iterations: 4