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 Drilled Depth.")
Minimo_real <- min(Variable)
Maximo_real <- max(Variable)
cat("Variable analizada: Drilled Depth, ft | Unidad: pies (ft)\n")
## Variable analizada: Drilled 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.639
cat("Mínimo:", fmt_num(Minimo_real, 0), "| Máximo:", fmt_num(Maximo_real, 0), "pies\n")
## Mínimo: 0 | Máximo: 15795 pies
Escala: la profundidad perforada es cuantitativa continua de escala de razón (el 0 ft indica ausencia de profundidad). El conjunto incluye 14.639 pozos con valor 0 ft (30.82%), que se mantienen en el análisis.
| VARIABLE | TIPO | ESCALA DE MEDICIÓN | UNIDAD DE MEDIDA | UNIDAD DE ANÁLISIS | REGISTROS VÁLIDOS (N) |
|---|---|---|---|---|---|
| DRILLED DEPTH (Profundidad perforada, ft) | Cuantitativa continua | Razón | Pies (ft) | Pozo regulado | 47.496 |
cortes_int <- pretty(c(Minimo_real, Maximo_real), n=15) # límites redondos calculados por R
if (max(cortes_int) < Maximo_real) cortes_int <- c(cortes_int, max(cortes_int) + (cortes_int[2] - cortes_int[1]))
K_real <- length(cortes_int) - 1
Amplitud_int <- cortes_int[2] - 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("Número de clases (k):", K_real, "\n")
## Número de clases (k): 16
cat("Amplitud de clase:", Amplitud_int, "pies\n")
## Amplitud de clase: 1000 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, 1,
"Distribución de frecuencias de los pozos regulados según la profundidad perforada (ft), 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 | 1000 | 500.0 | 18.674 | 0.3932 | 39.32 | 18.674 | 47.496 | 39.32 | 100.00 |
| 1000 | 2000 | 1500.0 | 17.683 | 0.3723 | 37.23 | 36.357 | 28.822 | 76.55 | 60.68 |
| 2000 | 3000 | 2500.0 | 4.717 | 0.0993 | 9.93 | 41.074 | 11.139 | 86.48 | 23.45 |
| 3000 | 4000 | 3500.0 | 3.393 | 0.0714 | 7.14 | 44.467 | 6.422 | 93.62 | 13.52 |
| 4000 | 5000 | 4500.0 | 2.465 | 0.0519 | 5.19 | 46.932 | 3.029 | 98.81 | 6.38 |
| 5000 | 6000 | 5500.0 | 265 | 0.0056 | 0.56 | 47.197 | 564 | 99.37 | 1.19 |
| 6000 | 7000 | 6500.0 | 97 | 0.0020 | 0.20 | 47.294 | 299 | 99.57 | 0.63 |
| 7000 | 8000 | 7500.0 | 85 | 0.0018 | 0.18 | 47.379 | 202 | 99.75 | 0.43 |
| 8000 | 9000 | 8500.0 | 29 | 0.0006 | 0.06 | 47.408 | 117 | 99.81 | 0.25 |
| 9000 | 10000 | 9500.0 | 40 | 0.0008 | 0.08 | 47.448 | 88 | 99.90 | 0.19 |
| 10000 | 11000 | 10500.0 | 27 | 0.0006 | 0.06 | 47.475 | 48 | 99.96 | 0.10 |
| 11000 | 12000 | 11500.0 | 17 | 0.0004 | 0.04 | 47.492 | 21 | 99.99 | 0.04 |
| 12000 | 13000 | 12500.0 | 2 | 0.0000 | 0.00 | 47.494 | 4 | 100.00 | 0.01 |
| 13000 | 14000 | 13500.0 | 0 | 0.0000 | 0.00 | 47.494 | 2 | 100.00 | 0.00 |
| 14000 | 15000 | 14500.0 | 1 | 0.0000 | 0.00 | 47.495 | 2 | 100.00 | 0.00 |
| 15000 | 16000 | 15500.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 profundidad con mayor concentración de pozos es [0 – 1000) pies, con 18.674 pozos (39.32% de los 47.496 registros válidos). Hasta los 2000 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 perforada (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 perforada (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 perforada (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 perforada (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 perforada")
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 perforada (ft)", side=1, line=5.5)
ojiva_ni <- data.frame(
x = c(TDF_Enteros$Ls, TDF_Enteros$Li),
y = c(TDF_Enteros$Ni_asc, TDF_Enteros$Ni_desc),
tipo = rep(c("Ascendente", "Descendente"), each=K_real)
)
ggplot2::ggplot(ojiva_ni, 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=fmt_entero, limits=c(0, N * 1.05),
expand=ggplot2::expansion(mult=c(0, 0))) +
ggplot2::labs(title="Gráfica N° 6: Ojivas de frecuencia absoluta acumulada (Nᵢ)",
x="Profundidad perforada (ft)", y="Frecuencia absoluta acumulada (Nᵢ)", 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))
ojiva_hi <- 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_hi, 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° 7: Ojivas de frecuencia relativa acumulada (Hᵢ)",
x="Profundidad perforada (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 perforada 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 perforada (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° 2: Indicadores estadísticos de Profundidad perforada (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 perforada (ft) | [0; 15795] | 1397.82 | 1251.00 | 500.00 | 1952986.86 | 1397.49 | 99.98 | 1.4597 | 4.0807 | 764 [4826; 15795] |
Registros válidos (N): 47.496 | Clases (k): 16 | Amplitud: 1000 pies | Q1: 0 | Q3: 1930.
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 profundidad perforada fluctúan entre 0 y 15795 pies y giran en torno a 1251.00 pies (mediana), con una desviación estándar de 1397.49, con valores atípicos (764 en total: entre 4826 y 15795 pies), siendo un conjunto de datos heterogéneo (C.V. = 99.98%), cuyos valores se agrupan fuertemente en la parte baja de la profundidad perforada (99.10% de los pozos). Por lo anterior, el comportamiento es beneficioso, ya que refleja una concentración de los valores en la parte baja de la profundidad perforada.
Autor: Estalin Echeverría | Grupo 5 | Análisis Estadístico — Oil, Gas & Other Regulated Wells - NY State