CARGA DE DATOS
# Carga de Datos
ruta_completa <- "C:/Users/klaus/OneDrive/5000_Datos.xlsx"
datos <- readxl::read_excel(ruta_completa, sheet = "Hoja1")CARGA DE LIBRERÍAS
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
TABLA DE DISTRIBUCIÓN DE PROBABILIDAD POR CLASIFICACIÓN
# Tabla de distribución de probabilidad por CLASSIFICATION
TablaClasificacion <- as.data.frame(
table(datos$CLASSIFICATION)
)
colnames(TablaClasificacion) <- c("Clasificacion", "ni")
# Probabilidades sin redondear
TablaClasificacion$hi <- TablaClasificacion$ni / sum(TablaClasificacion$ni)
TablaClasificacion$P <- TablaClasificacion$hi * 100
# Redondeo solo para presentación
TablaClasificacion$hi_red <- round(TablaClasificacion$hi, 4)
TablaClasificacion$P_red <- round(TablaClasificacion$P, 2)
# Corrección del error de redondeo (última categoría)
diferencia <- 100 - sum(TablaClasificacion$P_red)
TablaClasificacion$P_red[nrow(TablaClasificacion)] <-
TablaClasificacion$P_red[nrow(TablaClasificacion)] + diferencia
# Recalcular hi desde el porcentaje corregido
TablaClasificacion$hi_red <-
round(TablaClasificacion$P_red / 100, 4)
# Fila TOTAL
total_clasificacion <- data.frame(
Clasificacion = "Total",
ni = sum(TablaClasificacion$ni),
hi_red = sum(TablaClasificacion$hi_red),
P_red = sum(TablaClasificacion$P_red)
)
# Tabla final
TablaClasificacionFinal <- rbind(
TablaClasificacion[, c("Clasificacion", "ni", "hi_red", "P_red")],
total_clasificacion
)
colnames(TablaClasificacionFinal) <- c("Clasificacion", "ni", "hi", "P")
# Mostrar tabla
TablaClasificacionFinal## Clasificacion ni hi P
## 1 ALL OTHER OCCUPATIONAL ILLNESSES 4 0.0008 0.08
## 2 DISORDERS (PHYSICAL AGENTS) 22 0.0044 0.44
## 3 DISORDERS (REPEATED TRAUMA) 113 0.0229 2.29
## 4 DUST DISEASE OF LUNGS 32 0.0065 0.65
## 5 ELECTRICAL 26 0.0053 0.53
## 6 ENTRAPMENT 25 0.0051 0.51
## 7 EXPLODING VESSELS UNDER PRESSURE 27 0.0055 0.55
## 8 EXPLOSIVES AND BREAKING AGENTS 6 0.0012 0.12
## 9 FALL OF FACE/RIB/PILLAR/SIDE/HIGHWALL 45 0.0091 0.91
## 10 FALL OF ROOF OR BACK 476 0.0963 9.63
## 11 FALLING/SLIDING/ROLLING MATERIALS 23 0.0047 0.47
## 12 FIRE 63 0.0127 1.27
## 13 HANDLING OF MATERIALS 1363 0.2756 27.56
## 14 HANDTOOLS (NONPOWERED) 491 0.0993 9.93
## 15 HOISTING 133 0.0269 2.69
## 16 IGNITION OR EXPLOSION OF GAS OR DUST 24 0.0049 0.49
## 17 IMPOUNDMENT 2 0.0004 0.04
## 18 INUNDATION 13 0.0026 0.26
## 19 MACHINERY 535 0.1082 10.82
## 20 NONPOWERED HAULAGE 13 0.0026 0.26
## 21 OCCUPATIONAL SKIN DISEASES 6 0.0012 0.12
## 22 OTHER 159 0.0322 3.22
## 23 POISONING (TOXIC MATERIALS) 2 0.0004 0.04
## 24 POWERED HAULAGE 356 0.0720 7.20
## 25 RESPIRATORY CONDITIONS (TOXIC AGENTS) 2 0.0004 0.04
## 26 SLIP OR FALL OF PERSON 857 0.1733 17.33
## 27 STEPPING OR KNEELING ON OBJECT 75 0.0152 1.52
## 28 STRIKING OR BUMPING 52 0.0103 1.03
## 29 Total 4945 1.0000 100.00
TABLA DE DISTRIBUCIÓN DE PROBABILIDAD POR CLASIFICACIÓN
tabla_clasificacion_gt <- TablaClasificacionFinal %>%
gt() %>%
tab_header(
title = md("**Tabla N° 1**"),
subtitle = md("**Distribución de probabilidad de Accidentes, Lesiones y
Enfermedades en Operaciones Mineras<br>
por Clasificación (CLASSIFICATION)**")
) %>%
tab_source_note(
source_note = md("Autor: Grupo 1")
) %>%
tab_options(
table.border.top.color = "black",
table.border.bottom.color = "black",
heading.border.bottom.color = "black",
heading.border.bottom.width = px(2),
column_labels.border.top.color = "black",
column_labels.border.bottom.color = "black",
column_labels.border.bottom.width = px(2),
table_body.hlines.color = "gray",
table_body.border.bottom.color = "black",
row.striping.include_table_body = TRUE
) %>%
tab_style(
style = cell_text(weight = "bold"),
locations = cells_body(rows = Clasificacion == "Total")
)
tabla_clasificacion_gt| Tabla N° 1 | |||
| Distribución de probabilidad de Accidentes, Lesiones y
Enfermedades en Operaciones Mineras por Clasificación (CLASSIFICATION) |
|||
| Clasificacion | ni | hi | P |
|---|---|---|---|
| ALL OTHER OCCUPATIONAL ILLNESSES | 4 | 0.0008 | 0.08 |
| DISORDERS (PHYSICAL AGENTS) | 22 | 0.0044 | 0.44 |
| DISORDERS (REPEATED TRAUMA) | 113 | 0.0229 | 2.29 |
| DUST DISEASE OF LUNGS | 32 | 0.0065 | 0.65 |
| ELECTRICAL | 26 | 0.0053 | 0.53 |
| ENTRAPMENT | 25 | 0.0051 | 0.51 |
| EXPLODING VESSELS UNDER PRESSURE | 27 | 0.0055 | 0.55 |
| EXPLOSIVES AND BREAKING AGENTS | 6 | 0.0012 | 0.12 |
| FALL OF FACE/RIB/PILLAR/SIDE/HIGHWALL | 45 | 0.0091 | 0.91 |
| FALL OF ROOF OR BACK | 476 | 0.0963 | 9.63 |
| FALLING/SLIDING/ROLLING MATERIALS | 23 | 0.0047 | 0.47 |
| FIRE | 63 | 0.0127 | 1.27 |
| HANDLING OF MATERIALS | 1363 | 0.2756 | 27.56 |
| HANDTOOLS (NONPOWERED) | 491 | 0.0993 | 9.93 |
| HOISTING | 133 | 0.0269 | 2.69 |
| IGNITION OR EXPLOSION OF GAS OR DUST | 24 | 0.0049 | 0.49 |
| IMPOUNDMENT | 2 | 0.0004 | 0.04 |
| INUNDATION | 13 | 0.0026 | 0.26 |
| MACHINERY | 535 | 0.1082 | 10.82 |
| NONPOWERED HAULAGE | 13 | 0.0026 | 0.26 |
| OCCUPATIONAL SKIN DISEASES | 6 | 0.0012 | 0.12 |
| OTHER | 159 | 0.0322 | 3.22 |
| POISONING (TOXIC MATERIALS) | 2 | 0.0004 | 0.04 |
| POWERED HAULAGE | 356 | 0.0720 | 7.20 |
| RESPIRATORY CONDITIONS (TOXIC AGENTS) | 2 | 0.0004 | 0.04 |
| SLIP OR FALL OF PERSON | 857 | 0.1733 | 17.33 |
| STEPPING OR KNEELING ON OBJECT | 75 | 0.0152 | 1.52 |
| STRIKING OR BUMPING | 52 | 0.0103 | 1.03 |
| Total | 4945 | 1.0000 | 100.00 |
| Autor: Grupo 1 | |||
Debido al elevado número de categorías en la variable CLASSIFICATION, se procedió a agrupar las clasificaciones menos frecuentes en la categoría “Otras clasificaciones”, conservando individualmente aquellas con mayor frecuencia relativa, con el fin de facilitar la interpretación gráfica de los resultados.
TABLA DE DISTRIBUCIÓN DE PROBABILIDAD AGRUPADA
library(dplyr)
# Tabla base de frecuencias
TablaClasificacion <- datos %>%
count(CLASSIFICATION, name = "ni") %>%
arrange(desc(ni))
# Seleccionar las 6 clasificaciones más frecuentes
top_n <- 6
TablaClasificacion <- TablaClasificacion %>%
mutate(
Clasificacion_Agrupada = ifelse(
row_number() <= top_n,
as.character(CLASSIFICATION),
"Otras clasificaciones"
)
)
# Agrupar
TablaClasificacionAgrupada <- TablaClasificacion %>%
group_by(Clasificacion_Agrupada) %>%
summarise(ni = sum(ni), .groups = "drop")
# Probabilidades sin redondear
TablaClasificacionAgrupada$hi <-
TablaClasificacionAgrupada$ni / sum(TablaClasificacionAgrupada$ni)
TablaClasificacionAgrupada$P <-
TablaClasificacionAgrupada$hi * 100
# Redondeo para presentación
TablaClasificacionAgrupada$hi_red <- round(TablaClasificacionAgrupada$hi, 4)
TablaClasificacionAgrupada$P_red <- round(TablaClasificacionAgrupada$P, 2)
# Corrección de redondeo (última fila)
diferencia <- 100 - sum(TablaClasificacionAgrupada$P_red)
TablaClasificacionAgrupada$P_red[nrow(TablaClasificacionAgrupada)] <-
TablaClasificacionAgrupada$P_red[nrow(TablaClasificacionAgrupada)] + diferencia
# Recalcular hi desde P corregido
TablaClasificacionAgrupada$hi_red <-
round(TablaClasificacionAgrupada$P_red / 100, 4)
# Fila TOTAL
total_clasificacion <- data.frame(
Clasificacion_Agrupada = "Total",
ni = sum(TablaClasificacionAgrupada$ni),
hi_red = sum(TablaClasificacionAgrupada$hi_red),
P_red = sum(TablaClasificacionAgrupada$P_red)
)
# Tabla final
TablaClasificacionFinal <- rbind(
TablaClasificacionAgrupada[, c("Clasificacion_Agrupada", "ni", "hi_red", "P_red")],
total_clasificacion
)
colnames(TablaClasificacionFinal) <- c("Clasificacion", "ni", "hi", "P")
# Mostrar tabla
TablaClasificacionFinal## # A tibble: 8 × 4
## Clasificacion ni hi P
## <chr> <int> <dbl> <dbl>
## 1 FALL OF ROOF OR BACK 476 0.0963 9.63
## 2 HANDLING OF MATERIALS 1363 0.276 27.6
## 3 HANDTOOLS (NONPOWERED) 491 0.0993 9.93
## 4 MACHINERY 535 0.108 10.8
## 5 Otras clasificaciones 867 0.175 17.5
## 6 POWERED HAULAGE 356 0.072 7.2
## 7 SLIP OR FALL OF PERSON 857 0.173 17.3
## 8 Total 4945 1 100
TABLA DE DISTRIBUCIÓN DE PROBABILIDAD AGRUPADA FINAL
TablaClasificacionFinal <- TablaClasificacionFinal %>%
mutate(
Clasificacion = factor(
Clasificacion,
levels = c(
setdiff(
Clasificacion,
c("Otras clasificaciones", "Total")
),
"Otras clasificaciones",
"Total"
)
)
) %>%
arrange(Clasificacion)
tabla_clasificacion_gt <- TablaClasificacionFinal %>%
gt() %>%
tab_header(
title = md("**Tabla N° 2**"),
subtitle = md("**Distribución de probabilidad de Accidentes, Lesiones y Enfermedades en Operaciones Mineras<br>
por Clasificación (CLASSIFICATION)**")
) %>%
tab_source_note(
source_note = md("Autor: Grupo 1")
) %>%
tab_options(
table.border.top.color = "black",
table.border.bottom.color = "black",
heading.border.bottom.color = "black",
heading.border.bottom.width = px(2),
column_labels.border.top.color = "black",
column_labels.border.bottom.color = "black",
column_labels.border.bottom.width = px(2),
table_body.hlines.color = "gray",
table_body.border.bottom.color = "black",
row.striping.include_table_body = TRUE
) %>%
tab_style(
style = cell_text(weight = "bold"),
locations = cells_body(rows = Clasificacion == "Total")
)
tabla_clasificacion_gt| Tabla N° 2 | |||
| Distribución de probabilidad de Accidentes, Lesiones y Enfermedades en Operaciones Mineras por Clasificación (CLASSIFICATION) |
|||
| Clasificacion | ni | hi | P |
|---|---|---|---|
| FALL OF ROOF OR BACK | 476 | 0.0963 | 9.63 |
| HANDLING OF MATERIALS | 1363 | 0.2756 | 27.56 |
| HANDTOOLS (NONPOWERED) | 491 | 0.0993 | 9.93 |
| MACHINERY | 535 | 0.1082 | 10.82 |
| POWERED HAULAGE | 356 | 0.0720 | 7.20 |
| SLIP OR FALL OF PERSON | 857 | 0.1733 | 17.33 |
| Otras clasificaciones | 867 | 0.1753 | 17.53 |
| Total | 4945 | 1.0000 | 100.00 |
| Autor: Grupo 1 | |||
DIAGRAMA DE BARRAS
# Excluir Total para la gráfica
tabla_grafica <- TablaClasificacionFinal %>%
filter(Clasificacion != "Total")
par(mar = c(14, 4, 4, 2))
barplot(
tabla_grafica$P,
names.arg = tabla_grafica$Clasificacion,
col = "steelblue",
main = "Gráfica Nº 1: Distribución de probabilidad\nde Accidentes, Lesiones y
Enfermedades en Operaciones Mineras por Clasificación",
xlab = "Clasificación",
ylab = "Probabilidad (%)",
cex.names = 0.9,
las = 2,
ylim = c(0, max(tabla_grafica$P) + 5)
)# Identificar clasificación con mayor probabiblidad (excluye total)
tabla_sin_total <- TablaClasificacionFinal[
TablaClasificacionFinal$Clasificacion != "Total",
]
clasif_mayor <- tabla_sin_total$Clasificacion[
which.max(tabla_sin_total$P)
]
prob_mayor <- tabla_sin_total$P[
which.max(tabla_sin_total$P)
]
# Gráfico de texto explicativo
plot(1, type = "n", axes = FALSE, xlab = "", ylab = "")
text(
x = 1, y = 1,
labels = paste(
"Cálculo de probabilidad\n(Estimación general)\n\n",
"¿Qué clasificación es más probable\n",
"que registre Accidentes, Lesiones y
Enfermedades en Operaciones Mineras?\n\n",
"R: ", clasif_mayor, "\n",
"Probabilidad = ", prob_mayor, " (%)",
sep = ""
),
cex = 1.4,
font = 2
)Los resultados indican que la clasificación con mayor probabilidad de ocurrencia de Accidentes, Lesiones y Enfermedades en Operaciones Mineras corresponde a Handling of Materials, con una probabilidad del 27.56%.