Variable Cuantitativa Continua
Longitud
La longitud es una cordenada geográfica asociada con los meridianos
Importamos el archivo “Earthquakes (2).csv” desde una ruta local y lo almacena en el objeto datos, usando espacios o tabulaciones como separador. Luego, la función str() muestra la estructura del data frame.
datos<-read.csv("C:/Users/Public/Documents/Estadistica2/R/9462996/Earthquakes (2).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" ...
Extraemos la variable longitud de datos, omitimos las celdas en blanco y verificamos el tamaño muestral
Longitud<-datos$longitude
valoresnulos <- is.na(Longitud)
Longitud <- na.omit(Longitud)
n<-length(Longitud)
n## [1] 17805
Mediante la ley de Sturges, encontramos el valor total de intervalos que se recomienda para nuestro tamaño muestral:
## [1] 15
Calculamos el rango, amplitud, límites de los intervalos, marca de clase, frecuencias simples y frecuencias acumuladas.
min<-min(Longitud)
max<-max(Longitud)
R<-max-min
A<-R/k
Li<-round(seq(from=min, to=max-A, by=A),4)
Li## [1] 60.6678 63.3496 66.0314 68.7132 71.3951 74.0769 76.7587 79.4405 82.1223
## [10] 84.8041 87.4859 90.1677 92.8496 95.5314 98.2132
## [1] 63.3496 66.0314 68.7132 71.3951 74.0769 76.7587 79.4405 82.1223
## [9] 84.8041 87.4859 90.1677 92.8496 95.5314 98.2132 100.8950
## [1] 62.01 64.69 67.37 70.05 72.74 75.42 78.10 80.78 83.46 86.15 88.83 91.51
## [13] 94.19 96.87 99.55
ni <- numeric(length(Li))
for (i in 1:length(Li)) {
ni[i] <- sum(Longitud >= Li[i] & Longitud < Ls[i])
}
ni[length(Li)] <- sum(Longitud >= Li[length(Li)] & Longitud <= max)
sum(ni)## [1] 17805
## [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)Asignamos a una tabla con un dat.frame
Generamos una tabla mas completa para una mejor visualización con la libreria gt()
#Agregar Totales:
total_ni <- sum(ni)
total_hi <- 100 #Dado que los porcentajes de frecuencia relativa ya suman 100"
TDFLongitudCompleto<-rbind(TDFLongitud, data.frame(Li="Total",
Ls=" ", MC=" ",ni=total_ni, hi=total_hi, Ni_asc=" ", Ni_dsc=" ",
Hi_dsc=" ", Hi_dsc=" "))
#install.packages("gt")
library(gt)## 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
tabla_Longitud<-TDFLongitudCompleto %>%
gt() %>%
tab_header(
title = md("**Tabla Nro. 10**"),
subtitle = md("**Tabla de distribución de Frecuencias simples y acumuladas
de la Longitud 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 = Li == "Total"
)
)
tabla_Longitud| Tabla Nro. 10 | ||||||||
| Tabla de distribución de Frecuencias simples y acumuladas de la Longitud de los Sismos en el Subcontinente Indio (2000-2024) | ||||||||
| Li | Ls | MC | ni | hi | Ni_asc | Ni_dsc | Hi_dsc | Hi_dsc.1 |
|---|---|---|---|---|---|---|---|---|
| 60.6678 | 63.3496 | 62.01 | 404 | 2.269026 | 404 | 17805 | 100 | 100 |
| 63.3496 | 66.0314 | 64.69 | 254 | 1.426566 | 658 | 17401 | 97.73 | 97.73 |
| 66.0314 | 68.7132 | 67.37 | 502 | 2.819433 | 1160 | 17147 | 96.3 | 96.3 |
| 68.7132 | 71.3951 | 70.05 | 581 | 3.263128 | 1741 | 16645 | 93.48 | 93.48 |
| 71.3951 | 74.0769 | 72.74 | 943 | 5.296265 | 2684 | 16064 | 90.22 | 90.22 |
| 74.0769 | 76.7587 | 75.42 | 320 | 1.797248 | 3004 | 15121 | 84.93 | 84.93 |
| 76.7587 | 79.4405 | 78.1 | 188 | 1.055883 | 3192 | 14801 | 83.13 | 83.13 |
| 79.4405 | 82.1223 | 80.78 | 542 | 3.044089 | 3734 | 14613 | 82.07 | 82.07 |
| 82.1223 | 84.8041 | 83.46 | 426 | 2.392586 | 4160 | 14071 | 79.03 | 79.03 |
| 84.8041 | 87.4859 | 86.15 | 707 | 3.970795 | 4867 | 13645 | 76.64 | 76.64 |
| 87.4859 | 90.1677 | 88.83 | 541 | 3.038472 | 5408 | 12938 | 72.66 | 72.66 |
| 90.1677 | 92.8496 | 91.51 | 2352 | 13.209773 | 7760 | 12397 | 69.63 | 69.63 |
| 92.8496 | 95.5314 | 94.19 | 6497 | 36.489750 | 14257 | 10045 | 56.42 | 56.42 |
| 95.5314 | 98.2132 | 96.87 | 2828 | 15.883179 | 17085 | 3548 | 19.93 | 19.93 |
| 98.2132 | 100.895 | 99.55 | 720 | 4.043808 | 17805 | 720 | 4.04 | 4.04 |
| Total | 17805 | 100.000000 | ||||||
| Autor:Grupo1 | ||||||||
Creamos una nueva tabla de frecuencias con intervalos generados del histograma de R
#DETERMINACIÓN DE INTERVALOS CON R
histoLongitud<-hist(Longitud,
main= "Gráfica Nº30: Frecuencia de Longitud de los Sismos del
Subcontinente Indio ",
xlab= "Longitud",
ylab= "Cantidad", col="blue",
las=2)## [1] 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96
## [20] 98 100 102
Calculamos las frecuencias simples y acumuladas.
## [1] 17805
## [1] 100
#FRECUENCIAS ACUMULADAS
Niasc <- cumsum(ni)
Nidsc <- rev(cumsum(rev(ni)))
Hiasc <- round(cumsum(hi), 2)
Hidsc <- round(rev(cumsum(rev(hi))), 2)
TDFLongitudR<-data.frame(LimInf, LimSup, Mc, ni, hi, Niasc, Nidsc, Hiasc, Hidsc)
TDFLongitudRGeneramos una nueva tabla completa
#Agregar Totales:
totalni <- sum(ni)
totalhi <- 100
TDFLongitudCompleto<-rbind(TDFLongitudR, data.frame(LimInf="Total",
LimSup=" ", Mc=" ",ni=totalni, hi=totalhi, Niasc=" ", Nidsc=" ",
Hiasc=" ", Hidsc=" "))
print(TDFLongitudCompleto)## LimInf LimSup Mc ni hi Niasc Nidsc Hiasc Hidsc
## 1 60 62 61 217 1.2187588 217 17805 1.22 100
## 2 62 64 63 238 1.3367032 455 17588 2.56 98.78
## 3 64 66 65 199 1.1176636 654 17350 3.67 97.44
## 4 66 68 67 443 2.4880652 1097 17151 6.16 96.33
## 5 68 70 69 328 1.8421792 1425 16708 8 93.84
## 6 70 72 71 341 1.9151924 1766 16380 9.92 92
## 7 72 74 73 908 5.0996911 2674 16039 15.02 90.08
## 8 74 76 75 216 1.2131424 2890 15131 16.23 84.98
## 9 76 78 77 209 1.1738276 3099 14915 17.41 83.77
## 10 78 80 79 114 0.6402696 3213 14706 18.05 82.59
## 11 80 82 81 501 2.8138163 3714 14592 20.86 81.95
## 12 82 84 83 362 2.0331368 4076 14091 22.89 79.14
## 13 84 86 85 445 2.4992980 4521 13729 25.39 77.11
## 14 86 88 87 473 2.6565571 4994 13284 28.05 74.61
## 15 88 90 89 387 2.1735468 5381 12811 30.22 71.95
## 16 90 92 91 1013 5.6894131 6394 12424 35.91 69.78
## 17 92 94 93 3939 22.1229992 10333 11411 58.03 64.09
## 18 94 96 95 4737 26.6048863 15070 7472 84.64 41.97
## 19 96 98 97 1960 11.0081438 17030 2735 95.65 15.36
## 20 98 100 99 637 3.5776467 17667 775 99.22 4.35
## 21 100 102 101 138 0.7750632 17805 138 100 0.78
## 22 Total 17805 100.0000000
#install.packages("gt")
library(gt)
library(dplyr)
# Crear la tabla
tablaLongitud<-TDFLongitudCompleto %>%
gt() %>%
tab_header(
title = md("Tabla Nro. 11"),
subtitle = md("**Tabla de distribucion de Frecuencias simples y acumuladas
de la Longitud 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"
)
)
tablaLongitud| Tabla Nro. 11 | ||||||||
| **Tabla de distribucion de Frecuencias simples y acumuladas de la Longitud de los Sismos en el Subcontinente Indio (2000-2024) | ||||||||
| LimInf | LimSup | Mc | ni | hi | Niasc | Nidsc | Hiasc | Hidsc |
|---|---|---|---|---|---|---|---|---|
| 60 | 62 | 61 | 217 | 1.2187588 | 217 | 17805 | 1.22 | 100 |
| 62 | 64 | 63 | 238 | 1.3367032 | 455 | 17588 | 2.56 | 98.78 |
| 64 | 66 | 65 | 199 | 1.1176636 | 654 | 17350 | 3.67 | 97.44 |
| 66 | 68 | 67 | 443 | 2.4880652 | 1097 | 17151 | 6.16 | 96.33 |
| 68 | 70 | 69 | 328 | 1.8421792 | 1425 | 16708 | 8 | 93.84 |
| 70 | 72 | 71 | 341 | 1.9151924 | 1766 | 16380 | 9.92 | 92 |
| 72 | 74 | 73 | 908 | 5.0996911 | 2674 | 16039 | 15.02 | 90.08 |
| 74 | 76 | 75 | 216 | 1.2131424 | 2890 | 15131 | 16.23 | 84.98 |
| 76 | 78 | 77 | 209 | 1.1738276 | 3099 | 14915 | 17.41 | 83.77 |
| 78 | 80 | 79 | 114 | 0.6402696 | 3213 | 14706 | 18.05 | 82.59 |
| 80 | 82 | 81 | 501 | 2.8138163 | 3714 | 14592 | 20.86 | 81.95 |
| 82 | 84 | 83 | 362 | 2.0331368 | 4076 | 14091 | 22.89 | 79.14 |
| 84 | 86 | 85 | 445 | 2.4992980 | 4521 | 13729 | 25.39 | 77.11 |
| 86 | 88 | 87 | 473 | 2.6565571 | 4994 | 13284 | 28.05 | 74.61 |
| 88 | 90 | 89 | 387 | 2.1735468 | 5381 | 12811 | 30.22 | 71.95 |
| 90 | 92 | 91 | 1013 | 5.6894131 | 6394 | 12424 | 35.91 | 69.78 |
| 92 | 94 | 93 | 3939 | 22.1229992 | 10333 | 11411 | 58.03 | 64.09 |
| 94 | 96 | 95 | 4737 | 26.6048863 | 15070 | 7472 | 84.64 | 41.97 |
| 96 | 98 | 97 | 1960 | 11.0081438 | 17030 | 2735 | 95.65 | 15.36 |
| 98 | 100 | 99 | 637 | 3.5776467 | 17667 | 775 | 99.22 | 4.35 |
| 100 | 102 | 101 | 138 | 0.7750632 | 17805 | 138 | 100 | 0.78 |
| Total | 17805 | 100.0000000 | ||||||
| Autor:Grupo1 | ||||||||
#Graficas
#HISTOGRAMA LOCAL ni
hist(Longitud, main="Gráfica Nº32: Frecuencia de Longitud de los Sismos del
Subcontinente Indio (Local)", ylab="Cantidad", xlab="Longitud (°)", col="grey")#HISTOGRAMA GLOBAL ni
hist(Longitud, main="Gráfica Nº33: Frecuencia de Longitud de los Sismos del
Subcontinente Indio (Global)", ylab="Cantidad", xlab="Longitud (°)", col="grey",
ylim=c(0,length(Longitud)))#HISTOGRAMA LOCAL hi
barplot(TDFLongitudR$hi, space=0, main="Gráfica Nº34: Porcentaje de Longitud de los Sismos
del Subcontinente Indio (Local)", ylab="Porcentaje (%)", xlab="Longitud (°)",
col="grey", names.arg = TDFLongitudR$Mc)#HISTOGRAMA GLOBAL hi
barplot(TDFLongitudR$hi, space=0, main="Gráfica Nº35: Porcentaje de Longitud
de los Sismos del Subcontinente Indio (Global)",
ylab="Porcentaje (%)", xlab="Longitud (°)",
col="grey", names.arg=TDFLongitudR$Mc, ylim=c(0,100))Adicionalmente, generamos las ojivas que nos representa las frecuencias acumuladasy, de igual manera, el intercepto de las gráficas de la ojiva ascendente y la descendente representa la mediana en el eje horizontal.
Ojivas para las frecuencias absolutas acumuladas
#OJIVAS COMBINADAS DE LA FRECUENCIA Hi
plot(LimInf,Nidsc,main = "Grafica Nº36: Ojivas combinadas del Longitud de los
Sismos del Subcontinente Indio",
xlab = "Longitud",
ylab="Cantidad", col="blue",type = "b")
lines(LimSup,Niasc,col="grey",type = "b")
legend("right",legend = c("Ojiva descendente", "Ojiva ascendente"),
col = c("blue", "grey"), pch = 1, lty = 1,cex = 0.7, inset = c(0.65, 0.08))Ojivas para las frecuencias absolutas acumuladas
#OJIVAS COMBINADAS DE LA FRECUENCIA Hi
plot(LimInf,Hidsc,
main = "Grafica Nº37: Ojivas combinadas del Longitud de los
Sismos del Subcontinente Indio",
xlab = "Longitud",
ylab="Porcentaje (%)",
col="black",type = "b")
lines(LimSup,Hiasc,col="blue",type = "b")
legend("right",legend = c("Ojiva descendente", "Ojiva ascendente"),
col = c("black", "blue"), pch = 1, lty = 1,cex = 0.7, inset = c(0.65, 0.08))Los indicadores estadísticos son valores numéricos que resumen, describen y analizan características de un conjunto de datos. Estos indicadores permiten simplificar y entender grandes volúmenes de información de manera más eficiente. Se utilizan para tomar decisiones informadas.
#INDICADORES
ri<-min(Longitud)
rs<-max(Longitud)
#POSICION
#MEDIA ARITMETICA
x<-sum(Longitud)/(length(Longitud))
x## [1] 88.99298
## [1] 80.78
## [1] 9.76107
## [1] 10.96836
## Warning: package 'e1071' was built under R version 4.4.3
## [1] -1.386749
## [1] 0.6765752
Variable<-c("Longitud")
Tabla_indicadores<-data.frame(Variable,ri,rs,round(x,2),Me,round(sd,2), round(CV,2), round(As,2),
round(K,2))
colnames(Tabla_indicadores)<-c("Variable","minimo","máximo","x","Me","sd","Cv (%)","As","K")
library(knitr)
kable(Tabla_indicadores, format = "markdown", caption = "Tabla 11. Indicadores estadíticos de la variable Longitudd")## 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 |
|---|---|---|---|---|---|---|---|---|
| Longitud | 60.6678 | 100.895 | 88.99 | 80.78 | 9.76 | 10.97 | -1.39 | 0.68 |
#tabla outliers
Tabla_outliers<-data.frame(Outliers,minimo,máximo)
colnames(Tabla_outliers)<-c("Outliers","minimo ","máximo ")
library(knitr)
kable(Tabla_outliers, format = "markdown", caption = "Tabla 11.1. Outliers de la variable")## Warning in attr(x, "align"): 'xfun::attr()' está en desuso.
## Utilizar 'xfun::attr2()' en su lugar.
## Ver help("Deprecated")
## Warning in attr(x, "align"): 'xfun::attr()' está en desuso.
## Utilizar 'xfun::attr2()' en su lugar.
## Ver help("Deprecated")
| Outliers | minimo | máximo |
|---|---|---|
| 1778 | 60.6678 | 72.21 |
La variable longitud medida en grados, sus valores fluctúan desde 60.66 a 100.895, los valores están entorno a la mediana que es 80.78 grados, con una desviación estándar de 9.76, siendo un conjunto homogéneo, cuyos valores atípicos se centran en la parte izquierda desde 60.66 hasta 72.21. La acumulación de valores se encuentra en la parte alta de la variable de manera fuerte. Por todo lo anterior mencionado, es beneficioso ya que permite ubicar el epicentro de un sismo en el planeta para así identificar que áreas fueron más afectadas y como se propaga la energía sísmica.