Variable cuantitativa continua
Error Magnitud
Importamos el archivo “Earthquakes.csv” desde una ruta local y lo almacena en el Datos, usando espacios o tabulaciones como separador. Luego, la función str(Datos) muestra la estructura del data frame, indicando tipos de datos y ejemplos de sus columnas.
Datos <- read.csv("C:/Users/Estefania Ibaza/Desktop/UCE/CUARTO/GRUPALSISMOS/CODIGOSISMOS/Earthquakes.csv", header = TRUE, sep=",", dec=".")
str(Datos)## 'data.frame': 17805 obs. of 22 variables:
## $ time : chr "2024-10-31T01:32:40.503Z" "2024-10-30T23:51:31.217Z" "2024-10-29T02:35:27.930Z" "2024-10-28T13:08:40.107Z" ...
## $ latitude : num 29.86 28.21 4.72 27.87 32.75 ...
## $ longitude : num 92.2 67.1 96.2 94 90.4 ...
## $ depth : num 10 10 42.1 36.3 10 ...
## $ mag : num 4.4 4.3 4.6 4.6 4 4.6 4.7 4.3 5.3 4.4 ...
## $ magType : chr "mb" "mb" "mb" "mb" ...
## $ nst : int 35 36 27 62 22 44 39 34 80 27 ...
## $ gap : num 89 195 91 98 79 170 169 105 65 140 ...
## $ dmin : num 6.45 9.37 0.87 6.69 6.64 ...
## $ rms : num 0.82 0.72 0.55 0.65 0.72 0.74 0.81 0.54 0.92 0.9 ...
## $ net : chr "us" "us" "us" "us" ...
## $ id : chr "us7000np4h" "us7000np47" "us7000nnqs" "us7000nnml" ...
## $ updated : chr "2024-10-31T01:54:50.040Z" "2024-10-31T00:07:19.040Z" "2024-10-29T03:36:02.040Z" "2024-10-29T04:19:35.951Z" ...
## $ place : chr "113 km ENE of Lhasa, China" "64 km NE of Khuzdar, Pakistan" "55 km S of Reuleuet, Indonesia" "35 km NNE of Ziro, India" ...
## $ type : chr "earthquake" "earthquake" "earthquake" "earthquake" ...
## $ horizontalError: num 7.45 12.2 5.1 8.9 9.39 ...
## $ depthError : num 1.88 1.99 8.27 7.33 1.98 ...
## $ magError : num 0.114 0.092 0.146 0.078 0.139 0.078 0.097 0.107 0.11 0.102 ...
## $ magNst : int 22 33 14 49 14 49 32 25 8 28 ...
## $ status : chr "reviewed" "reviewed" "reviewed" "reviewed" ...
## $ locationSource : chr "us" "us" "us" "us" ...
## $ magSource : chr "us" "us" "us" "us" ...
Cálculo de los intervalos mediante la regla de Sturges
k<-1+(3.3*log10(length(ErrorMagnitud)))
k<-floor(k)
min<-min(ErrorMagnitud)
max<-max(ErrorMagnitud)
R<-max-min
A<-R/k
Li<-round(seq(from=min, to=max-A, by=A),4)
Ls<-round(seq(from=min+A, to=max, by=A),4)
MC<-round((Li+Ls)/2,2) #Marca de clase
MC## [1] 0.05 0.09 0.13 0.17 0.21 0.25 0.29 0.32 0.36 0.40 0.44 0.48 0.52
ni <- numeric(length(Li))
for (i in 1:length(Li)) {
ni[i] <- sum(ErrorMagnitud >= Li[i] & ErrorMagnitud < Ls[i])
}
ni[length(Li)] <- sum(ErrorMagnitud >= Li[length(Li)] & ErrorMagnitud <= max)
sum(ni) #Nuevo tamaño muestral ## [1] 5852
## [1] 100
Ni_asc <- cumsum(ni)
Ni_dsc <- rev(cumsum(rev(ni)))
Hi_asc <- round(cumsum(hi), 2)
Hi_dsc <- round(rev(cumsum(rev(hi))), 2)
TDFErrorMagnitud <-data.frame(Li, Ls, MC, ni, hi, Ni_asc, Ni_dsc, Hi_asc, Hi_dsc)
TDFErrorMagnitudRealizamos el histograma de la variable para extraer los breaks y asi conocer los nuevos límites.
histoErrorMag<-hist(ErrorMagnitud,
main= "Gráfica N°55: Distribución de frecuencia de Error de Magnitud \nde los sismos en el Subcontiente Indio (2000-2024)",
xlab= " Error Magnitud",
ylab= "Cantidad", col="blue",
las=2)## [1] 0.00 0.05 0.10 0.15 0.20 0.25 0.30 0.35 0.40 0.45 0.50 0.55
## [1] 5852
## [1] 100
Niasc <- cumsum(ni)
Nidsc <- rev(cumsum(rev(ni)))
Hiasc <- round(cumsum(hi), 2)
Hidsc <- round(rev(cumsum(rev(hi))), 2)
TDFErrorMag<-data.frame(LimInf, LimSup, Mc, ni, hi, Niasc, Nidsc, Hiasc, Hidsc)
TDFErrorMagAgregar Totales, para una mejor visualización de la tabla
totalni <- sum(ni)
totalhi <- 100
TDFErrorMagCompleto<-rbind(TDFErrorMag, data.frame(LimInf="Total",
LimSup=" ", Mc=" ",ni=totalni, hi=totalhi, Niasc=" ", Nidsc=" ",
Hiasc=" ", Hidsc=" "))
print(TDFErrorMagCompleto)## LimInf LimSup Mc ni hi Niasc Nidsc Hiasc Hidsc
## 1 0 0.05 0.025 268 4.57963090 268 5852 4.58 100
## 2 0.05 0.1 0.075 2128 36.36363636 2396 5584 40.94 95.42
## 3 0.1 0.15 0.125 1849 31.59603554 4245 3456 72.54 59.06
## 4 0.15 0.2 0.175 1035 17.68626111 5280 1607 90.23 27.46
## 5 0.2 0.25 0.225 365 6.23718387 5645 572 96.46 9.77
## 6 0.25 0.3 0.275 119 2.03349282 5764 207 98.5 3.54
## 7 0.3 0.35 0.325 36 0.61517430 5800 88 99.11 1.5
## 8 0.35 0.4 0.375 36 0.61517430 5836 52 99.73 0.89
## 9 0.4 0.45 0.425 1 0.01708817 5837 16 99.74 0.27
## 10 0.45 0.5 0.475 2 0.03417635 5839 15 99.78 0.26
## 11 0.5 0.55 0.525 13 0.22214627 5852 13 100 0.22
## 12 Total 5852 100.00000000
## Warning: package 'gt' was built under R version 4.4.3
## Warning: package 'dplyr' was built under R version 4.4.3
##
## Adjuntando el paquete: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
# Crear la tabla
tablaErrorMag<-TDFErrorMagCompleto %>%
gt() %>%
tab_header(
title = md("**Tabla N°19**"),
subtitle = md("**Tabla de distribución de Frecuencias simples y acumuladas
del Error de Magnitud de los Sismos en el Subcontinente Indio (2000-2024)**")
) %>%
tab_source_note(
source_note = md("Autor:Grupo1")
) %>%
tab_options(
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),
row.striping.include_table_body = TRUE,
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"
)
)
tablaErrorMag| Tabla N°19 | ||||||||
| Tabla de distribución de Frecuencias simples y acumuladas del Error de Magnitud de los Sismos en el Subcontinente Indio (2000-2024) | ||||||||
| LimInf | LimSup | Mc | ni | hi | Niasc | Nidsc | Hiasc | Hidsc |
|---|---|---|---|---|---|---|---|---|
| 0 | 0.05 | 0.025 | 268 | 4.57963090 | 268 | 5852 | 4.58 | 100 |
| 0.05 | 0.1 | 0.075 | 2128 | 36.36363636 | 2396 | 5584 | 40.94 | 95.42 |
| 0.1 | 0.15 | 0.125 | 1849 | 31.59603554 | 4245 | 3456 | 72.54 | 59.06 |
| 0.15 | 0.2 | 0.175 | 1035 | 17.68626111 | 5280 | 1607 | 90.23 | 27.46 |
| 0.2 | 0.25 | 0.225 | 365 | 6.23718387 | 5645 | 572 | 96.46 | 9.77 |
| 0.25 | 0.3 | 0.275 | 119 | 2.03349282 | 5764 | 207 | 98.5 | 3.54 |
| 0.3 | 0.35 | 0.325 | 36 | 0.61517430 | 5800 | 88 | 99.11 | 1.5 |
| 0.35 | 0.4 | 0.375 | 36 | 0.61517430 | 5836 | 52 | 99.73 | 0.89 |
| 0.4 | 0.45 | 0.425 | 1 | 0.01708817 | 5837 | 16 | 99.74 | 0.27 |
| 0.45 | 0.5 | 0.475 | 2 | 0.03417635 | 5839 | 15 | 99.78 | 0.26 |
| 0.5 | 0.55 | 0.525 | 13 | 0.22214627 | 5852 | 13 | 100 | 0.22 |
| Total | 5852 | 100.00000000 | ||||||
| Autor:Grupo1 | ||||||||
hist(ErrorMagnitud,main="Gráfica N°56: Distribución de frecuencia de Error Magnitud \nde los sismos del Subcontinente Indio (Local)",
ylab="Cantidad",
xlab="Error Magnitud",
col="blue")hist(ErrorMagnitud,main="Gráfica N°57: Distribución de frecuencia de Error Magnitud \nde los sismos del Subcontinente Indio (Global)",
ylab="Cantidad",
xlab="Error Magnitud",
col="blue", ylim = c(0,length(ErrorMagnitud)))barplot(hi,space = 0,
main="Gráfica N°58:Distribución del porcentaje de Error Magnitud \nde los sismos del Subcontinente Indio (Local)",
col="blue",
xlab = "Error Magnitud",
ylab = "Porcentaje (%)",
names.arg =TDFErrorMag$Mc)barplot(hi,space = 0,
main="Gráfica N°59:Distribución del porcentaje de Error Magnitud \nde los sismos del Subcontinente Indio (Global)",
col="blue",
xlab = "Error Magnitud",
ylab = "Porcentaje (%)",
names.arg =TDFErrorMag$Mc,
ylim = c(0,100)
)TDFErrorMag <- na.omit(TDFErrorMag)
# Verifica longitudes antes de graficar
if(length(TDFErrorMag$LimInf) == length(TDFErrorMag$Nidsc)) {
plot(TDFErrorMag$LimInf, TDFErrorMag$Nidsc,
main = "Gráfica N°60: Ojivas combinadas del Error Magnitud \nde los sismos del Subcontinente Indio",
xlab = "Error Magnitud",
ylab = "Cantidad",
col = "blue",
type = "b")
if(length(TDFErrorMag$LimSup) == length(TDFErrorMag$Niasc)) {
lines(TDFErrorMag$LimSup, TDFErrorMag$Niasc, col = "black", type = "b")
}
legend("right",
legend = c("Ojiva descendente", "Ojiva ascendente"),
col = c("blue", "black"),pch = 1,lty = 1,cex = 0.7)
} # Verificamos que los vectores estén completos y sean compatibles
if(length(TDFErrorMag$LimInf) == length(TDFErrorMag$Hidsc)) {
plot(TDFErrorMag$LimInf, TDFErrorMag$Hidsc,
main = "Gráfica N°61:Ojivas combinadas del Error Magnitud \nde los sismos del Subcontinente Indio",
xlab = "Error Magnitud",
ylab = "Porcentaje (%)",
col = "black",
type = "b")
if(length(TDFErrorMag$LimSup) == length(TDFErrorMag$Hiasc)) {
lines(TDFErrorMag$LimSup, TDFErrorMag$Hiasc, col = "blue", type = "b")
}
legend("right",
legend = c("Ojiva descendente", "Ojiva ascendente"),
col = c("black", "blue"),pch = 1,lty = 1,cex = 0.7)
} Caja<-boxplot(ErrorMagnitud,horizontal = T,
col = "skyblue",
main="Gráfica N°62:Distribución de la cantidad de Error Magnitud \nde los sismos del Subcontinente Indio",
xlab="Error Magnitud")## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.0310 0.0820 0.1130 0.1248 0.1560 0.5390
## [1] 0.1248242
## [1] 0.113
## [1] 0.06085456
## [1] 48.75223
#FORMA
#COEFICIENTE DE ASIMETRÍA
options(repos = c(CRAN = "https://cran.rstudio.com"))
install.packages("e1071")## package 'e1071' successfully unpacked and MD5 sums checked
## Warning: cannot remove prior installation of package 'e1071'
## Warning in file.copy(savedcopy, lib, recursive = TRUE): problema al copiar
## C:\Users\Estefania
## Ibaza\AppData\Local\Programs\R\R-4.4.2\library\00LOCK\e1071\libs\x64\e1071.dll
## a C:\Users\Estefania
## Ibaza\AppData\Local\Programs\R\R-4.4.2\library\e1071\libs\x64\e1071.dll:
## Permission denied
## Warning: restored 'e1071'
##
## The downloaded binary packages are in
## C:\Users\Public\Documents\Wondershare\CreatorTemp\RtmpoHaL51\downloaded_packages
## Warning: package 'e1071' was built under R version 4.4.3
## [1] 1.617131
## [1] 5.336228
Variable<-c("Error Magnitud")
TablaIndicadores<-data.frame(Variable,ri,rs,round(x,2),Me,round(sd,2), round(CV,2), round(As,2),round(K,2))
colnames(TablaIndicadores)<-c("Variable","minimo","máximo","x","Me","sd","Cv (%)","As","K")
library(knitr)
kable(TablaIndicadores, format = "markdown", caption = "Tabla N°20. Indicadores estadíticos de la variable Eror Magnitud")## Warning in attr(x, "align"): 'xfun::attr()' está en desuso.
## Utilizar 'xfun::attr2()' en su lugar.
## Ver help("Deprecated")
## Warning in attr(x, "format"): 'xfun::attr()' está en desuso.
## Utilizar 'xfun::attr2()' en su lugar.
## Ver help("Deprecated")
| Variable | minimo | máximo | x | Me | sd | Cv (%) | As | K |
|---|---|---|---|---|---|---|---|---|
| Error Magnitud | 0.031 | 0.539 | 0.12 | 0.113 | 0.06 | 48.75 | 1.62 | 5.34 |
outliers<-boxplot.stats(ErrorMagnitud)$out
# Contar los valores atípicos
num_outliers <- length(outliers)
num_outliers## [1] 136
## [1] 0.268
## [1] 0.539
TablaOutliers<-data.frame(num_outliers,minoutliers,maxoutliers)
colnames(TablaOutliers)<-c("Outliers","Mínimo","Máximo")
library(knitr)
kable(TablaOutliers, format = "markdown", caption = "Tabla N°21: Outliers de la variable Error Magnitud).")## Warning in attr(x, "align"): 'xfun::attr()' está en desuso.
## Utilizar 'xfun::attr2()' en su lugar.
## Ver help("Deprecated")
## Warning in attr(x, "format"): 'xfun::attr()' está en desuso.
## Utilizar 'xfun::attr2()' en su lugar.
## Ver help("Deprecated")
| Outliers | Mínimo | Máximo |
|---|---|---|
| 136 | 0.268 | 0.539 |
La variable error de magnitud en el subcontinente indio fluctúa entre 0.031 y 0.539, con una mediana de aproximadamente 0.113 y una desviación estándar de 0.0608. El conjunto de datos es ligeramente heterogéneo, con una acumulación de valores en los niveles bajos, mostrando una asimetría positiva con sesgo hacia la derecha. Además, se identifican valores atípicos, con un total de 136 observaciones que se encuentran en el rango de 0.268 a 0.539. Por lo antes mencionado, el comportamiento de la variable es medianamente beneficioso. ya que apesar de que la mayoría de los valores son bajos y consistentes, la presencia de 136 valores atípicos con errores altos introduce cierta incertidumbre, por lo que se recomienda tener precaución en análisis que requieran alta precisión.