2. TABLA DE DISTRIBUCIÓN DE CANTIDAD POR
STURGES
longitud_pozos <- as.numeric(datos$Longitude.of.well.pad)
longitud_pozos <- na.omit(longitud_pozos)
n <- length(longitud_pozos)
#Sturges
k <- floor(1 + 3.322 * log10(n))
k
## [1] 14
#minimo
minimo <- min(longitud_pozos)
minimo
## [1] -108.4039
#maximo
maximo <- max(longitud_pozos)
maximo
## [1] -103.0692
#rango
R <- maximo - minimo
R
## [1] 5.334686
#amplitud
A <- R / k
A
## [1] 0.381049
Li_s <- round(seq(from = minimo, to = maximo - A, by = A),3)
Ls_s <- round(seq(from = minimo + A, to = maximo, by = A),3)
MC_s <- round((Li_s + Ls_s) / 2, 2)
ni_s <- numeric(length(Li_s))
for (i in 1:length(Li_s)) {
ni_s[i] <- sum(longitud_pozos >= Li_s[i] & longitud_pozos < Ls_s[i])
}
ni_s[length(Li_s)] <- sum(longitud_pozos >= Li_s[length(Li_s)] & longitud_pozos <= maximo)
TDF_Sturges <- data.frame(Li=Li_s, Ls=Ls_s, MC=MC_s, ni=ni_s, hi=round((ni_s/n)*100, 2))
TDF_Sturges_P <- rbind(TDF_Sturges, data.frame(Li="TOTAL", Ls="", MC="", ni=sum(ni_s), hi=100))
TDF_Sturges_P %>%
gt() %>%
tab_header(title = md("Tabla N°1. Tabla de distribucion de cantidad de
longitud de los pozos de gas natural en Nuevo México")) %>%
tab_style(
style = list(cell_fill(color = "lightgray"), cell_text(weight = "bold")),
locations = list(
cells_body(rows = Li == "TOTAL"),
cells_title(groups = "title")
)
) %>%
tab_options(
table.width = pct(90),
heading.title.font.weight = "bold",
column_labels.font.weight = "bold"
) %>%
tab_source_note(
source_note = md("**Tabla 1 de 4**")
)
| Tabla N°1. Tabla de distribucion de cantidad de
longitud de los pozos de gas natural en Nuevo México |
| Li |
Ls |
MC |
ni |
hi |
| -108.404 |
-108.023 |
-108.21 |
1470 |
11.70 |
| -108.023 |
-107.642 |
-107.83 |
3057 |
24.34 |
| -107.642 |
-107.261 |
-107.45 |
3247 |
25.85 |
| -107.261 |
-106.88 |
-107.07 |
855 |
6.81 |
| -106.88 |
-106.499 |
-106.69 |
0 |
0.00 |
| -106.499 |
-106.118 |
-106.31 |
0 |
0.00 |
| -106.118 |
-105.737 |
-105.93 |
0 |
0.00 |
| -105.737 |
-105.355 |
-105.55 |
0 |
0.00 |
| -105.355 |
-104.974 |
-105.16 |
207 |
1.65 |
| -104.974 |
-104.593 |
-104.78 |
600 |
4.78 |
| -104.593 |
-104.212 |
-104.4 |
1193 |
9.50 |
| -104.212 |
-103.831 |
-104.02 |
828 |
6.59 |
| -103.831 |
-103.45 |
-103.64 |
353 |
2.81 |
| -103.45 |
-103.069 |
-103.26 |
751 |
5.98 |
| TOTAL |
|
|
12561 |
100.00 |
| Tabla 1 de 4 |
#GRAFICA 1
cortes_histograma_lon <- c(Li_s, maximo)
hist(longitud_pozos,
breaks = cortes_histograma_lon,
right = FALSE,
col = "darkgrey",
xaxt = "n",
xlab = "Longitud",
ylab = "Cantidad",
main = "Grafica N°1: Distribución de cantidad de la longitud en pozos de
gas natural en Nuevo México")
axis(1, at = cortes_histograma_lon, labels = round(cortes_histograma_lon, 3), las = 2)
box(which = "outer", col = "black")

3. TABLA DE DISTRIBUCIÓN DE CANTIDAD
SIMPLIFICADA
Debido a que la tabla y la grafica presentan
valores con decimales complejos vamos a agruparla
h_f <- hist(longitud_pozos, plot = FALSE)
lis <- h_f$breaks[1:(length(h_f$breaks)-1)]
lss <- h_f$breaks[2:length(h_f$breaks)]
MC_f <- h_f$mids
ni_f <- h_f$counts
hi_f <- (ni_f / sum(ni_f)) * 100
Niasc <- cumsum(ni_f); Nidsc <- rev(cumsum(rev(ni_f)))
Hiasc <- round(cumsum(hi_f), 2); Hidsc <- round(rev(cumsum(rev(hi_f))), 2)
TDF_Simp <- data.frame(Li=lis, Ls=lss, MC=MC_f, ni=ni_f, hi=round(hi_f, 2),
Niasc, Nidsc, Hiasc, Hidsc)
TDF_Simp_P <- rbind(TDF_Simp, data.frame(Li="TOTAL", Ls=" ", MC=" ", ni=sum(ni_f), hi=100,
Niasc=" ", Nidsc=" ", Hiasc=" ", Hidsc=" "))
TDF_Simp_P %>%
gt() %>%
tab_header(title = md("TABLA N°2: Tabla de distribución de cantidad de la longitud en pozos
de gas natural en Nuevo México")) %>%
tab_style(
style = list(cell_fill(color = "lightgray"), cell_text(weight = "bold")),
locations = list(
cells_body(rows = Li == "TOTAL"),
cells_title(groups = "title")
)
) %>%
tab_options(
table.width = pct(95),
heading.title.font.weight = "bold",
column_labels.font.weight = "bold"
)%>%
tab_source_note(
source_note = md("**Tabla 2 de 4**"))
| TABLA N°2: Tabla de distribución de cantidad de la longitud en pozos
de gas natural en Nuevo México |
| Li |
Ls |
MC |
ni |
hi |
Niasc |
Nidsc |
Hiasc |
Hidsc |
| -108.5 |
-108 |
-108.25 |
1630 |
12.98 |
1630 |
12561 |
12.98 |
100 |
| -108 |
-107.5 |
-107.75 |
4010 |
31.92 |
5640 |
10931 |
44.9 |
87.02 |
| -107.5 |
-107 |
-107.25 |
2972 |
23.66 |
8612 |
6921 |
68.56 |
55.1 |
| -107 |
-106.5 |
-106.75 |
17 |
0.14 |
8629 |
3949 |
68.7 |
31.44 |
| -106.5 |
-106 |
-106.25 |
0 |
0.00 |
8629 |
3932 |
68.7 |
31.3 |
| -106 |
-105.5 |
-105.75 |
0 |
0.00 |
8629 |
3932 |
68.7 |
31.3 |
| -105.5 |
-105 |
-105.25 |
171 |
1.36 |
8800 |
3932 |
70.06 |
31.3 |
| -105 |
-104.5 |
-104.75 |
804 |
6.40 |
9604 |
3761 |
76.46 |
29.94 |
| -104.5 |
-104 |
-104.25 |
1690 |
13.45 |
11294 |
2957 |
89.91 |
23.54 |
| -104 |
-103.5 |
-103.75 |
453 |
3.61 |
11747 |
1267 |
93.52 |
10.09 |
| -103.5 |
-103 |
-103.25 |
814 |
6.48 |
12561 |
814 |
100 |
6.48 |
| TOTAL |
|
|
12561 |
100.00 |
|
|
|
|
| Tabla 2 de 4 |
4. GRÁFICAS DE DISTRIBUCIÓN
par(oma = c(1, 1, 1, 1))
par(mfrow=c(1,1))
par(mar = c(6, 5, 4, 2) + 0.1)
colores <- gray.colors(length(ni_f), start = 0.3, end = 0.9)
# VECTORES PARA LOS POLÍGONOS DE LA LONGITUD
h_datos23_lon <- hist(longitud_pozos, plot = FALSE)
x_cant_lon <- h_datos23_lon$mids
y_cant_lon <- h_datos23_lon$counts
h_datos45_lon <- hist(longitud_pozos, plot = FALSE)
h_datos45_lon$counts <- (h_datos45_lon$counts / sum(h_datos45_lon$counts)) * 100
x_porc_lon <- h_datos45_lon$mids
y_porc_lon <- h_datos45_lon$counts
#GRAFICA 1
hist(longitud_pozos, col = colores, xlab = "Longitud", ylab = "Cantidad",
main = "Grafica N°2: Distribución de cantidad de la longitud en pozos
de gas natural en Nuevo México")
lines(x_cant_lon, y_cant_lon, type = "b", col = "red", pch = 19, lwd = 2)
box(which = "outer", col = "black")

#GRAFICA 2
hist(longitud_pozos, col = colores, xlab = "Longitud", ylab = "Cantidad",
ylim = c(0, n),
main = "Grafica N°3: Distribución de cantidad de la longitud en pozos
de gas natural en Nuevo México")
lines(x_cant_lon, y_cant_lon, type = "b", col = "red", pch = 19, lwd = 2)
box(which = "outer", col = "black")

#GRAFICA 3
h_porcentaje <- hist(longitud_pozos, plot = FALSE)
h_porcentaje$counts <- (h_porcentaje$counts / sum(h_porcentaje$counts)) * 100
plot(h_porcentaje, col = colores, xlab = "Longitud", ylab = "Porcentaje (%)",
main = "Grafica N°4: Distribución de cantidad en porcentaje
de la longitud en pozos de gas natural en Nuevo México")
lines(x_porc_lon, y_porc_lon, type = "b", col = "red", pch = 19, lwd = 2)
box(which = "outer", col = "black")

#GRAFICA 4
plot(h_porcentaje, col = colores, xlab = "Longitud", ylab = "Porcentaje (%)",
ylim = c(0, 100),
main = "Grafica N°5: Distribución de cantidad en porcentaje
de la longitud en pozos de gas natural en Nuevo México")
lines(x_porc_lon, y_porc_lon, type = "b", col = "red", pch = 19, lwd = 2)
box(which = "outer", col = "black")

#GRAFICA 5
plot(lss, Nidsc, type="b", col="blue", pch=19, bg="white", xlab="Longitud", ylab="Cant. Acumulada",
main="Grafica N°6: Ojivas combinadas de cantidad acumulada de la
longitud en pozos de gas natural en Nuevo México")
lines(lis, Niasc, col="black", type="b", pch=1)
legend("right", legend=c("Descendente", "Ascendente"), col=c("blue", "black"), pch=c(19, 19), pt.bg="white", bty="n")
box(which = "outer", col = "black")

#GRAFICA 6
plot(lss, Hidsc, type="b", col="blue", pch=19, bg="white", ylim=c(0, 100),
xlab="Longitud", ylab="Porcentaje Acumulado",
main="Grafica N°7: Ojivas combinadas de porcentaje acumulado de la
longitud en pozos de gas natural en Nuevo México")
lines(lis, Hiasc, col="black", type="b", pch=18)
legend("right", legend=c("Descendente", "Ascendente"), col=c("blue", "black"), pch=c(19, 19), pt.bg="white", bty="n")
box(which = "outer", col = "black")

#GRAFICA 7
boxplot(longitud_pozos, horizontal = TRUE, col = "skyblue", xlab = "Longitud",
main = "Grafica N°8: Distribución de cantidad de la longitud")
box(which = "outer", col = "black")

summary(longitud_pozos)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -108.4 -107.8 -107.4 -106.6 -104.6 -103.1
#GRAFICA N°9: SUPERPOSICIÓN DE BOXPLOT SOBRE HISTOGRAMA (AGREGADO)
hist(longitud_pozos, prob = TRUE,
col = colores, xlab = "Longitud", ylab = "Densidad",
main = "Grafica N°9: Grafica N°9: Distribución de cantidad en porcentaje
de la longitud en pozos de gas natural en Nuevo México")
par(new = TRUE)
boxplot(longitud_pozos, horizontal = TRUE, axes = FALSE,
col = rgb(0, 0.8, 1, alpha = 0.5))
box(which = "outer", col = "black")

5. INDICADORES ESTADÍSTICOS Y OUTLIERS
TablaInd <- data.frame(Variable="Longitud", min=min(longitud_pozos), max=max(longitud_pozos),
x=round(mean(longitud_pozos),2), Me=median(longitud_pozos),
sd=round(sd(longitud_pozos),2), Cv=round(abs((sd(longitud_pozos)/mean(longitud_pozos))*100),2),
As=round(skewness(longitud_pozos),2), K=round(kurtosis(longitud_pozos),2))
#media
media_val <- mean(longitud_pozos)
media_val
## [1] -106.566
#desviacion estandar
desv_val <- sd(longitud_pozos)
desv_val
## [1] 1.69539
#minimo
min_val <- min(longitud_pozos)
min_val
## [1] -108.4039
#maximo
max_val <- max(longitud_pozos)
max_val
## [1] -103.0692
#coeficiente de variacion o desviacion relativa
cv_analisis <- abs(desv_val / media_val) * 100
cv_analisis
## [1] 1.590929
tipo_datos <- if(cv_analisis > 30) "heterogeneos" else "homogeneos"
#TABLA DE INDICADORES
TablaInd %>%
gt() %>%
tab_header(title = md("Tabla N.3: Indicadores estadisticos de la variable
longitud en pozos de gas natural en Nuevo México")) %>%
tab_style(
style = list(cell_fill(color = "lightgray"), cell_text(weight = "bold")),
locations = cells_title(groups = "title")
) %>%
tab_options(
column_labels.font.weight = "bold" # Subtítulos de columnas en negrita
) %>%
tab_source_note(
source_note = md("**Tabla 3 de 4**"))
| Tabla N.3: Indicadores estadisticos de la variable
longitud en pozos de gas natural en Nuevo México |
| Variable |
min |
max |
x |
Me |
sd |
Cv |
As |
K |
| Longitud |
-108.4039 |
-103.0692 |
-106.57 |
-107.434 |
1.7 |
1.59 |
0.84 |
-1.03 |
| Tabla 3 de 4 |
valores_atipicos <- boxplot.stats(longitud_pozos)$out
conteo_atipicos <- length(boxplot.stats(longitud_pozos)$out)
n_atipicos <- length(valores_atipicos)
min_atipico <- if(n_atipicos > 0) min(valores_atipicos) else 0
max_atipico <- if(n_atipicos > 0) max(valores_atipicos) else 0
TablaOutliers <- data.frame(Cantidad = n_atipicos, Mínimo = min_atipico, Máximo = max_atipico)
TablaOutliers %>%
gt() %>%
tab_header(title = md("TABLA N°4: Valores atípicos de la variable Longitud")) %>%
tab_style(
style = list(cell_fill(color = "lightgray"), cell_text(weight = "bold")),
locations = cells_title(groups = "title")
) %>%
tab_options(
column_labels.font.weight = "bold" # Subtítulos de columnas en negrita
) %>%
tab_source_note(
source_note = md("**Tabla 4 de 4**"))
| TABLA N°4: Valores atípicos de la variable Longitud |
| Cantidad |
Mínimo |
Máximo |
| 0 |
0 |
0 |
| Tabla 4 de 4 |
names(which.max(table(longitud_pozos)))
## [1] "-103.2294998"