ANÁLISIS ESTADÍSTICO

CARGA DE DATOS Y LIBRERÍAS

CARGA DE DATOS

#Carga de datos

setwd("~/UNI/ESTADISTICA")
datos <- read.csv("Depositos_Sulfuro.csv", header = TRUE, sep = ";", dec = ".")

CARGA DE LIBRERIAS

#Carga de librerias
library(countrycode)
library(gt)
library(dplyr)
library(knitr)

TABLA DE DISTRIBUCIÓN DE PROBABILIDAD

TABLA DE DISTRIBUCION DE PROBABILIDAD POR TIPO DE DEPOSITO

# Extraer variable tipo de depósito
Tipo_Deposito <- datos$deptype

# Reemplazar NA por "Sin Registro"
TipoDep_limpio <- ifelse(
  is.na(Tipo_Deposito) | trimws(Tipo_Deposito) == "",
  "Sin Registro",
  trimws(Tipo_Deposito)
)

TIPODEPOSITO <- factor(TipoDep_limpio)

# Frecuencias y probabilidades
TablaTIPODEPOSITO <- as.data.frame(table(TIPODEPOSITO))
colnames(TablaTIPODEPOSITO) <- c("TIPODEPOSITO", "ni")
TablaTIPODEPOSITO$hi <- round(TablaTIPODEPOSITO$ni / sum(TablaTIPODEPOSITO$ni),4)
TablaTIPODEPOSITO$P <- round(TablaTIPODEPOSITO$hi * 100,2)

#Fila TOTAL
Total <- data.frame(
  TIPODEPOSITO = "TOTAL",
  ni = sum(TablaTIPODEPOSITO$ni),
  hi = round(sum(TablaTIPODEPOSITO$hi), ),
  P  = round(sum(TablaTIPODEPOSITO$P), )
)

#Tabla final
TablaFinalTD <- rbind(TablaTIPODEPOSITO, Total)

TablaFinalTD
##    TIPODEPOSITO   ni     hi      P
## 1 Bimodal-Mafic  358 0.3284  32.84
## 2        Felsic  529 0.4853  48.53
## 3         Mafic  202 0.1853  18.53
## 4  Sin Registro    1 0.0009   0.09
## 5         TOTAL 1090 1.0000 100.00

TABLA DE DISTRIBUCION DE PROBABILIDAD POR TIPO DE DEPOSITO

tabla_TD_gt <- TablaFinalTD %>%
  gt() %>%
  tab_header(
    title = md("**Tabla N° 1**"),
    subtitle = md("Distribución de probabilidad por tipo de 
    Depósitos Masivos de Sulfuro Volcánicos")
  ) %>%
  tab_source_note(
    source_note = md("Autor: Grupo 2")
  ) %>%
  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 = TIPODEPOSITO == "Total")
  )

tabla_TD_gt
Tabla N° 1
Distribución de probabilidad por tipo de Depósitos Masivos de Sulfuro Volcánicos
TIPODEPOSITO ni hi P
Bimodal-Mafic 358 0.3284 32.84
Felsic 529 0.4853 48.53
Mafic 202 0.1853 18.53
Sin Registro 1 0.0009 0.09
TOTAL 1090 1.0000 100.00
Autor: Grupo 2

GRÁFICAS DE DISTRIBUCIÓN DE PROBABILIDAD

Diagrama de barras

# Extraer la probabilidad en porcentaje 
P_global <- as.numeric(TablaFinalTD$P[1:(nrow(TablaFinalTD)-1)])

#Diagrama de barras

barplot(
  P_global,
  main = "Gráfica Nº1: Distribución de probabilidad del tipo de depósitos
masivos de sulfuros volcánicos",
  cex.main = 0.8,
  xlab = "Tipo de depósito",
  ylab = "Probabilidad",
  col = "blue",
  names.arg = TablaFinalTD$TIPODEPOSITO[1:(nrow(TablaFinalTD)-1)],
  cex.names = 0.6,
  ylim = c(0, 100),
  las = 2
)

CÁLCULO DE PROBABILIDAD

# Eliminar fila TOTAL
tabla_sin_total <- TablaFinalTD[
  TablaFinalTD$TIPODEPOSITO != "TOTAL",
]

# Identificar el tipo de depósito con mayor probabilidad
tipo_mayor <- tabla_sin_total$TIPODEPOSITO[
  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é tipo de depósito es más probable\n",
    "que concentre la mayor cantidad de\n",
    "depósitos masivos de sulfuros volcánicos?\n\n",
    "R: ", tipo_mayor, "\n",
    "Probabilidad = ", prob_mayor, " (%)",
    sep = ""
  ),
  cex = 1.4,
  col = "black",
  font = 2
)