1 Configuración y Carga de Datos

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.

2 Extracción y Limpieza de la Variable

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 Depth Fee.")

Minimo_real <- min(Variable)
Maximo_real <- max(Variable)

cat("Variable analizada: Depth Fee | Unidad: dólares (USD)\n")
## Variable analizada: Depth 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.496 | Nulos omitidos: 5 | Valores en 0: 35.744
cat("Mínimo:", fmt_num(Minimo_real, 0), "| Máximo:", fmt_num(Maximo_real, 0), "USD\n")
## Mínimo: 0 | Máximo: 10900 USD

3 Identificación de la Variable

Escala: la tarifa por profundidad es cuantitativa continua de escala de razón (0 USD indica ausencia de cobro). El conjunto incluye 35.744 pozos con valor 0 USD (75.26%), que se mantienen en el análisis.

VARIABLE TIPO ESCALA DE MEDICIÓN UNIDAD DE MEDIDA UNIDAD DE ANÁLISIS REGISTROS VÁLIDOS (N)
DEPTH FEE (Tarifa por profundidad, USD) Cuantitativa continua Razón Dólares (USD) Pozo regulado 47.496

4 Tabla de Distribución de Frecuencias

4.1 Tabla con Límites Decimales (Regla de Sturges)

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: 641.1765
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 por profundidad (USD) — Regla de Sturges, límites exactos, Nueva York, 1860 - 2026 (k = ", k_sturges, ")"),
  align=c("c","c","c","r","r","r")))
Cuadro N° 1: Distribución de frecuencias de la tarifa por profundidad (USD) — Regla de Sturges, límites exactos, Nueva York, 1860 - 2026 (k = 17)
LÍM. INF (USD) LÍM. SUP (USD) MARCA DE CLASE (xᵢ) FRECUENCIA ABSOLUTA (nᵢ) FRECUENCIA RELATIVA (hᵢ) FRECUENCIA RELATIVA PORCENTUAL (%)
0.000 641.176 320.588 39.956 0.8412 84.12%
641.176 1282.353 961.765 5.879 0.1238 12.38%
1282.353 1923.529 1602.941 1.085 0.0228 2.28%
1923.529 2564.706 2244.118 253 0.0053 0.53%
2564.706 3205.882 2885.294 98 0.0021 0.21%
3205.882 3847.059 3526.471 78 0.0016 0.16%
3847.059 4488.235 4167.647 56 0.0012 0.12%
4488.235 5129.412 4808.824 48 0.0010 0.10%
5129.412 5770.588 5450.000 38 0.0008 0.08%
5770.588 6411.765 6091.176 4 0.0001 0.01%
6411.765 7052.941 6732.353 0 0.0000 0.00%
7052.941 7694.118 7373.529 0 0.0000 0.00%
7694.118 8335.294 8014.706 0 0.0000 0.00%
8335.294 8976.471 8655.882 0 0.0000 0.00%
8976.471 9617.647 9297.059 0 0.0000 0.00%
9617.647 10258.824 9938.235 0 0.0000 0.00%
10258.824 10900.000 10579.412 1 0.0000 0.00%
TOTAL 47.496 1.0000 100.00%

Fuente: Oil, Gas & Other Regulated Wells: Beginning 1860.

4.2 Justificación del ajuste

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).

4.3 Tabla con Límites Enteros

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 por profundidad (USD), límites enteros, Nueva York, 1860 - 2026",
  desplazamiento=(K_real > 15L), align=c("c","c","c",rep("r",7))))
Cuadro N° 2: Distribución de frecuencias de los pozos regulados según la tarifa por profundidad (USD), límites enteros, Nueva York, 1860 - 2026
LÍM. INF (USD) LÍM. SUP (USD) MARCA DE CLASE (xᵢ) nᵢ hᵢ hᵢ (%) Nᵢ (↑) Nᵢ (↓) Hᵢ (% ↑) Hᵢ (% ↓)
0 650 325.0 39.956 0.8412 84.12 39.956 47.496 84.12 100.00
650 1300 975.0 5.879 0.1238 12.38 45.835 7.540 96.50 15.88
1300 1950 1625.0 1.085 0.0228 2.28 46.920 1.661 98.79 3.50
1950 2600 2275.0 253 0.0053 0.53 47.173 576 99.32 1.21
2600 3250 2925.0 114 0.0024 0.24 47.287 323 99.56 0.68
3250 3900 3575.0 62 0.0013 0.13 47.349 209 99.69 0.44
3900 4550 4225.0 56 0.0012 0.12 47.405 147 99.81 0.31
4550 5200 4875.0 64 0.0013 0.13 47.469 91 99.94 0.19
5200 5850 5525.0 22 0.0005 0.05 47.491 27 99.99 0.06
5850 6500 6175.0 4 0.0001 0.01 47.495 5 100.00 0.01
6500 7150 6825.0 0 0.0000 0.00 47.495 1 100.00 0.00
7150 7800 7475.0 0 0.0000 0.00 47.495 1 100.00 0.00
7800 8450 8125.0 0 0.0000 0.00 47.495 1 100.00 0.00
8450 9100 8775.0 0 0.0000 0.00 47.495 1 100.00 0.00
9100 9750 9425.0 0 0.0000 0.00 47.495 1 100.00 0.00
9750 10400 10075.0 0 0.0000 0.00 47.495 1 100.00 0.00
10400 11050 10725.0 1 0.0000 0.00 47.496 1 100.00 0.00
TOTAL 47.496 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 39.956 pozos (84.12% de los 47.496 registros válidos). Hasta los 650 USD se acumula al menos el 50 % de los pozos.

5 Representación Gráfica

5.1 Gráfica N° 1 — Frecuencia absoluta (nᵢ) local

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 por profundidad (USD)", y="Frecuencia absoluta (nᵢ)", caption=fuente_graficas) +
  tema_barras

5.2 Gráfica N° 2 — Frecuencia absoluta (nᵢ) global

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 por profundidad (USD)", y="Frecuencia absoluta (nᵢ)", caption=fuente_graficas) +
  tema_barras

5.3 Gráfica N° 3 — Frecuencia relativa (hᵢ) local

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 por profundidad (USD)", y="Frecuencia relativa (%)", caption=fuente_graficas) +
  tema_barras

5.4 Gráfica N° 4 — Frecuencia relativa (hᵢ) global

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 por profundidad (USD)", y="Frecuencia relativa (%)", caption=fuente_graficas) +
  tema_barras

5.5 Gráfica N° 5 — Diagrama de caja

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 por profundidad")
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 por profundidad (USD)", side=1, line=5.5)

5.6 Gráfica N° 6 — Ojivas

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 por profundidad (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))

6 Tabla de Indicadores

Tarifa por profundidad 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 por profundidad (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 por profundidad (USD), Nueva York, 1860 - 2026</div>',
    as.character(k),
    '<p class="cuadro-nota"><strong>Registros válidos (N):</strong> ', fmt_entero(N),
    ' &nbsp; | &nbsp; <strong>Clases (k):</strong> ', K_real,
    ' &nbsp; | &nbsp; <strong>Amplitud:</strong> ', Amplitud_int, ' USD',
    ' &nbsp; | &nbsp; <strong>Q1:</strong> ', fmt_num(Q1,0),
    ' &nbsp; | &nbsp; <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 &amp; Other Regulated Wells: Beginning 1860.</p></div>', sep="")
Cuadro N° 3: Indicadores estadísticos de Tarifa por profundidad (USD), Nueva York, 1860 - 2026
Variable
Tendencia central
Dispersión
Forma
Valores atípicos
Variable Rango Media (X̄) Mediana (Me) Moda (Mo) Varianza (S²) Desv. Est. (S) C.V. (%) Asimetría (As) Curtosis (K) Outliers [Intervalo]
Tarifa por profundidad (USD) [0; 10900] 230.06 0.00 325.00 269040.94 518.69 225.46 3.9405 26.1299 11.752 [90; 10900]

Registros válidos (N): 47.496   |   Clases (k): 17   |   Amplitud: 650 USD   |   Q1: 0   |   Q3: 0.

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.

7 Conclusión

Los valores de la tarifa por profundidad de los pozos regulados de Nueva York fluctúan entre 0 y 10900 USD y giran en torno a 0.00 USD (mediana), con una media de 230.06 USD y una desviación estándar de 518.69, lo que da un conjunto de datos heterogéneo (C.V. = 225.46%). La distribución es asimétrica positiva (cola hacia los montos altos) (As = 3.9405) y leptocúrtica (más concentrada que la normal) (K = 26.1299), y presenta 11.752 valores atípicos (entre 90 y 10900 USD). El intervalo con más pozos es [0 – 650) USD, con 84.12% de los registros válidos, lo que muestra que los montos se concentran en determinadas franjas de valor. Cabe señalar que 35.744 pozos (75.26%) registran un monto de 0 USD y que 5 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