ANÁLISIS ESTADÍSTICO
1. CARGA DE LIBRERÍAS Y DATOS
#==============================ENCABEZADO================================
# TEMA: MODELOS PROBABILISTICOS- PRODUCCION TOTAL DE GAS
# AUTOR: GRUPO 3
# FECHA: 03-2026
#========================================================================
library(dplyr)
library(knitr)
library(gt)
setwd("C:/Users/HP/Documents/PROYECTO ESTADISTICA/RStudio")
datos <- read.csv("tablap.csv", header = TRUE, dec = ",", sep = ";")
2. TABLA DE DISTRIBUCIÓN DE CANTIDAD
produccion_gas <- as.numeric(datos$Total.gas.production.by.2023)
produccion_gas <- na.omit(produccion_gas)
produccion_gas <- produccion_gas[produccion_gas > 0]
caja <- boxplot(produccion_gas, plot = FALSE)
limite_sup <- caja$stats[5]
limite_inf <- caja$stats[1]
gas_outliers <- produccion_gas[produccion_gas < limite_inf | produccion_gas > limite_sup]
gas_sin_outliers <- produccion_gas[produccion_gas >= limite_inf & produccion_gas <= limite_sup]
cat("Cantidad con outliers:", length(produccion_gas), "\n")
## Cantidad con outliers: 12561
cat("Cantidad sin outliers:", length(gas_sin_outliers), "\n")
## Cantidad sin outliers: 11480
histograma_gas <- hist(gas_sin_outliers, plot = FALSE)
ni_gas <- histograma_gas$counts
hi_gas <- ni_gas / sum(ni_gas) * 100
intervalos_gas <- paste0("[", round(histograma_gas$breaks[-length(histograma_gas$breaks)], 2),
", ", round(histograma_gas$breaks[-1], 2), ")")
tabla_base <- data.frame(Intervalo = intervalos_gas, ni = ni_gas, hi = round(hi_gas, 2))
fila_total <- data.frame(Intervalo = "TOTAL", ni = sum(tabla_base$ni), hi = round(sum(tabla_base$hi)))
tabla_final_c <- rbind(tabla_base, fila_total)
tabla_final_c %>%
gt() %>%
cols_label(Intervalo = "Intervalo", ni = "ni", hi = "hi (%)") %>%
tab_header(title = md("Tabla N° 1. Distribución de frecuencias de producción de gas")) %>%
tab_style(
style = list(cell_fill(color = "lightgray"), cell_text(weight = "bold")),
locations = cells_body(rows = Intervalo == "TOTAL")
) %>%
cols_align(align = "center", columns = c(ni, hi)) %>%
tab_options(table.width = pct(80), heading.title.font.size = px(20), column_labels.font.weight = "bold")
| Tabla N° 1. Distribución de frecuencias de producción de gas |
| Intervalo |
ni |
hi (%) |
| [0, 2e+05) |
1031 |
8.98 |
| [2e+05, 4e+05) |
1445 |
12.59 |
| [4e+05, 6e+05) |
1349 |
11.75 |
| [6e+05, 8e+05) |
1280 |
11.15 |
| [8e+05, 1e+06) |
1163 |
10.13 |
| [1e+06, 1200000) |
986 |
8.59 |
| [1200000, 1400000) |
805 |
7.01 |
| [1400000, 1600000) |
595 |
5.18 |
| [1600000, 1800000) |
491 |
4.28 |
| [1800000, 2e+06) |
396 |
3.45 |
| [2e+06, 2200000) |
334 |
2.91 |
| [2200000, 2400000) |
263 |
2.29 |
| [2400000, 2600000) |
260 |
2.26 |
| [2600000, 2800000) |
234 |
2.04 |
| [2800000, 3e+06) |
159 |
1.39 |
| [3e+06, 3200000) |
168 |
1.46 |
| [3200000, 3400000) |
139 |
1.21 |
| [3400000, 3600000) |
122 |
1.06 |
| [3600000, 3800000) |
106 |
0.92 |
| [3800000, 4e+06) |
107 |
0.93 |
| [4e+06, 4200000) |
47 |
0.41 |
| TOTAL |
11480 |
100.00 |
3. GRÁFICA DE DISTRIBUCIÓN DE CANTIDAD
hist(gas_sin_outliers, freq = TRUE,
main = "Grafica 1. Distribucion de cantidad de \n la produccion total de gas",
xlab = "Produccion de Gas", ylab = "Cantidad", col = "indianred1")

4. CONJETURA DEL MODELO
histograma <- hist(gas_sin_outliers, freq = FALSE,
main = "Grafica 2. Comparacion de la realidad con el modelo de la \n produccion de gas",
xlab = "Produccion de Gas", ylab = "Densidad de probabilidad", col = "indianred1")
medialog <- mean(log(gas_sin_outliers))
sd_log <- sd(log(gas_sin_outliers))
x_seq <- seq(min(gas_sin_outliers), max(gas_sin_outliers), length.out = 1000)
curve(dlnorm(x, meanlog = medialog, sdlog = sd_log), add = TRUE, col = "black", lwd = 3)

5. TESTS DE APROBACIÓN
Fo <- histograma$counts
P <- c(0)
for (i in 1:length(Fo)) {
P[i] <- plnorm(histograma$breaks[i+1], medialog, sd_log) - plnorm(histograma$breaks[i], medialog, sd_log)
}
Fe <- P * length(gas_sin_outliers)
Fo_perc <- (Fo / length(gas_sin_outliers)) * 100
Fe_perc <- (Fe / length(gas_sin_outliers)) * 100
Correlacion <- cor(Fo_perc, Fe_perc) * 100
grados_libertad <- length(Fo) - 1
Fe_perc[Fe_perc == 0] <- 1e-9
x2 <- sum((Fe_perc - Fo_perc)^2 / Fe_perc)
umbral_aceptacion <- qchisq(0.95, grados_libertad)
# Tabla Resumen con gt
tabla_resumen <- data.frame(Variable = "Produccion Total Gas",
Pearson = round(Correlacion, 2),
Chi = round(x2, 2),
Umbral = round(umbral_aceptacion, 2))
tabla_resumen %>% gt() %>%
cols_label(Variable = "Variable", Pearson = "Test Pearson (%)", Chi = "Chi Cuadrado", Umbral = "Umbral de aceptacion") %>%
tab_header(title = md("Tabla N° 2. Resumen de test de bondad")) %>%
cols_align(align = "center") %>%
tab_options(table.width = pct(80), column_labels.font.weight = "bold")
| Tabla N° 2. Resumen de test de bondad |
| Variable |
Test Pearson (%) |
Chi Cuadrado |
Umbral de aceptacion |
| Produccion Total Gas |
97.21 |
4.67 |
31.41 |
6. CÁLCULO DE PROBABILIDADES
probabilidad_Gas <- (plnorm(1000000, medialog, sd_log) - plnorm(0, medialog, sd_log))
x_plot <- seq(min(gas_sin_outliers), max(gas_sin_outliers), length.out = 1000)
plot(x_plot, dlnorm(x_plot, medialog, sd_log), col = "skyblue3", lwd = 2, type = "l",
main = "Grafica 4. Calculo de probabilidades de la \n produccion total de gas",
ylab = "Densidad de probabilidad", xlab = "Produccion de Gas")
x_area <- seq(0, 1000000, length.out = 500)
y_area <- dlnorm(x_area, medialog, sd_log)
polygon(c(x_area, rev(x_area)), c(y_area, rep(0, length(y_area))), col = rgb(1, 0, 0, 0.5), border = "black")
text(x = max(gas_sin_outliers)*0.7, y = max(dlnorm(x_plot, medialog, sd_log))*0.8,
labels = paste0("Probabilidad: ", round(probabilidad_Gas*100, 2), "%"), font = 2)

7. INTERVALOS DE CONFIANZA
media_original <- exp(medialog + (sd_log^2)/2)
sigma_original <- sqrt((exp(sd_log^2) - 1) * exp(2 * medialog + sd_log^2))
e <- sigma_original / sqrt(length(gas_sin_outliers))
li <- media_original - 2 * e
ls <- media_original + 2 * e
tabla_media <- data.frame(Variable = "Produccion Total Gas",
li = round(li, 2),
media = round(media_original, 2),
ls = round(ls, 2))
tabla_media %>% gt() %>%
cols_label(Variable = "Variable", li = "Limite inferior", media = "Media poblacional", ls = "Limite superior") %>%
tab_header(title = md("Tabla Nro.3. Media poblacional (TLC)")) %>%
cols_align(align = "center") %>%
tab_options(table.width = pct(80), column_labels.font.weight = "bold")
| Tabla Nro.3. Media poblacional (TLC) |
| Variable |
Limite inferior |
Media poblacional |
Limite superior |
| Produccion Total Gas |
1223382 |
1251457 |
1279531 |
8. CONCLUSIÓN
cat(paste0("La variable produccion total de gas se explica a traves del modelo log-normal siendo la media aritmetica de ",
round(media_original, 2), " y una desviacion estandar de " , round(sigma_original, 2),". De esta manera logramos calcular probabilidades como por ejemplo, que al seleccionar aleatoriamente cualquier area donde la produccion se encuentre entre 0 y 1,000,000 es de ", round(probabilidad_Gas*100, 2), " %. Mediante el teorema de limite central, sabemos que la media aritmetica poblacional de la produccion de gas se encuentra entre ", round(li, 2), " y ", round(ls, 2), " con un 95% de confianza."))
## La variable produccion total de gas se explica a traves del modelo log-normal siendo la media aritmetica de 1251456.72 y una desviacion estandar de 1504031.77. De esta manera logramos calcular probabilidades como por ejemplo, que al seleccionar aleatoriamente cualquier area donde la produccion se encuentre entre 0 y 1,000,000 es de 59.31 %. Mediante el teorema de limite central, sabemos que la media aritmetica poblacional de la produccion de gas se encuentra entre 1223381.96 y 1279531.48 con un 95% de confianza.