descrip longitu — title: ‘VARIABLE CUANTITATIVA CONTINUA: LONGITUD’ author: “Geología Grupo 2” date: “r Sys.Date()” output: html_document: theme: cosmo toc: true toc_float: true toc_depth: 2 —

1. CARGA DE LIBRERIAS Y DATOS

```{r}

#Carga de Librerías library(readxl) library(dplyr) library(gt)

Cargar base de datos

datos_nuevoartes <- read_excel(“datos_nuevoartes.xlsx”)


# **2. DEFINICIÓN DE LA VARIABLE**

```{r}
longitude <- datos_nuevoartes$longitude
longitude <- longitude[!is.na(longitude)]

3. PARÁMETROS DE CLASIFICACIÓN

```{r} k_long <- 12 n_long <- length(longitude)

min_long <- min(longitude) max_long <- max(longitude)

R_long <- max_long - min_long A_real <- R_long / k_long


# **4. AJUSTE DE AMPLITUD DE CLASE**

```{r}
A_long <- ifelse(
  A_real <= 2, 2,
  ifelse(
    A_real <= 5, 5,
    ifelse(
      A_real <= 10, 10,
      ceiling(A_real / 10) * 10
    )
  )
)

5. DEFINICIÓN DE CLASES

```{r}

Li0 <- floor(min_long / A_long) * A_long

Li_long <- seq(Li0, by = A_long, length.out = k_long) Ls_long <- Li_long + A_long

MC_long <- round((Li_long + Ls_long) / 2, 2)


# **6. CÁLCULO DE FRECUENCIAS**
```{r}
ni_long <- numeric(k_long)

for (i in 1:k_long) {
  if (i < k_long) {
    ni_long[i] <- sum(longitude >= Li_long[i] & longitude < Ls_long[i])
  } else {
    ni_long[i] <- sum(longitude >= Li_long[i] & longitude <= max_long)
  }
}

hi_long <- round((ni_long / sum(ni_long)) * 100, 2)

Ni_asc_long <- cumsum(ni_long)
Ni_dsc_long <- rev(cumsum(rev(ni_long)))

Hi_asc_long <- round(cumsum(hi_long), 2)
Hi_dsc_long <- round(rev(cumsum(rev(hi_long))), 2)

7. TABLA DE FRECUENCIAS

```{r} TDF_longitude <- data.frame( Li = Li_long, Ls = Ls_long, MC = MC_long, ni = ni_long, hi = hi_long, Ni_asc = Ni_asc_long, Ni_dsc = Ni_dsc_long, Hi_asc = Hi_asc_long, Hi_dsc = Hi_dsc_long )

TDF_longitude <- rbind( TDF_longitude, data.frame( Li = “TOTAL”, Ls = ““, MC =”“, ni = sum(ni_long), hi = 100, Ni_asc =”“, Ni_dsc =”“, Hi_asc =”“, Hi_dsc =”” ) )


# **8. TABLA DE PRESENTACIÓN**
```{r}
tabla_longitude <- TDF_longitude %>%
  gt() %>%
  fmt_number(columns = MC, decimals = 2) %>%
  tab_header(
    title = md("Tabla N° 1"),
    subtitle = md("Distribución de frecuencias de Longitude (12 clases)")
  ) %>%
  tab_source_note(
    source_note = md("Autor: Grupo Geología")
  ) %>%
  tab_style(
    style = cell_text(weight = "bold"),
    locations = cells_body(rows = Li == "TOTAL")
  )

tabla_longitude

9. HISTOGRAMAS

9.1 Histograma local ni

{r} hist( longitude, breaks = c(Li_long, max(Ls_long)), right = FALSE, freq = TRUE, col = "grey", border = "black", main = "Histograma local de Longitude (ni)", xlab = "Longitude (°)", ylab = "Frecuencia absoluta (ni)" )

9.2. Histograma global ni

{r} hist( longitude, breaks = c(Li_long, max(Ls_long)), right = FALSE, freq = TRUE, col = "grey", border = "black", ylim = c(0, sum(ni_long)), main = "Histograma global de Longitude (ni)", xlab = "Longitude (°)", ylab = "Frecuencia absoluta acumulable" )

9.3. Histograma local hi

{r} hist( longitude, breaks = c(Li_long, max(Ls_long)), right = FALSE, freq = FALSE, # <- frecuencia relativa col = "grey", border = "black", main = "Histograma local de Longitude (hi)", xlab = "Longitude (°)", ylab = "Frecuencia relativa" )

9.4. Histograma global hi

{r} hist( longitude, breaks = c(Li_long, max(Ls_long)), right = FALSE, freq = FALSE, # <- frecuencia relativa col = "grey", border = "black", ylim = c(0, max(hi_long) / 100 * 1.2), main = "Histograma global de Longitude (hi)", xlab = "Longitude (°)", ylab = "Frecuencia relativa" )

10. DIAGRAMA DE OJIVAS

```{r} plot( Ls_long, Ni_asc_long, type = “o”, pch = 19, col = “blue”, ylim = c(0, max(Ni_asc_long)), main = “Ojiva combinada de Longitude”, xlab = “Límites de clase (°)”, ylab = “Frecuencia acumulada” )

lines( Li_long, Ni_dsc_long, type = “o”, pch = 17, col = “red” ) legend( “right”, legend = c(“Ojiva ascendente (Ni ≤)”, “Ojiva descendente (Ni ≥)”), col = c(“blue”, “red”), pch = c(19, 17), lty = 1, cex = 0.8, bty = “b” )


# **11. DIAGRAMA DE CAJAS**

```{r}
boxplot(
  longitude,
  horizontal = TRUE,
  col = "grey",
  border = "black",
  main = "Diagrama de caja de Longitude (con outliers)",
  xlab = "Longitude (°)",
  outline = TRUE,        # asegura que se muestren los outliers
  pch = 19,              # símbolo de los outliers
  outcol = "red"         # color de los outliers
)

12. INDICADORES ESTADÍSTICOS

```{r} ri <- -180 rs <- 180 x <- mean(longitude) Me <- median(longitude)

Mo <- as.numeric( names(sort(table(round(longitude, 1)), decreasing = TRUE)[1]) )

sd_long <- sd(longitude) CV <- (sd_long / x) * 100

As <- mean((longitude - x)^3) / sd_long^3 K <- mean((longitude - x)^4) / sd_long^4 - 3


## 12.1. Tabla de indicadores

```{r}
TablaIndicadores_longitude <- data.frame(
  Var = "Longitude",
  ri = ri,
  rs = rs,
  x  = round(x, 2),
  Me = round(Me, 2),
  Mo = round(Mo, 2),
  sd = round(sd_long, 2),
  CV = round(CV, 2),
  As = round(As, 2),
  K  = round(K, 2)
)

tabla_longitude_indicadores <- TablaIndicadores_longitude %>%
  gt() %>%
  tab_header(
    title = md("Tabla N° X"),
    subtitle = md("Indicadores estadísticos de la variable Longitude")
  ) %>%
  tab_source_note(
    source_note = md("Autor: Grupo Geología")
  )

tabla_longitude_indicadores

13. DETECCIÓN DE OUTLIERS – VARIABLE LONGITUDE (IQR)

13.1. CUARTILES E IQR

{r} Q1 <- quantile(longitude, 0.25) Q3 <- quantile(longitude, 0.75) IQR_long <- Q3 - Q1

13.2. LÍMITES DE OUTLIERS

{r} minimo <- Q1 - 1.5 * IQR_long maximo <- Q3 + 1.5 * IQR_long

13.3. IDENTIFICAR OUTLIERS

```{r} outliers <- longitude[longitude < minimo | longitude > maximo]

n_outliers <- length(outliers)


## 13.4. TABLA DE OUTLIERS

```{r}
Tabla_outliers <- data.frame(
  Outliers = ifelse(n_outliers == 0, "No se detectan", n_outliers),
  minimo   = round(minimo, 2),
  máximo   = round(maximo, 2)
)

13.5. TABLA PRESENTACIÓN

```{r} tabla_outliers_gt <- Tabla_outliers %>% gt() %>% tab_header( title = md(“Tabla 11.1”), subtitle = md(“Detección de outliers – Variable Longitude (método IQR)”) ) %>% cols_label( Outliers = “Outliers”, minimo = “Límite inferior”, máximo = “Límite superior” ) %>% tab_source_note( source_note = md(“Autor: Grupo Geología”) ) %>% tab_options( table.border.top.color = “black”, table.border.bottom.color = “black”, column_labels.border.bottom.color = “black”, heading.border.bottom.color = “black” )

tabla_outliers_gt ``` # 14. CONCLUSIÓN