ANÁLISIS ESTADÍSTICO

1. CARGA DE DATOS Y LIBRERÍAS

library(knitr)
library(dplyr)

setwd("C:/Users/HP/Documents/PROYECTO ESTADISTICA/RStudio")
datos <- read.csv("tablap.csv", header = TRUE, dec = ",", sep = ";")

2. TABLA DE DISTRIBUCION

# Procesamiento de la variable
Complejidad_raw <- datos$Complexity.of.the.casing.structure
Complejidad_limpia <- Complejidad_raw[!is.na(Complejidad_raw)]

Complejidad <- factor(
  Complejidad_limpia,
  levels = as.character(0:7),
  ordered = TRUE
)

# Generar frecuencias
ni_table <- table(Complejidad)
hi_table <- round(prop.table(ni_table) * 100, 2)

tabla_complejidad <- data.frame(
  Nivel = names(ni_table),
  ni = as.numeric(ni_table),
  hi = as.numeric(hi_table)
)

fila_total <- data.frame(
  Nivel = "TOTAL",
  ni = sum(tabla_complejidad$ni),
  hi = round(sum(tabla_complejidad$hi))
)

tabla_final_p <- rbind(tabla_complejidad, fila_total)

kable(tabla_final_p, format = "markdown", 
      caption = "Tabla N 1. Distribución de cantidad por nivel de complejidad del revestimiento")
Tabla N 1. Distribución de cantidad por nivel de complejidad del revestimiento
Nivel ni hi
0 2476 19.71
1 33 0.26
2 5383 42.85
3 4138 32.94
4 503 4.00
5 25 0.20
6 2 0.02
7 1 0.01
TOTAL 12561 100.00

3. GRAFICAS DE DISTRIBUCION

color_barras_abs <- "#76D7C4" 
color_barras_rel <- "#F1948A" 

# Gráfica N 1
barplot(
  tabla_complejidad$ni,
  main = "Gráfica N 1: Distribución de cantidad de complejidad de revestimiento\nen pozos de gas natural",
  cex.main = 1.1, col = color_barras_abs, border = "white",
  xlab = "Nivel de Complejidad", ylab = "Cantidad (ni)",
  names.arg = tabla_complejidad$Nivel)

# Gráfica N 2
barplot(
  tabla_complejidad$ni,
  main = "Gráfica N 2: Distribución de cantidad de complejidad de revestimiento\nen pozos de gas natural",
  cex.main = 1.1, col = color_barras_abs, border = "white",
  xlab = "Nivel de Complejidad", ylab = "Cantidad (ni)",
  names.arg = tabla_complejidad$Nivel,
  ylim = c(0, 12561))

# Gráfica N 3
barplot(
  tabla_complejidad$hi,
  main = "Gráfica N 3: Distribución porcentual del nivel de complejidad de\nrevestimiento en pozos de gas natural",
  cex.main = 1.1, col = color_barras_rel, border = "white",
  xlab = "Nivel de Complejidad", ylab = "Porcentaje (%)",
  names.arg = tabla_complejidad$Nivel)

# Gráfica N 4
barplot(
  tabla_complejidad$hi,
  main = "Gráfica N 4: Distribución porcentual del nivel de complejidad de\nrevestimiento en pozos de gas natural",
  cex.main = 1.1, col = color_barras_rel, border = "white",
  xlab = "Nivel de Complejidad", ylab = "Porcentaje (%)",
  names.arg = tabla_complejidad$Nivel,
  ylim = c(0, 100))

# Gráfica N 5: Diagrama Circular
Colores_pie <- colorRampPalette(c("#82E0AA", "#F8C471", "#BB8FCE"))
etiquetas <- paste0(round(tabla_complejidad$hi), "%")

pie(
  tabla_complejidad$hi,
  radius = 1.0,
  col = Colores_pie(nrow(tabla_complejidad)),
  labels = etiquetas,
  main = "Gráfica Nº 5: Distribución porcentual de complejidad de\nrevestimiento en pozos de gas natural",
  cex.main = 1.1,
  border = "white"
)

legend(
  "bottomright",
  title = "Niveles",
  legend = tabla_complejidad$Nivel,
  fill = Colores_pie(nrow(tabla_complejidad)),
  cex = 1.1,
  bty = "n"
)

4. INDICADORES ESTADISTICOS

4.1 MODA

# Moda
moda_complejidad <- tabla_complejidad$Nivel[which.max(tabla_complejidad$ni)]
cat("La moda es:", moda_complejidad, "\n")
## La moda es: 2

4.2 MEDIANA

# Mediana
Complejidad_ordenada <- sort(Complejidad)
Me <- Complejidad_ordenada[ceiling(length(Complejidad_ordenada) / 2)]
cat("La mediana es:", as.character(Me))
## La mediana es: 2

5. TABLA DE INDICADORES ESTADISTICOS

Variable <- c("Complejidad de Revestimiento")
TablaIndicadores <- data.frame(
  Variable, 
  Moda = moda_complejidad, 
  Mediana = as.character(Me)
)
colnames(TablaIndicadores) <- c("Variable", "Moda", "Mediana")

kable(TablaIndicadores, format = "markdown", 
      caption = "Tabla N 2. Indicadores estadísticos de la variable complejidad de revestimiento")
Tabla N 2. Indicadores estadísticos de la variable complejidad de revestimiento
Variable Moda Mediana
Complejidad de Revestimiento 2 2

6. CONCLUSIÓN

## La variable de complejidad del revestimiento presenta una mayor frecuencia en el nivel: 2 mientras que su mediana se sitúa en el nivel: 2