setwd("/cloud/project/")
datos<-read.csv("DerramesEEUU.csv", header = TRUE, sep=";" , dec=",")
str(datos)
## 'data.frame': 2760 obs. of 59 variables:
## $ NumeroInforme : int 20100064 20100054 20100092 20100098 20100101 20100102 20100113 20100120 20100039 20100150 ...
## $ NumeroComplementario : int 15072 15114 15120 15127 15130 15132 15146 15162 15197 15205 ...
## $ DiaAccidente : int 8 25 10 28 27 29 11 23 15 11 ...
## $ MesAccidente : int 4 3 5 4 5 5 6 5 3 1 ...
## $ AnioAccidente : int 2010 2010 2010 2010 2010 2010 2010 2010 2010 2010 ...
## $ HoraAccidente : int 6 13 6 24 3 14 7 6 15 2 ...
## $ AmPmAccidente : chr "a. m." "p. m." "a. m." "p. m." ...
## $ IDOperador : int 31684 18779 30829 12105 20160 30003 1248 300 18718 32296 ...
## $ NombreOperador : chr "CONOCOPHILLIPS" "SUNOCO, INC (R&M)" "TEPPCO CRUDE PIPELINE, LLC" "MAGELLAN AMMONIA PIPELINE, L.P." ...
## $ NombreOleoductoInstalacion : chr "GD-03, GOLD LINE" "PHILADELPHIA REFINERY - WEST YARD" "HOBBS TO MIDLAND" "WHITING TO EARLY SEGMENT" ...
## $ UbicacionOleoducto : chr "ONSHORE" "ONSHORE" "ONSHORE" "ONSHORE" ...
## $ TipoOleoducto : chr "ABOVEGROUND" "ABOVEGROUND" "UNDERGROUND" "UNDERGROUND" ...
## $ TipoLiquido : chr "REFINED AND/OR PETROLEUM PRODUCT (NON-HVL), LIQUID" "REFINED AND/OR PETROLEUM PRODUCT (NON-HVL), LIQUID" "CRUDE OIL" "HVL OR OTHER FLAMMABLE OR TOXIC FLUID, GAS" ...
## $ SubtipoLiquido : chr "GASOLINE (NON-ETHANOL)" "OTHER" "-" "ANHYDROUS AMMONIA" ...
## $ NombreLiquido : chr "-" "VACUUM GAS OIL (VGO)" "-" "-" ...
## $ CiudadAccidente : chr "GREEN RIDGE" "PHILADELPHIA" "HOBBS" "SCHALLER" ...
## $ CondadoAccidente : chr "PETTIS" "PHILADELPHIA" "LEA" "IDA" ...
## $ EstadoAccidente : chr "MO" "PA" "NM" "IA" ...
## $ LatitudAccidente : num 38.6 39.9 32.6 42.5 30.2 ...
## $ LongitudAccidente : num -93.4 -75.2 -103.1 -95.3 -91.2 ...
## $ CategoriaCausa : chr "NATURAL FORCE DAMAGE" "MATERIAL/WELD/EQUIP FAILURE" "CORROSION" "MATERIAL/WELD/EQUIP FAILURE" ...
## $ SubcategoriaCausa : chr "TEMPERATURE" "NON-THREADED CONNECTION FAILURE" "EXTERNAL" "CONSTRUCTION, INSTALLATION OR FABRICATION-RELATED" ...
## $ LiberacionInvoluntariaBarriles : num 0.24 1700 2 0.36 1.31 ...
## $ LiberacionIntencionalBarriles : chr "0" "0" "-" "0.05" ...
## $ RecuperacionLiquidoBarriles : num 0.07 1699 0.48 0 0 ...
## $ PerdidaNetaBarriles : num 0.17 1 1.52 0.36 1.31 ...
## $ IgnicionLiquido : chr "NO" "NO" "NO" "NO" ...
## $ ExplosionLiquido : chr "NO" "NO" "NO" "NO" ...
## $ CierreOleoducto : chr "YES" "YES" "NO" "NO" ...
## $ DiaCierre : chr "8" "25" "-" "-" ...
## $ MesCierre : chr "4" "3" "-" "-" ...
## $ AnioCierre : chr "2010" "2010" "-" "-" ...
## $ HoraCierre : chr "6" "18" "-" "-" ...
## $ AmPmCierre : chr "a. m." "p. m." "-" "-" ...
## $ DiaReinicio : chr "9" "28" "-" "-" ...
## $ MesReinicio : chr "4" "3" "-" "-" ...
## $ AnioReinicio : chr "2010" "2010" "-" "-" ...
## $ HoraReinicio : chr "10" "16" "-" "-" ...
## $ AmPmReinicio : chr "a. m." "p. m." "-" "-" ...
## $ EvacuacionesPublicas : chr "-" "0" "-" "-" ...
## $ LesionesEmpleadosOperador : chr "-" "-" "-" "-" ...
## $ LesionesContratistasOperador : chr "-" "-" "-" "-" ...
## $ LesionesRescatistasEmergencia : chr "-" "-" "-" "-" ...
## $ OtrasLesiones : chr "-" "-" "-" "-" ...
## $ LesionesPublico : chr "-" "-" "-" "-" ...
## $ TodasLesiones : chr "-" "-" "-" "-" ...
## $ FallecimientosEmpleadosOperador : chr "-" "-" "-" "-" ...
## $ FallecimientosContratistasOperador : chr "-" "-" "-" "-" ...
## $ FallecimientosRescatistasEmergencia : chr "-" "-" "-" "-" ...
## $ OtrosFallecimientos : chr "-" "-" "-" "-" ...
## $ FallecimientosPublico : chr "-" "-" "-" "-" ...
## $ TodosFallecimientos : chr "-" "-" "-" "-" ...
## $ CostosDaniosPropiedad : chr "0" "0" "30000" "12000" ...
## $ CostosMercanciaPerdidas : chr "27" "0" "100" "30" ...
## $ CostosDaniosPropiedadesPublicasPrivadas: chr "0" "0" "1000" "5000" ...
## $ CostosRespuestaEmergencia : chr "0" "0" "-" "0" ...
## $ CostosRemediacionAmbiental : chr "0" "100000" "20000" "15000" ...
## $ OtrosCostos : chr "0" "0" "-" "0" ...
## $ TodosCostos : int 27 100000 51100 32030 5220 150 7500 9965 11497 165593 ...
Latitud <- datos$LatitudAccidente
Latitud <- na.omit(Latitud)
R_Latitud <- max(Latitud) - min(Latitud)
k_Latitud <- floor(1 + (3.3 * log10(length(Latitud))))
A_Latitud <- R_Latitud / k_Latitud
liminf <- seq(from = min(Latitud), by = A_Latitud, length.out = k_Latitud)
limsup <- liminf + A_Latitud
limsup[k_Latitud] <- max(Latitud)
MC <- (liminf + limsup) / 2
ni <- numeric(k_Latitud)
for (i in 1:k_Latitud) {
if (i == k_Latitud) {
ni[i] <- sum(Latitud >= liminf[i] & Latitud <= limsup[i])
} else {
ni[i] <- sum(Latitud >= liminf[i] & Latitud < limsup[i])
}
}
hi <- round((ni / length(Latitud)) * 100, 3)
Niasc <- cumsum(ni)
Nidsc <- rev(cumsum(rev(ni)))
Hiasc <- cumsum(hi)
Hidsc <- rev(cumsum(rev(hi)))
tabla_Latitud <- data.frame(
liminf = round(liminf, 3),
limsup = round(limsup, 3),
MC = round(MC, 3),
ni = ni,
hi_porc = round(hi, 3),
Ni_asc = Niasc,
Ni_dsc = Nidsc,
Hiasc_porc = round(Hiasc, 3),
Hidsc_porc = round(Hidsc, 3)
)
total_ni <- sum(tabla_Latitud$ni)
total_hi <- 100
TDFLatitudCompleto <- rbind(tabla_Latitud, data.frame(
liminf = "TOTAL",
limsup = " ",
MC = " ",
ni = total_ni,
hi_porc = total_hi,
Ni_asc = " ",
Ni_dsc = " ",
Hiasc_porc = " ",
Hidsc_porc = " "
))
library(gt)
tabla_latitud_gt <- TDFLatitudCompleto %>%
gt() %>%
cols_label(
liminf = md("**liminf**"),
limsup = md("**limsup**"),
MC = md("**MC**"),
ni = md("**ni**"),
hi_porc = md("**hi (%)**"),
Ni_asc = md("**Ni ↑**"),
Ni_dsc = md("**Ni ↓**"),
Hiasc_porc = md("**Hi ↑ (%)**"),
Hidsc_porc = md("**Hi ↓ (%)**")
) %>%
tab_header(
title = md("**Tabla N° 1**"),
subtitle = md("**Distribución de frecuencias de la Latitud de accidentes ocurridos en EE.UU (2010-2017)**")
) %>%
tab_source_note(
source_note = md("Autor: Grupo 1")
) %>%
tab_options(
table.background.color = "white",
row.striping.background_color = "white",
table.border.top.color = "black",
table.border.bottom.color = "black",
table.border.top.style = "solid",
table.border.bottom.style = "solid",
column_labels.border.top.color = "black",
column_labels.border.bottom.color = "black",
column_labels.border.bottom.width = px(2),
heading.border.bottom.color = "black",
heading.border.bottom.width = px(2),
table_body.hlines.color = "gray",
table_body.border.bottom.color = "black"
) %>%
tab_style(
style = cell_text(weight = "bold"),
locations = cells_body(
rows = liminf == "TOTAL"
)
)
tabla_latitud_gt
| Tabla N° 1 | ||||||||
| Distribución de frecuencias de la Latitud de accidentes ocurridos en EE.UU (2010-2017) | ||||||||
| liminf | limsup | MC | ni | hi (%) | Ni ↑ | Ni ↓ | Hi ↑ (%) | Hi ↓ (%) |
|---|---|---|---|---|---|---|---|---|
| 21.304 | 25.384 | 23.344 | 3 | 0.109 | 3 | 2760 | 0.109 | 100.001 |
| 25.384 | 29.464 | 27.424 | 183 | 6.630 | 186 | 2757 | 6.739 | 99.892 |
| 29.464 | 33.544 | 31.504 | 980 | 35.507 | 1166 | 2574 | 42.246 | 93.262 |
| 33.544 | 37.623 | 35.583 | 557 | 20.181 | 1723 | 1594 | 62.427 | 57.755 |
| 37.623 | 41.703 | 39.663 | 675 | 24.457 | 2398 | 1037 | 86.884 | 37.574 |
| 41.703 | 45.783 | 43.743 | 218 | 7.899 | 2616 | 362 | 94.783 | 13.117 |
| 45.783 | 49.863 | 47.823 | 133 | 4.819 | 2749 | 144 | 99.602 | 5.218 |
| 49.863 | 53.942 | 51.902 | 0 | 0.000 | 2749 | 11 | 99.602 | 0.399 |
| 53.942 | 58.022 | 55.982 | 0 | 0.000 | 2749 | 11 | 99.602 | 0.399 |
| 58.022 | 62.102 | 60.062 | 0 | 0.000 | 2749 | 11 | 99.602 | 0.399 |
| 62.102 | 66.182 | 64.142 | 3 | 0.109 | 2752 | 11 | 99.711 | 0.399 |
| 66.182 | 70.261 | 68.221 | 8 | 0.290 | 2760 | 8 | 100.001 | 0.29 |
| TOTAL | 2760 | 100.000 | ||||||
| Autor: Grupo 1 | ||||||||
histoLatitud <- hist(Latitud,
main ="Distribución de frecuencias de la Latitud de
accidentes en oleoductos ocurridos en EE.UU.",
xlab = "Latitud (°)",
ylab = "Frecuencia",
col = "pink",
border = "black")
Limites<-histoLatitud$breaks
Limites
## [1] 20 25 30 35 40 45 50 55 60 65 70 75
LimInf <- Limites[1:(length(Limites)-1)]
LimSup <- Limites[2:length(Limites)]
MC <- (LimInf + LimSup)/2
ni<-histoLatitud$counts
hi<-(ni/sum(ni)*100)
Niasc <- cumsum(ni)
Nidsc <- rev(cumsum(rev(ni)))
Hiasc <- round(cumsum(hi), 3)
Hidsc <- round(rev(cumsum(rev(hi))), 3)
TDFLatitudR <- data.frame(LimInf, LimSup, MC, ni,
hi = round(hi,3) ,
Niasc, Nidsc, Hiasc, Hidsc)
total_ni <- sum(ni)
total_hi <- 100
TDFLatitudRFinal<-rbind(TDFLatitudR,
data.frame(LimInf="Total",
LimSup=" ",
MC=" ",
ni=total_ni,
hi=total_hi,
Niasc=" ",
Nidsc=" ",
Hiasc=" ",
Hidsc=" "))
library(gt)
tabla_LatitudR_gt <- TDFLatitudRFinal %>%
gt() %>%
cols_label(
LimInf = md("**LimInf**"),
LimSup = md("**LimSup**"),
MC = md("**MC**"),
ni = md("**ni**"),
hi = md("**hi (%)**"),
Niasc = md("**Ni ↑**"),
Nidsc = md("**Ni ↓**"),
Hiasc = md("**Hi ↑ (%)**"),
Hidsc = md("**Hi ↓ (%)**")
) %>%
tab_header(
title = md("**Tabla N° 2**"),
subtitle = md("**Distribución de frecuencias de la Latitud de accidentes ocurridos en EE.UU (2010-2017)**")
) %>%
tab_source_note(
source_note = md("Autor: Grupo 1")
) %>%
tab_options(
table.background.color = "white",
row.striping.background_color = "white",
table.border.top.color = "black",
table.border.bottom.color = "black",
table.border.top.style = "solid",
table.border.bottom.style = "solid",
column_labels.border.top.color = "black",
column_labels.border.bottom.color = "black",
column_labels.border.bottom.width = px(2),
heading.border.bottom.color = "black",
heading.border.bottom.width = px(2),
table_body.hlines.color = "gray",
table_body.border.bottom.color = "black"
) %>%
tab_style(
style = cell_text(weight = "bold"),
locations = cells_body(
rows = LimInf == "Total"
)
)
tabla_LatitudR_gt
| Tabla N° 2 | ||||||||
| Distribución de frecuencias de la Latitud de accidentes ocurridos en EE.UU (2010-2017) | ||||||||
| LimInf | LimSup | MC | ni | hi (%) | Ni ↑ | Ni ↓ | Hi ↑ (%) | Hi ↓ (%) |
|---|---|---|---|---|---|---|---|---|
| 20 | 25 | 22.5 | 3 | 0.109 | 3 | 2760 | 0.109 | 100 |
| 25 | 30 | 27.5 | 462 | 16.739 | 465 | 2757 | 16.848 | 99.891 |
| 30 | 35 | 32.5 | 908 | 32.899 | 1373 | 2295 | 49.746 | 83.152 |
| 35 | 40 | 37.5 | 670 | 24.275 | 2043 | 1387 | 74.022 | 50.254 |
| 40 | 45 | 42.5 | 552 | 20.000 | 2595 | 717 | 94.022 | 25.978 |
| 45 | 50 | 47.5 | 154 | 5.580 | 2749 | 165 | 99.601 | 5.978 |
| 50 | 55 | 52.5 | 0 | 0.000 | 2749 | 11 | 99.601 | 0.399 |
| 55 | 60 | 57.5 | 0 | 0.000 | 2749 | 11 | 99.601 | 0.399 |
| 60 | 65 | 62.5 | 2 | 0.072 | 2751 | 11 | 99.674 | 0.399 |
| 65 | 70 | 67.5 | 4 | 0.145 | 2755 | 9 | 99.819 | 0.326 |
| 70 | 75 | 72.5 | 5 | 0.181 | 2760 | 5 | 100 | 0.181 |
| Total | 2760 | 100.000 | ||||||
| Autor: Grupo 1 | ||||||||
A continuación, las gráficas de histogramas se presentan con escalas
local y global: la escala local ajusta el eje Y al valor máximo de la
categoría más alta, mientras que la escala global fija el eje Y a un
límite total, mostrando cada categoría en relación al conjunto
completo.
hist(Latitud,main="Gráfica N°1: Distribución de frecuencias de la
Latitud de accidentes en oleoductos ocurridos en EE.UU.",
ylab="Cantidad",
xlab="Latitud (°)",
las = 1,
col="mistyrose")
hist(Latitud,main="Gráfica N°2: Distribución de frecuencias de la
Latitud de accidentes en oleoductos ocurridos en EE.UU.",
ylab="Cantidad",
xlab="Latitud (°)",
col="mistyrose2",
las = 1,
ylim = c(0,length(Latitud)))
barplot(hi,space = 0,
main="Gráfica N°3: Distribución porcentual de la
Latitud de accidentes en oleoductos ocurridos en EE.UU.",
col="mistyrose3",
xlab = "Latitud (°)",
ylab = "Porcentaje (%)",
las = 1,
axis.lty = 1.5,
names.arg =TDFLatitudR$MC)
barplot(hi,space = 0,
main="Gráfica N°4: Distribución porcentual de la
Latitud de accidentes en oleoductos ocurridos en EE.UU.",
col="mistyrose4",
xlab = "Latitud (°)",
ylab = "Porcentaje (%)",
names.arg =TDFLatitudR$MC,
las = 1,
axis.lty = 1.5,
ylim = c(0,100))
if(length(TDFLatitudR$LimInf) == length(TDFLatitudR$Nidsc)) {
plot(TDFLatitudR$LimInf, TDFLatitudR$Nidsc,
main = "Gráfica N°5: Ojivas combinadas de la Latitud
de accidentes en oleoductos ocurridos en EE.UU.",
xlab = "Latitud (°)",
ylab = "Cantidad",
las = 1,
col = "skyblue",
type = "b")
# Agrega segunda ojiva solo si longitudes son iguales
if(length(TDFLatitudR$LimSup) == length(TDFLatitudR$Niasc)) {
lines(TDFLatitudR$LimSup, TDFLatitudR$Niasc, col = "pink", type = "b")
}
# Agregar leyenda
legend("right",
legend = c("Ojiva descendente", "Ojiva ascendente"),
col = c("skyblue", "pink"),
pch = 1,
lty = 1,
cex = 0.7)
}
plot(TDFLatitudR$LimInf,TDFLatitudR$Hidsc,
main = "Gráfica N°6: Ojivas combinadas de la Latitud
de accidentes en oleoductos ocurridos en EE.UU.",
xlab = "Latitud (°)",
ylab="Porcentaje (%)",
col="skyblue3",
las = 1,
type = "b")
lines(TDFLatitudR$LimSup,TDFLatitudR$Hiasc,col="pink4",type = "b")
legend("right",legend = c("Ojiva descendente", "Ojiva ascendente"),
col = c("skyblue3", "pink4"),
pch = 1, lty = 1,cex = 0.7)
boxplot(Latitud, horizontal = TRUE, col = "pink3",
main = "Gráfica No.7: Distribución de la Latitud de
accidentes en oleoductos ocurridos en EE.UU.",
xlab = "Latitud (°)",
xaxt = "n")
axis(1, at = pretty(Latitud), labels = format(pretty(Latitud), scientific = FALSE))
mediana <- median(Latitud)
media_aritmetica <- mean(Latitud)
Mo <- "[37.623, 41.703)"
# Cuartiles
ri <- min(Latitud)
rs <- max(Latitud)
summary(Latitud)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 21.30 31.13 35.05 35.85 40.31 70.26
desviacion_estandar <- sd(Latitud)
coeficiente_variabilidad <- (desviacion_estandar / media_aritmetica) * 100
library(e1071)
As <- skewness(Latitud)
curtosis <- kurtosis(Latitud)
library(gt)
Variable <- c("Latitud")
Tabla_indicadores_Latitud <- data.frame(
Variable,
ri = round(ri, 3),
rs = round(rs, 3),
media_aritmetica = round(media_aritmetica, 3),
mediana = round(mediana, 3),
Mo,
S = round(desviacion_estandar, 3),
`Cv (%)` = round(coeficiente_variabilidad, 3),
As = round(As, 3),
K = round(curtosis, 3)
)
colnames(Tabla_indicadores_Latitud) <- c("Variable","Mínimo","Máximo","x","Me","Mo","S","Cv (%)","As","K")
tabla_indicadores_gt <- Tabla_indicadores_Latitud %>%
gt() %>%
tab_header(
title = md("**Tabla N°3**"),
subtitle = md("**Indicadores estadísticos de la variable Latitud de
accidentes ocurridos en EE.UU (2010-2017)**")
) %>%
tab_source_note(
source_note = md("Autor: Grupo 1")
) %>%
cols_align(
align = "center",
columns = everything()
) %>%
tab_options(
table.background.color = "white",
row.striping.background_color = "white",
table.border.top.color = "black",
table.border.bottom.color = "black",
table.border.top.style = "solid",
table.border.bottom.style = "solid",
column_labels.font.weight = "bold",
column_labels.border.top.color = "black",
column_labels.border.bottom.color = "black",
column_labels.border.bottom.width = px(2),
heading.border.bottom.color = "black",
heading.border.bottom.width = px(2),
table_body.hlines.color = "gray",
table_body.border.bottom.color = "black"
)
tabla_indicadores_gt
| Tabla N°3 | |||||||||
| Indicadores estadísticos de la variable Latitud de accidentes ocurridos en EE.UU (2010-2017) | |||||||||
| Variable | Mínimo | Máximo | x | Me | Mo | S | Cv (%) | As | K |
|---|---|---|---|---|---|---|---|---|---|
| Latitud | 21.304 | 70.261 | 35.85 | 35.048 | [37.623, 41.703) | 5.627 | 15.696 | 1.072 | 3.026 |
| Autor: Grupo 1 | |||||||||
outliers <- boxplot.stats(Latitud)$out
num_outliers <- length(outliers)
minimooutliers <- min(outliers)
maximooutliers <- max(outliers)
Tabla_outliers_Latitud <- data.frame(
Outliers = num_outliers,
Mínimo = minimooutliers,
Máximo = maximooutliers
)
library(gt)
Tabla_outliers_Latitud %>%
gt() %>%
tab_header(
title = md("**Tabla N°4**"),
subtitle = md("**Valores atípicos de la variable Latitud
de accidentes ocurridos en EE.UU (2010-2017)**")
) %>%
cols_align(
align = "center",
columns = everything()
) %>%
tab_options(
table.border.top.color = "black",
table.border.bottom.color = "black",
table.border.top.style = "solid",
table.border.bottom.style = "solid",
column_labels.font.weight = "bold",
column_labels.border.top.color = "black",
column_labels.border.bottom.color = "black",
column_labels.border.bottom.width = px(2),
heading.border.bottom.color = "black",
heading.border.bottom.width = px(2),
table_body.hlines.color = "grey",
table_body.border.bottom.color = "black"
)
| Tabla N°4 | ||
| Valores atípicos de la variable Latitud de accidentes ocurridos en EE.UU (2010-2017) | ||
| Outliers | Mínimo | Máximo |
|---|---|---|
| 11 | 63.42546 | 70.26126 |
La variable latitud de los accidentes ocurridos en EE.UU. fluctúa
entre 21.304° y 70.261°, con una media de 35.85° y una desviación
estándar de 5.627°, lo que refleja un conjunto de datos relativamente
homogéneo y con baja dispersión. Los valores tienden a concentrarse en
la franja central-sur del país, en torno a los 35° de latitud, con un
sesgo positivo que indica cierta acumulación de accidentes en latitudes
más altas. No obstante, se identificaron 11 valores atípicos a partir de
los 63.425°, correspondientes principalmente a regiones extremas como
Alaska. Por lo antes señalado, el comportamiento de la variable puede
considerarse coherente y beneficioso para el análisis, ya que permite
identificar claramente la franja latitudinal donde ocurre la mayoría de
los accidentes, diferenciándola de casos aislados en zonas alejadas del
territorio continental.