CARRERA DE GEOLOGÍA
GRUPO N°2
ANÁLISIS ESTADÍSTICO MULTIVARIABLE
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.6'
## (as 'lib' is unspecified)
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.6'
## (as 'lib' is unspecified)
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.6'
## (as 'lib' is unspecified)
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.6'
## (as 'lib' is unspecified)
##
## 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
## Rows: 898 Columns: 77
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ";"
## chr (26): volcanoLocationNum, volcano_name, location_description, country, v...
## dbl (43): noaa_event_id, year, month, day, linked_tsunami_event_id, linked_e...
## num (1): ejecta_volume_km3_min
## lgl (7): is_significant, publish, is_eruption, tsunami_confirmed, ring_of_f...
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## --- REPORTE DE CONTROL DE VALORES OMITIDOS ---
## Número de datos en la variable Vei (X): 714
## Número de datos en la variable muertes_t (Y): 714
## ----------------------------------------------
## Valores NA encontrados en Vei: 0
## Valores NA encontrados en muertes_t: 0
# Variable Independiente (X)
Vei <- as.numeric(Volcanes_Globales$vei)
# Variable Dependiente (Y)
muertes_t <- as.numeric(Volcanes_Globales$total_deaths)
# Limpieza de dataset
TPV_inicial <- data.frame(Vei = Vei, muertes_t = muertes_t)
TPV_inicial <- na.omit(TPV_inicial)
# Filtro físico: El VEI es >= 0 y las muertes deben ser mayores o iguales a cero
TPV_inicial <- TPV_inicial[TPV_inicial$Vei >= 0 & TPV_inicial$muertes_t >= 0, ]
total_inicial <- nrow(TPV_inicial)
# USO INTERCUARTIL (Adaptado a la nueva escala lineal proporcional)
# Límites para el Índice de Explosividad (X)
q1_p <- quantile(TPV_inicial$Vei, 0.25)
q3_p <- quantile(TPV_inicial$Vei, 0.75)
iqr_p <- q3_p - q1_p
# Límites para las Muertes Totales (Y)
q1_c <- quantile(TPV_inicial$muertes_t, 0.25)
q3_c <- quantile(TPV_inicial$muertes_t, 0.75)
iqr_c <- q3_c - q1_c
# Aplicar filtro de Outliers usando las fronteras lineales calculadas
TPV_sin_outliers <- TPV_inicial %>%
filter(Vei >= (q1_p - 1.5 * iqr_p) & Vei <= (q3_p + 1.5 * iqr_p)) %>%
filter(muertes_t >= (q1_c - 1.5 * iqr_c) & muertes_t <= (q3_c + 1.5 * iqr_c))
total_restante_outliers <- nrow(TPV_sin_outliers)
outliers_encontrados <- total_inicial - total_restante_outliers
# En lugar de colapsar con summarise(), simplemente asignamos el dataset filtrado a TPV
TPV <- TPV_sin_outliers
row.names(TPV) <- NULL
TPV_final_id <- cbind(Nro = 1:nrow(TPV), TPV)
valores_consolidados_media <- 0
# Outliers encontrados por Intercuartil
outliers_encontrados <- total_inicial - total_restante_outliers
outliers_encontrados
## [1] 4
# Reducción de filas repetidas por Media Aritmética
# No se consolidan filas, por lo que la reducción es 0
valores_consolidados_media <- 0
valores_consolidados_media
## [1] 0
# Total de pares de valores
total_pares <- nrow(TPV)
total_pares
## [1] 710
| TABLA N°1 | ||
| Primeros 10 pares de valores para la regresión lineal | ||
| N° | VEI | Muertes Totales |
|---|---|---|
| 1 | 6 | 24,685 |
| 2 | 6 | 24,182 |
| 3 | 6 | 24,316 |
| 4 | 6 | 24,202 |
| 5 | 6 | 23,947 |
| 6 | 5 | 20,756 |
| 7 | 6 | 23,953 |
| 8 | 6 | 25,009 |
| 9 | 6 | 23,969 |
| 10 | 6 | 24,652 |
plot(TPV$Vei, TPV$muertes_t,
pch = 16,
col = rgb(0.2, 0.4, 0.6, 0.6),
main = "Gráfica Nº1: Diagrama de Dispersión entre el VEI\ny las Muertes Totales (Sin Outliers)",
xlab = "Índice de Explosividad Volcánica - VEI (X)",
ylab = "Número Total de Muertes - muertes_t (Y)")
box(which = "outer", col = "black")
x <- TPV$Vei
y <- TPV$muertes_t
# Ejecutamos la regresión lineal
regresion_lineal <- lm(y ~ x)
# Imprimimos el resumen del modelo en consola
cat("## \n## Call:\n## ")
## ##
## ## Call:
## ##
print(regresion_lineal$call)
## lm(formula = y ~ x)
cat("\n## Coefficients:\n")
##
## ## Coefficients:
print(coef(regresion_lineal))
## (Intercept) x
## -21.71651 4005.50110
# Separamos y mostramos de forma individual los coeficientes paramétricos
intercepto <- coef(regresion_lineal)[1]
pendiente <- coef(regresion_lineal)[2]
cat("\nIntercepto\n## (Intercept) \n ", round(intercepto, 4), "\n")
##
## Intercepto
## ## (Intercept)
## -21.7165
cat("\nPendiente\n## x \n ", round(pendiente, 7), "\n")
##
## Pendiente
## ## x
## 4005.501
# Test de Pearson
r <- cor(x, y)
cat("Test de Pearson\n")
## Test de Pearson
cat("r <- cor(x, y)\n")
## r <- cor(x, y)
cat("r*100\n")
## r*100
cat("## [1]", round(r * 100, 4), "\n\n")
## ## [1] 99.5452
# Coeficiente de Determinación
r2 <- r^2
cat("Coeficiente de Determinación\n")
## Coeficiente de Determinación
cat("r2 <- r^2\n")
## r2 <- r^2
cat("r2*100\n")
## r2*100
cat("## [1]", round(r2 * 100, 5), "\n")
## ## [1] 99.09252
## Tabla Nº3: Test de Aprobación del Modelo Lineal
## ---------------------------------------------------------
## Indicador Valor
## Coeficiente de Pearson (r) 99.55 %
## Coeficiente de Determinación (R²) 99.09 %
| Tabla Nº3: Test de Aprobación del Modelo Lineal | |
| Evaluación estadística mediante coeficiente de correlación y determinación | |
| Indicador estadístico | Resultado |
|---|---|
| Coeficiente de Pearson (r) | 99.55% |
| Coeficiente de Determinación (R²) | 99.09% |
# Raíz física del modelo lineal
x_restriccion <- -a / b
x_restriccion
## (Intercept)
## 0.005421672
# Raíz física del modelo lineal
x_restriccion <- -a / b
# Definimos el valor a pronosticar (VEI = 7)
x_pronostico <- 7
# Calculamos el número de muertes esperadas usando la ecuación lineal
muertes_esp <- a + b * x_pronostico