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_md]]))
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 Measured Depth.")
Minimo_real <- min(Variable)
Maximo_real <- max(Variable)
cat("Variable analizada: Measured Depth, ft | Unidad: pies (ft)\n")
## Variable analizada: Measured Depth, ft | Unidad: pies (ft)
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: 14.679
cat("Mínimo:", fmt_num(Minimo_real, 0), "| Máximo:", fmt_num(Maximo_real, 0), "pies\n")
## Mínimo: 0 | Máximo: 15921 pies
Escala: la profundidad medida es cuantitativa continua de escala de razón (el 0 ft indica ausencia de profundidad). El conjunto incluye 14.679 pozos con valor 0 ft (30.91%), que se mantienen en el análisis.
| VARIABLE | TIPO | ESCALA DE MEDICIÓN | UNIDAD DE MEDIDA | UNIDAD DE ANÁLISIS | REGISTROS VÁLIDOS (N) |
|---|---|---|---|---|---|
| MEASURED DEPTH (Profundidad medida, ft) | Cuantitativa continua | Razón | Pies (ft) | Pozo regulado | 47.496 |
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: 936.5294
tabla_sturges <- data.frame(
"LÍM. INF (ft)"=fmt_num(TDF_Sturges$Li, 3),
"LÍM. SUP (ft)"=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 (ft)"="TOTAL", "LÍM. SUP (ft)"="", "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 profundidad medida (ft) — Regla de Sturges, límites exactos, Nueva York, 1860 - 2026 (k = ", k_sturges, ")"),
align=c("c","c","c","r","r","r")))
| LÍM. INF (ft) | LÍM. SUP (ft) | MARCA DE CLASE (xᵢ) | FRECUENCIA ABSOLUTA (nᵢ) | FRECUENCIA RELATIVA (hᵢ) | FRECUENCIA RELATIVA PORCENTUAL (%) |
|---|---|---|---|---|---|
| 0.000 | 936.529 | 468.265 | 18.033 | 0.3797 | 37.97% |
| 936.529 | 1873.059 | 1404.794 | 16.688 | 0.3514 | 35.14% |
| 1873.059 | 2809.588 | 2341.324 | 5.566 | 0.1172 | 11.72% |
| 2809.588 | 3746.118 | 3277.853 | 2.959 | 0.0623 | 6.23% |
| 3746.118 | 4682.647 | 4214.382 | 2.983 | 0.0628 | 6.28% |
| 4682.647 | 5619.176 | 5150.912 | 638 | 0.0134 | 1.34% |
| 5619.176 | 6555.706 | 6087.441 | 109 | 0.0023 | 0.23% |
| 6555.706 | 7492.235 | 7023.971 | 112 | 0.0024 | 0.24% |
| 7492.235 | 8428.765 | 7960.500 | 85 | 0.0018 | 0.18% |
| 8428.765 | 9365.294 | 8897.029 | 62 | 0.0013 | 0.13% |
| 9365.294 | 10301.824 | 9833.559 | 74 | 0.0016 | 0.16% |
| 10301.824 | 11238.353 | 10770.088 | 50 | 0.0011 | 0.11% |
| 11238.353 | 12174.882 | 11706.618 | 68 | 0.0014 | 0.14% |
| 12174.882 | 13111.412 | 12643.147 | 42 | 0.0009 | 0.09% |
| 13111.412 | 14047.941 | 13579.676 | 20 | 0.0004 | 0.04% |
| 14047.941 | 14984.471 | 14516.206 | 4 | 0.0001 | 0.01% |
| 14984.471 | 15921.000 | 15452.735 | 3 | 0.0001 | 0.01% |
| TOTAL | 47.496 | 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, "pies\n")
## Amplitud ajustada: 940 pies
tabla_final <- data.frame(
"LÍM. INF (ft)"=fmt_num(TDF_Enteros$Li, 0),
"LÍM. SUP (ft)"=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 (ft)"="TOTAL", "LÍM. SUP (ft)"="", "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 profundidad medida (ft), límites enteros, Nueva York, 1860 - 2026",
desplazamiento=(K_real > 15L), align=c("c","c","c",rep("r",7))))
| LÍM. INF (ft) | LÍM. SUP (ft) | MARCA DE CLASE (xᵢ) | nᵢ | hᵢ | hᵢ (%) | Nᵢ (↑) | Nᵢ (↓) | Hᵢ (% ↑) | Hᵢ (% ↓) |
|---|---|---|---|---|---|---|---|---|---|
| 0 | 940 | 470.0 | 18.051 | 0.3801 | 38.01 | 18.051 | 47.496 | 38.01 | 100.00 |
| 940 | 1880 | 1410.0 | 16.751 | 0.3527 | 35.27 | 34.802 | 29.445 | 73.27 | 61.99 |
| 1880 | 2820 | 2350.0 | 5.516 | 0.1161 | 11.61 | 40.318 | 12.694 | 84.89 | 26.73 |
| 2820 | 3760 | 3290.0 | 2.970 | 0.0625 | 6.25 | 43.288 | 7.178 | 91.14 | 15.11 |
| 3760 | 4700 | 4230.0 | 2.965 | 0.0624 | 6.24 | 46.253 | 4.208 | 97.38 | 8.86 |
| 4700 | 5640 | 5170.0 | 615 | 0.0129 | 1.29 | 46.868 | 1.243 | 98.68 | 2.62 |
| 5640 | 6580 | 6110.0 | 109 | 0.0023 | 0.23 | 46.977 | 628 | 98.91 | 1.32 |
| 6580 | 7520 | 7050.0 | 120 | 0.0025 | 0.25 | 47.097 | 519 | 99.16 | 1.09 |
| 7520 | 8460 | 7990.0 | 78 | 0.0016 | 0.16 | 47.175 | 399 | 99.32 | 0.84 |
| 8460 | 9400 | 8930.0 | 61 | 0.0013 | 0.13 | 47.236 | 321 | 99.45 | 0.68 |
| 9400 | 10340 | 9870.0 | 76 | 0.0016 | 0.16 | 47.312 | 260 | 99.61 | 0.55 |
| 10340 | 11280 | 10810.0 | 49 | 0.0010 | 0.10 | 47.361 | 184 | 99.72 | 0.39 |
| 11280 | 12220 | 11750.0 | 68 | 0.0014 | 0.14 | 47.429 | 135 | 99.86 | 0.28 |
| 12220 | 13160 | 12690.0 | 42 | 0.0009 | 0.09 | 47.471 | 67 | 99.95 | 0.14 |
| 13160 | 14100 | 13630.0 | 18 | 0.0004 | 0.04 | 47.489 | 25 | 99.99 | 0.05 |
| 14100 | 15040 | 14570.0 | 4 | 0.0001 | 0.01 | 47.493 | 7 | 99.99 | 0.01 |
| 15040 | 15980 | 15510.0 | 3 | 0.0001 | 0.01 | 47.496 | 3 | 100.00 | 0.01 |
| TOTAL | 47.496 | 1.0000 | 100.00 |
Fuente: Oil, Gas & Other Regulated Wells: Beginning 1860.
Interpretación: el intervalo de profundidad con mayor concentración de pozos es [0 – 940) pies, con 18.051 pozos (38.01% de los 47.496 registros válidos). Hasta los 1880 pies 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="Profundidad medida (ft)", 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="Profundidad medida (ft)", 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="Profundidad medida (ft)", 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="Profundidad medida (ft)", 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 profundidad medida")
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("Profundidad medida (ft)", 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="Profundidad medida (ft)", 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))
Profundidad medida 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"="Profundidad medida (ft)",
"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 Profundidad medida (ft), 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, ' pies',
' | <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] |
|---|---|---|---|---|---|---|---|---|---|---|
| Profundidad medida (ft) | [0; 15921] | 1449.79 | 1255.00 | 470.00 | 2467071.17 | 1570.69 | 108.34 | 2.2581 | 9.8647 | 1.015 [4869; 15921] |
Registros válidos (N): 47.496 | Clases (k): 17 | Amplitud: 940 pies | Q1: 0 | Q3: 1947.
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.
Las profundidades medidas de los pozos regulados de Nueva York fluctúan entre 0 y 15921 pies y giran en torno a 1255.00 pies (mediana), con una media de 1449.79 pies y una desviación estándar de 1570.69, lo que da un conjunto de datos heterogéneo (C.V. = 108.34%). La distribución es asimétrica positiva (cola hacia las profundidades altas) (As = 2.2581) y leptocúrtica (más concentrada que la normal) (K = 9.8647), y presenta 1.015 valores atípicos (entre 4869 y 15921 pies). El intervalo con más pozos es [0 – 940) pies, con 38.01% de los registros válidos, lo que muestra que la actividad de perforación se concentra en determinadas franjas de profundidad. Cabe señalar que 14.679 pozos (30.91%) registran profundidad 0 ft 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