datos_originales <- readr::read_delim(
ruta, delim=delimitador, trim_ws=TRUE, show_col_types=FALSE,
name_repair="minimal", col_types=readr::cols(.default=readr::col_character())
)
## Carga exitosa: 47.501 registros y 56 variables.
valores_txt <- stringr::str_squish(as.character(datos_originales[[columna_dd]]))
valores_txt[toupper(valores_txt) %in% c("", "NA", "N/A", "NULL")] <- NA
valores_limpios <- gsub(",", "", valores_txt)
Variable <- suppressWarnings(as.numeric(valores_limpios))
n_total <- length(Variable)
n_nulos <- sum(is.na(Variable))
Variable <- Variable[!is.na(Variable)]
N <- length(Variable)
n_ceros <- sum(Variable == 0)
if (N == 0L) stop("No hay registros válidos de Permit Fee.")
Minimo_real <- min(Variable)
Maximo_real <- max(Variable)
cat("Variable analizada: Permit Fee | Unidad: dólares (USD)\n")
## Variable analizada: Permit Fee | Unidad: dólares (USD)
cat("Observaciones útiles (N):", fmt_entero(N), "| Nulos omitidos:", fmt_entero(n_nulos), "| Valores en 0:", fmt_entero(n_ceros), "\n")
## Observaciones útiles (N): 47.412 | Nulos omitidos: 89 | Valores en 0: 34.397
cat("Mínimo:", fmt_num(Minimo_real, 0), "| Máximo:", fmt_num(Maximo_real, 0), "USD\n")
## Mínimo: 0 | Máximo: 11000 USD
Escala: la tarifa de permiso es cuantitativa continua de escala de razón (0 USD indica ausencia de cobro). El conjunto incluye 34.397 pozos con valor 0 USD (72.55%), que se mantienen en el análisis.
| VARIABLE | TIPO | ESCALA DE MEDICIÓN | UNIDAD DE MEDIDA | UNIDAD DE ANÁLISIS | REGISTROS VÁLIDOS (N) |
|---|---|---|---|---|---|
| PERMIT FEE (Tarifa de permiso, USD) | Cuantitativa continua | Razón | Dólares (USD) | Pozo regulado | 47.412 |
R_sturges <- Maximo_real - Minimo_real
k_sturges <- ceiling(1 + 3.322 * log10(N))
Amplitud_sturges <- R_sturges / k_sturges
cortes_sturges <- Minimo_real + (0:k_sturges) * Amplitud_sturges
cortes_sturges[k_sturges + 1] <- Maximo_real # evita errores de redondeo en el extremo
Li_sturges <- cortes_sturges[1:k_sturges]
Ls_sturges <- cortes_sturges[2:(k_sturges + 1)]
MC_sturges <- (Li_sturges + Ls_sturges) / 2
inter_sturges <- cut(Variable, breaks=cortes_sturges, include.lowest=TRUE, right=FALSE)
ni_sturges <- as.vector(table(inter_sturges))
hi_sturges <- ni_sturges / N
TDF_Sturges <- data.frame(Li=Li_sturges, Ls=Ls_sturges, MC=MC_sturges,
ni=ni_sturges, hi=hi_sturges, hi_perc=hi_sturges * 100)
stopifnot(sum(TDF_Sturges$ni) == N)
cat("Número de intervalos (k):", k_sturges, "\n")
## Número de intervalos (k): 17
cat("Amplitud exacta de clase:", round(Amplitud_sturges, 4), "\n")
## Amplitud exacta de clase: 647.0588
tabla_sturges <- data.frame(
"LÍM. INF (USD)"=fmt_num(TDF_Sturges$Li, 3),
"LÍM. SUP (USD)"=fmt_num(TDF_Sturges$Ls, 3),
"MARCA DE CLASE (xᵢ)"=fmt_num(TDF_Sturges$MC, 3),
"FRECUENCIA ABSOLUTA (nᵢ)"=fmt_entero(TDF_Sturges$ni),
"FRECUENCIA RELATIVA (hᵢ)"=sprintf("%.4f", TDF_Sturges$hi),
"FRECUENCIA RELATIVA PORCENTUAL (%)"=sprintf("%.2f%%", TDF_Sturges$hi_perc),
check.names=FALSE
)
tabla_sturges <- rbind(tabla_sturges, data.frame(
"LÍM. INF (USD)"="TOTAL", "LÍM. SUP (USD)"="", "MARCA DE CLASE (xᵢ)"="",
"FRECUENCIA ABSOLUTA (nᵢ)"=fmt_entero(sum(TDF_Sturges$ni)),
"FRECUENCIA RELATIVA (hᵢ)"="1.0000", "FRECUENCIA RELATIVA PORCENTUAL (%)"="100.00%",
check.names=FALSE
))
cat(crear_cuadro(tabla_sturges, 1,
paste0("Distribución de frecuencias de la tarifa de permiso (USD) — Regla de Sturges, límites exactos, Nueva York, 1860 - 2026 (k = ", k_sturges, ")"),
align=c("c","c","c","r","r","r")))
| LÍM. INF (USD) | LÍM. SUP (USD) | MARCA DE CLASE (xᵢ) | FRECUENCIA ABSOLUTA (nᵢ) | FRECUENCIA RELATIVA (hᵢ) | FRECUENCIA RELATIVA PORCENTUAL (%) |
|---|---|---|---|---|---|
| 0.000 | 647.059 | 323.529 | 38.361 | 0.8091 | 80.91% |
| 647.059 | 1294.118 | 970.588 | 7.135 | 0.1505 | 15.05% |
| 1294.118 | 1941.176 | 1617.647 | 1.106 | 0.0233 | 2.33% |
| 1941.176 | 2588.235 | 2264.706 | 468 | 0.0099 | 0.99% |
| 2588.235 | 3235.294 | 2911.765 | 117 | 0.0025 | 0.25% |
| 3235.294 | 3882.353 | 3558.824 | 59 | 0.0012 | 0.12% |
| 3882.353 | 4529.412 | 4205.882 | 75 | 0.0016 | 0.16% |
| 4529.412 | 5176.471 | 4852.941 | 48 | 0.0010 | 0.10% |
| 5176.471 | 5823.529 | 5500.000 | 38 | 0.0008 | 0.08% |
| 5823.529 | 6470.588 | 6147.059 | 3 | 0.0001 | 0.01% |
| 6470.588 | 7117.647 | 6794.118 | 1 | 0.0000 | 0.00% |
| 7117.647 | 7764.706 | 7441.176 | 0 | 0.0000 | 0.00% |
| 7764.706 | 8411.765 | 8088.235 | 0 | 0.0000 | 0.00% |
| 8411.765 | 9058.824 | 8735.294 | 0 | 0.0000 | 0.00% |
| 9058.824 | 9705.882 | 9382.353 | 0 | 0.0000 | 0.00% |
| 9705.882 | 10352.941 | 10029.412 | 0 | 0.0000 | 0.00% |
| 10352.941 | 11000.000 | 10676.471 | 1 | 0.0000 | 0.00% |
| TOTAL | 47.412 | 1.0000 | 100.00% |
Fuente: Oil, Gas & Other Regulated Wells: Beginning 1860.
Los límites exactos de Sturges (Cuadro N° 1) son poco prácticos, por lo que se redondean a múltiplos de 10 manteniendo el mismo número de clases (k).
BASE <- 10
min_int <- floor(Minimo_real / BASE) * BASE
max_int <- ceiling(Maximo_real / BASE) * BASE
k_int_sug <- k_sturges # se mantiene el mismo k obtenido en el paso 1 (Sturges)
Rango_int <- max_int - min_int
Amplitud_int <- ceiling((Rango_int / k_int_sug) / BASE) * BASE
if (Amplitud_int == 0) Amplitud_int <- BASE
cortes_int <- seq(from=min_int, by=Amplitud_int, length.out=k_int_sug + 1)
if (max(cortes_int) < Maximo_real) cortes_int <- c(cortes_int, max(cortes_int) + Amplitud_int)
while (length(cortes_int) > 2 && cortes_int[length(cortes_int) - 1] >= Maximo_real) {
cortes_int <- cortes_int[-length(cortes_int)]
}
K_real <- length(cortes_int) - 1
inter_int <- cut(Variable, breaks=cortes_int, include.lowest=TRUE, right=FALSE)
ni_int <- as.vector(table(inter_int))
hi_int_unit <- ni_int / N
hi_int_perc <- hi_int_unit * 100
TDF_Enteros <- data.frame(
Li = cortes_int[1:K_real],
Ls = cortes_int[2:(K_real + 1)],
MC = (cortes_int[1:K_real] + cortes_int[2:(K_real + 1)]) / 2,
ni = ni_int,
hi_unit = hi_int_unit,
hi_perc = hi_int_perc,
Ni_asc = cumsum(ni_int),
Ni_desc = rev(cumsum(rev(ni_int))),
Hi_asc_perc = cumsum(hi_int_perc),
Hi_desc_perc = rev(cumsum(rev(hi_int_perc)))
)
stopifnot(sum(TDF_Enteros$ni) == N)
cat("Clases ajustadas (k), consistentes con Sturges:", K_real, "\n")
## Clases ajustadas (k), consistentes con Sturges: 17
cat("Amplitud ajustada:", Amplitud_int, "USD\n")
## Amplitud ajustada: 650 USD
tabla_final <- data.frame(
"LÍM. INF (USD)"=fmt_num(TDF_Enteros$Li, 0),
"LÍM. SUP (USD)"=fmt_num(TDF_Enteros$Ls, 0),
"MARCA DE CLASE (xᵢ)"=fmt_num(TDF_Enteros$MC, 1),
"nᵢ"=fmt_entero(TDF_Enteros$ni),
"hᵢ"=sprintf("%.4f", TDF_Enteros$hi_unit),
"hᵢ (%)"=sprintf("%.2f", TDF_Enteros$hi_perc),
"Nᵢ (↑)"=fmt_entero(TDF_Enteros$Ni_asc),
"Nᵢ (↓)"=fmt_entero(TDF_Enteros$Ni_desc),
"Hᵢ (% ↑)"=sprintf("%.2f", TDF_Enteros$Hi_asc_perc),
"Hᵢ (% ↓)"=sprintf("%.2f", TDF_Enteros$Hi_desc_perc),
check.names=FALSE
)
tabla_final <- rbind(tabla_final, data.frame(
"LÍM. INF (USD)"="TOTAL", "LÍM. SUP (USD)"="", "MARCA DE CLASE (xᵢ)"="",
"nᵢ"=fmt_entero(sum(TDF_Enteros$ni)), "hᵢ"="1.0000", "hᵢ (%)"="100.00",
"Nᵢ (↑)"="", "Nᵢ (↓)"="", "Hᵢ (% ↑)"="", "Hᵢ (% ↓)"="", check.names=FALSE
))
cat(crear_cuadro(tabla_final, 2,
"Distribución de frecuencias de los pozos regulados según la tarifa de permiso (USD), límites enteros, Nueva York, 1860 - 2026",
desplazamiento=(K_real > 15L), align=c("c","c","c",rep("r",7))))
| LÍM. INF (USD) | LÍM. SUP (USD) | MARCA DE CLASE (xᵢ) | nᵢ | hᵢ | hᵢ (%) | Nᵢ (↑) | Nᵢ (↓) | Hᵢ (% ↑) | Hᵢ (% ↓) |
|---|---|---|---|---|---|---|---|---|---|
| 0 | 650 | 325.0 | 38.361 | 0.8091 | 80.91 | 38.361 | 47.412 | 80.91 | 100.00 |
| 650 | 1300 | 975.0 | 7.135 | 0.1505 | 15.05 | 45.496 | 9.051 | 95.96 | 19.09 |
| 1300 | 1950 | 1625.0 | 1.106 | 0.0233 | 2.33 | 46.602 | 1.916 | 98.29 | 4.04 |
| 1950 | 2600 | 2275.0 | 468 | 0.0099 | 0.99 | 47.070 | 810 | 99.28 | 1.71 |
| 2600 | 3250 | 2925.0 | 117 | 0.0025 | 0.25 | 47.187 | 342 | 99.53 | 0.72 |
| 3250 | 3900 | 3575.0 | 59 | 0.0012 | 0.12 | 47.246 | 225 | 99.65 | 0.47 |
| 3900 | 4550 | 4225.0 | 75 | 0.0016 | 0.16 | 47.321 | 166 | 99.81 | 0.35 |
| 4550 | 5200 | 4875.0 | 48 | 0.0010 | 0.10 | 47.369 | 91 | 99.91 | 0.19 |
| 5200 | 5850 | 5525.0 | 38 | 0.0008 | 0.08 | 47.407 | 43 | 99.99 | 0.09 |
| 5850 | 6500 | 6175.0 | 4 | 0.0001 | 0.01 | 47.411 | 5 | 100.00 | 0.01 |
| 6500 | 7150 | 6825.0 | 0 | 0.0000 | 0.00 | 47.411 | 1 | 100.00 | 0.00 |
| 7150 | 7800 | 7475.0 | 0 | 0.0000 | 0.00 | 47.411 | 1 | 100.00 | 0.00 |
| 7800 | 8450 | 8125.0 | 0 | 0.0000 | 0.00 | 47.411 | 1 | 100.00 | 0.00 |
| 8450 | 9100 | 8775.0 | 0 | 0.0000 | 0.00 | 47.411 | 1 | 100.00 | 0.00 |
| 9100 | 9750 | 9425.0 | 0 | 0.0000 | 0.00 | 47.411 | 1 | 100.00 | 0.00 |
| 9750 | 10400 | 10075.0 | 0 | 0.0000 | 0.00 | 47.411 | 1 | 100.00 | 0.00 |
| 10400 | 11050 | 10725.0 | 1 | 0.0000 | 0.00 | 47.412 | 1 | 100.00 | 0.00 |
| TOTAL | 47.412 | 1.0000 | 100.00 |
Fuente: Oil, Gas & Other Regulated Wells: Beginning 1860.
Interpretación: el intervalo de monto con mayor concentración de pozos es [0 – 650) USD, con 38.361 pozos (80.91% de los 47.412 registros válidos). Hasta los 650 USD se acumula al menos el 50 % de los pozos.
ggplot2::ggplot(tabla_graf, ggplot2::aes(x=intervalo, y=ni, fill=intervalo)) +
ggplot2::geom_col(width=.72, color="#244861", linewidth=.36) +
ggplot2::geom_text(ggplot2::aes(label=fmt_entero(ni)), vjust=-.48,
size=4.5, fontface="bold", color="#15364C") +
ggplot2::scale_fill_manual(values=colores) +
ggplot2::scale_y_continuous(limits=c(0, limite_ni_local), labels=fmt_entero,
expand=ggplot2::expansion(mult=c(0,0))) +
ggplot2::coord_cartesian(clip="off") +
ggplot2::labs(title="Gráfica N° 1: Frecuencia absoluta (nᵢ) local",
x="Tarifa de permiso (USD)", y="Frecuencia absoluta (nᵢ)", caption=fuente_graficas) +
tema_barras
ggplot2::ggplot(tabla_graf, ggplot2::aes(x=intervalo, y=ni)) +
ggplot2::geom_col(fill=color_barras, color="#244861", width=.72, linewidth=.36) +
ggplot2::geom_text(ggplot2::aes(label=fmt_entero(ni)), vjust=-.48,
size=4.5, fontface="bold", color="#15364C") +
ggplot2::scale_y_continuous(limits=c(0, limite_ni_global), labels=fmt_entero,
expand=ggplot2::expansion(mult=c(0,0))) +
ggplot2::coord_cartesian(clip="off") +
ggplot2::labs(title="Gráfica N° 2: Frecuencia absoluta (nᵢ) global",
x="Tarifa de permiso (USD)", y="Frecuencia absoluta (nᵢ)", caption=fuente_graficas) +
tema_barras
ggplot2::ggplot(tabla_graf, ggplot2::aes(x=intervalo, y=hi_unit, fill=intervalo)) +
ggplot2::geom_col(width=.72, color="#244861", linewidth=.36) +
ggplot2::geom_text(ggplot2::aes(label=sprintf("%.2f%%", hi_perc)), vjust=-.48,
size=4.3, fontface="bold", color="#15364C") +
ggplot2::scale_fill_manual(values=colores) +
ggplot2::scale_y_continuous(limits=c(0, limite_hi_local), labels=etiqueta_pct,
expand=ggplot2::expansion(mult=c(0,0))) +
ggplot2::coord_cartesian(clip="off") +
ggplot2::labs(title="Gráfica N° 3: Frecuencia relativa (hᵢ) local",
x="Tarifa de permiso (USD)", y="Frecuencia relativa (%)", caption=fuente_graficas) +
tema_barras
ggplot2::ggplot(tabla_graf, ggplot2::aes(x=intervalo, y=hi_unit)) +
ggplot2::geom_col(fill=color_barras, color="#244861", width=.72, linewidth=.36) +
ggplot2::geom_text(ggplot2::aes(label=sprintf("%.2f%%", hi_perc)), vjust=-.48,
size=4.3, fontface="bold", color="#15364C") +
ggplot2::scale_y_continuous(limits=c(0, limite_hi_global), breaks=seq(0, 1, by=.2),
labels=etiqueta_pct, expand=ggplot2::expansion(mult=c(0,0))) +
ggplot2::coord_cartesian(clip="off") +
ggplot2::labs(title="Gráfica N° 4: Frecuencia relativa (hᵢ) global",
x="Tarifa de permiso (USD)", y="Frecuencia relativa (%)", caption=fuente_graficas) +
tema_barras
col_grid <- "#DDE6ED"
eje_x <- pretty(Variable, n=8)
par(mar=c(7, 5, 4, 2))
plot(NULL, xlim=range(eje_x), ylim=c(0.4, 1.6), axes=FALSE, xlab="", ylab="",
main="Gráfica N° 5: Diagrama de caja de la tarifa de permiso")
abline(v=eje_x, col=col_grid, lty="dotted") # cuadrícula detrás de la caja
boxplot(Variable, horizontal=TRUE, at=1, add=TRUE, axes=FALSE, col=color_barras,
border="#15364C", medlwd=3, outline=TRUE, outcol=color_outlier,
boxwex=0.5, frame.plot=FALSE)
axis(1, at=eje_x, labels=fmt_entero(eje_x), las=2, cex.axis=0.9)
mtext("Tarifa de permiso (USD)", side=1, line=5.5)
ojiva_df <- data.frame(
x = c(TDF_Enteros$Ls, TDF_Enteros$Li),
y = c(TDF_Enteros$Hi_asc_perc, TDF_Enteros$Hi_desc_perc),
tipo = rep(c("Ascendente", "Descendente"), each=K_real)
)
ggplot2::ggplot(ojiva_df, ggplot2::aes(x=x, y=y, color=tipo, group=tipo)) +
ggplot2::geom_line(linewidth=1.2) +
ggplot2::geom_point(size=2.8) +
ggplot2::scale_color_manual(values=c(Ascendente=color_ojiva1, Descendente=color_ojiva2)) +
ggplot2::scale_x_continuous(labels=fmt_entero) +
ggplot2::scale_y_continuous(labels=function(x) paste0(x, "%"), limits=c(0, 105),
expand=ggplot2::expansion(mult=c(0, 0))) +
ggplot2::labs(title="Gráfica N° 6: Ojivas ascendente y descendente",
x="Tarifa de permiso (USD)", y="Frecuencia acumulada (%)", color=NULL,
caption=fuente_graficas) +
tema_barras +
ggplot2::theme(legend.position="bottom",
legend.text=ggplot2::element_text(size=13),
axis.text.x=ggplot2::element_text(angle=0, hjust=.5),
panel.grid.major.x=ggplot2::element_line(color="#DDE6ED", linewidth=.35))
Tarifa de permiso es cuantitativa continua de escala de razón (sección 3): se calculan tendencia central, dispersión, forma y valores atípicos.
media <- mean(Variable)
mediana <- median(Variable)
moda_val <- TDF_Enteros$MC[which.max(TDF_Enteros$ni)] # marca de clase de la clase modal
varianza <- var(Variable)
sd_val <- sd(Variable)
CV <- (sd_val / abs(media)) * 100
asim <- e1071::skewness(Variable, type=2)
kurt <- e1071::kurtosis(Variable) # curtosis en exceso (normal = 0)
Q1 <- quantile(Variable, 0.25); Q3 <- quantile(Variable, 0.75); IQR_val <- Q3 - Q1
outliers_data <- Variable[Variable < (Q1 - 1.5*IQR_val) | Variable > (Q3 + 1.5*IQR_val)]
num_out <- length(outliers_data)
out_txt <- if (num_out > 0) {
paste0(fmt_entero(num_out), " [", fmt_num(min(outliers_data), 0), "; ", fmt_num(max(outliers_data), 0), "]")
} else "0 [Sin outliers]"
ind <- data.frame(
"Variable"="Tarifa de permiso (USD)",
"Rango"=paste0("[", fmt_num(min(Variable),0), "; ", fmt_num(max(Variable),0), "]"),
"Media (X̄)"=fmt_num(media, 2), "Mediana (Me)"=fmt_num(mediana, 2), "Moda (Mo)"=fmt_num(moda_val, 2),
"Varianza (S²)"=fmt_num(varianza, 2), "Desv. Est. (S)"=fmt_num(sd_val, 2),
"C.V. (%)"=fmt_num(CV, 2),
"Asimetría (As)"=fmt_num(asim, 4), "Curtosis (K)"=fmt_num(kurt, 4),
"Outliers [Intervalo]"=out_txt, check.names=FALSE
)
k <- knitr::kable(ind, format="html", escape=TRUE, align=c("l", rep("c", 10))) |>
kableExtra::kable_styling(bootstrap_options=c("striped","condensed"),
full_width=TRUE, position="center") |>
kableExtra::add_header_above(c("Variable"=2, "Tendencia central"=3,
"Dispersión"=3, "Forma"=2, "Valores atípicos"=1), bold=TRUE, background="#dddfe2") |>
kableExtra::row_spec(0, bold=TRUE, background="#f1f2f4")
cat('<div class="cuadro indicadores">',
'<div class="cuadro-titulo">Cuadro N° 3: Indicadores estadísticos de Tarifa de permiso (USD), Nueva York, 1860 - 2026</div>',
as.character(k),
'<p class="cuadro-nota"><strong>Registros válidos (N):</strong> ', fmt_entero(N),
' | <strong>Clases (k):</strong> ', K_real,
' | <strong>Amplitud:</strong> ', Amplitud_int, ' USD',
' | <strong>Q1:</strong> ', fmt_num(Q1,0),
' | <strong>Q3:</strong> ', fmt_num(Q3,0), '.</p>',
'<p class="cuadro-nota">La moda se calcula como la marca de clase del intervalo de mayor frecuencia. La curtosis se expresa en exceso respecto a la normal (K = 0).</p>',
'<p class="cuadro-fuente">Fuente: Oil, Gas & Other Regulated Wells: Beginning 1860.</p></div>', sep="")
| Variable | Rango | Media (X̄) | Mediana (Me) | Moda (Mo) | Varianza (S²) | Desv. Est. (S) | C.V. (%) | Asimetría (As) | Curtosis (K) | Outliers [Intervalo] |
|---|---|---|---|---|---|---|---|---|---|---|
| Tarifa de permiso (USD) | [0; 11000] | 255.79 | 0.00 | 325.00 | 305695.99 | 552.90 | 216.15 | 3.5599 | 21.4793 | 11.752 [190; 11000] |
Registros válidos (N): 47.412 | Clases (k): 17 | Amplitud: 650 USD | Q1: 0 | Q3: 20.
La moda se calcula como la marca de clase del intervalo de mayor frecuencia. La curtosis se expresa en exceso respecto a la normal (K = 0).
Fuente: Oil, Gas & Other Regulated Wells: Beginning 1860.
Los valores de la tarifa de permiso de los pozos regulados de Nueva York fluctúan entre 0 y 11000 USD y giran en torno a 0.00 USD (mediana), con una media de 255.79 USD y una desviación estándar de 552.90, lo que da un conjunto de datos heterogéneo (C.V. = 216.15%). La distribución es asimétrica positiva (cola hacia los montos altos) (As = 3.5599) y leptocúrtica (más concentrada que la normal) (K = 21.4793), y presenta 11.752 valores atípicos (entre 190 y 11000 USD). El intervalo con más pozos es [0 – 650) USD, con 80.91% de los registros válidos, lo que muestra que los montos se concentran en determinadas franjas de valor. Cabe señalar que 34.397 pozos (72.55%) registran un monto de 0 USD y que 89 registros sin dato fueron excluidos del análisis.
Autor: Estalin Echeverría | Grupo 5 | Análisis Estadístico — Oil, Gas & Other Regulated Wells - NY State