candidatos <- c(
"SUM_HardOrSoft_PlasticBottleCap", "sum_taplst",
"Suma_Tapas_Plástico", "Suma_Tapas_Plastico"
)
encontrados <- intersect(candidatos, names(datos))
col_v7 <- if (length(encontrados) > 0) encontrados[1] else names(datos)[1]
sum_taplst <- as.integer(round(suppressWarnings(as.numeric(datos[[col_v7]]))))
sum_taplst <- sum_taplst[!is.na(sum_taplst) & is.finite(sum_taplst) & sum_taplst >= 0]valores <- seq(from = min(sum_taplst), to = max(sum_taplst), by = 1)
ni <- as.integer(table(factor(sum_taplst, levels = valores)))
total_n <- sum(ni)
hi <- ni / total_n
porcentaje <- hi * 100
Ni_asc <- cumsum(ni)
Ni_desc <- rev(cumsum(rev(ni)))
Hi_asc_pct <- cumsum(porcentaje)
Hi_desc_pct <- rev(cumsum(rev(porcentaje)))tabla_freq <- data.frame(
Valor = as.character(valores),
ni = as.character(ni),
hi = sprintf("%.4f", hi),
`hi (%)` = sprintf("%.2f", porcentaje),
Ni_asc = as.character(Ni_asc),
`Hi (%)` = sprintf("%.2f", Hi_asc_pct),
check.names = FALSE
)
fila_total <- data.frame(
Valor = "Total",
ni = as.character(total_n),
hi = sprintf("%.4f", sum(hi)),
`hi (%)` = sprintf("%.2f", sum(porcentaje)),
Ni_asc = as.character(max(Ni_asc)),
`Hi (%)` = sprintf("%.2f", max(Hi_asc_pct)),
check.names = FALSE
)
kable(rbind(tabla_freq, fila_total), align = "c")| Valor | ni | hi | hi (%) | Ni_asc | Hi (%) |
|---|---|---|---|---|---|
| 0 | 10 | 0.0400 | 4.00 | 10 | 4.00 |
| 1 | 9 | 0.0360 | 3.60 | 19 | 7.60 |
| 2 | 9 | 0.0360 | 3.60 | 28 | 11.20 |
| 3 | 12 | 0.0480 | 4.80 | 40 | 16.00 |
| 4 | 5 | 0.0200 | 2.00 | 45 | 18.00 |
| 5 | 7 | 0.0280 | 2.80 | 52 | 20.80 |
| 6 | 8 | 0.0320 | 3.20 | 60 | 24.00 |
| 7 | 7 | 0.0280 | 2.80 | 67 | 26.80 |
| 8 | 6 | 0.0240 | 2.40 | 73 | 29.20 |
| 9 | 12 | 0.0480 | 4.80 | 85 | 34.00 |
| 10 | 7 | 0.0280 | 2.80 | 92 | 36.80 |
| 11 | 15 | 0.0600 | 6.00 | 107 | 42.80 |
| 12 | 16 | 0.0640 | 6.40 | 123 | 49.20 |
| 13 | 7 | 0.0280 | 2.80 | 130 | 52.00 |
| 14 | 7 | 0.0280 | 2.80 | 137 | 54.80 |
| 15 | 10 | 0.0400 | 4.00 | 147 | 58.80 |
| 16 | 9 | 0.0360 | 3.60 | 156 | 62.40 |
| 17 | 9 | 0.0360 | 3.60 | 165 | 66.00 |
| 18 | 13 | 0.0520 | 5.20 | 178 | 71.20 |
| 19 | 12 | 0.0480 | 4.80 | 190 | 76.00 |
| 20 | 7 | 0.0280 | 2.80 | 197 | 78.80 |
| 21 | 11 | 0.0440 | 4.40 | 208 | 83.20 |
| 22 | 8 | 0.0320 | 3.20 | 216 | 86.40 |
| 23 | 15 | 0.0600 | 6.00 | 231 | 92.40 |
| 24 | 11 | 0.0440 | 4.40 | 242 | 96.80 |
| 25 | 8 | 0.0320 | 3.20 | 250 | 100.00 |
| Total | 250 | 1.0000 | 100.00 | 250 | 100.00 |
las_ejes <- if (length(valores) <= 20) 1 else 2
barplot(ni, names.arg = valores, col = "skyblue3", las = las_ejes,
main = "5.1 Frecuencia absoluta (ni) - Suma_Tapas_Plástico",
xlab = "Suma_Tapas_Plástico (Unidades: ítems / fragmentos)", ylab = "ni",
ylim = c(0, max(ni) * 1.15))
grid(nx = NA, ny = NULL, col = "gray85", lty = "dotted")barplot(ni, names.arg = valores, col = "skyblue3", las = las_ejes,
main = "5.2 Frecuencia respecto al total - Suma_Tapas_Plástico",
xlab = "Suma_Tapas_Plástico (Unidades: ítems / fragmentos)", ylab = "ni",
ylim = c(0, total_n))
grid(nx = NA, ny = NULL, col = "gray85", lty = "dotted")barplot(porcentaje, names.arg = valores, col = "steelblue3", las = las_ejes,
main = "5.3 Porcentaje (%) - Suma_Tapas_Plástico",
xlab = "Suma_Tapas_Plástico (Unidades: ítems / fragmentos)", ylab = "Porcentaje (%)",
ylim = c(0, max(porcentaje) * 1.15))
grid(nx = NA, ny = NULL, col = "gray85", lty = "dotted")barplot(porcentaje, names.arg = valores, col = "steelblue3", las = las_ejes,
main = "5.4 Porcentaje respecto a 100% - Suma_Tapas_Plástico",
xlab = "Suma_Tapas_Plástico (Unidades: ítems / fragmentos)", ylab = "Porcentaje (%)",
ylim = c(0, 100))
grid(nx = NA, ny = NULL, col = "gray85", lty = "dotted")boxplot(sum_taplst, horizontal = TRUE, col = "#76D7C4", border = "black", pch = 19,
main = "6. Diagrama de caja horizontal - Suma_Tapas_Plástico",
xlab = "Suma_Tapas_Plástico (Unidades: ítems / fragmentos)")
grid()plot(valores, Ni_asc, type = "b", col = "orange", pch = 19, lwd = 2,
ylim = c(0, total_n), main = "7.1 Ojivas absolutas - Suma_Tapas_Plástico",
xlab = "Suma_Tapas_Plástico (Unidades: ítems / fragmentos)", ylab = "Frecuencia acumulada (Ni)")
lines(valores, Ni_desc, type = "b", col = "blue", pch = 19, lwd = 2)
grid(col = "gray85", lty = 1)
legend("topleft", legend = c("Ascendente", "Descendente"),
col = c("orange", "blue"), pch = 19, lty = 1, lwd = 2, bg = "white")plot(valores, Hi_asc_pct, type = "b", col = "orange", pch = 19, lwd = 2,
ylim = c(0, 100), main = "7.2 Ojivas porcentuales - Suma_Tapas_Plástico",
xlab = "Suma_Tapas_Plástico (Unidades: ítems / fragmentos)", ylab = "Porcentaje acumulado (%)")
lines(valores, Hi_desc_pct, type = "b", col = "blue", pch = 19, lwd = 2)
grid(col = "gray85", lty = 1)
legend("topleft", legend = c("Ascendente (%)", "Descendente (%)"),
col = c("orange", "blue"), pch = 19, lty = 1, lwd = 2, bg = "white")media_v7 <- mean(sum_taplst)
mediana_v7 <- median(sum_taplst)
moda_v7 <- paste(names(which(table(sum_taplst) == max(table(sum_taplst)))), collapse = ", ")
rango_v7 <- paste0(min(sum_taplst), " - ", max(sum_taplst))
q1_v7 <- quantile(sum_taplst, 0.25)
q3_v7 <- quantile(sum_taplst, 0.75)
ric_v7 <- IQR(sum_taplst)
atip_v7 <- unique(sum_taplst[sum_taplst < (q1_v7 - 1.5 * ric_v7) | sum_taplst > (q3_v7 + 1.5 * ric_v7)])
atip_txt <- if (length(atip_v7) == 0) "No existen" else paste(sort(atip_v7), collapse = ", ")
indicadores_v7 <- data.frame(
Indicador = c("Media", "Mediana", "Moda", "Rango", "Varianza", "Desviación estándar", "Asimetría", "Curtosis", "Valores atípicos"),
Valor = c(
sprintf("%.2f", media_v7),
sprintf("%.2f", mediana_v7),
moda_v7,
rango_v7,
sprintf("%.2f", var(sum_taplst)),
sprintf("%.2f", sd(sum_taplst)),
sprintf("%.2f", skewness(sum_taplst, type = 2)),
sprintf("%.2f", kurtosis(sum_taplst)),
atip_txt
),
stringsAsFactors = FALSE
)
kable(indicadores_v7, align = "c")| Indicador | Valor |
|---|---|
| Media | 13.01 |
| Mediana | 13.00 |
| Moda | 12 |
| Rango | 0 - 25 |
| Varianza | 56.06 |
| Desviación estándar | 7.49 |
| Asimetría | -0.12 |
| Curtosis | -1.17 |
| Valores atípicos | No existen |
cat(paste0(
"En **n = ", total_n, "** registros válidos de **Suma_Tapas_Plástico** (`sum_taplst`), la cantidad de tapas de plástico rígido o blando recolectadas fluctúa entre **",
min(sum_taplst), "** y **", max(sum_taplst), "**, con media de **", sprintf("%.2f", media_v7),
"**, mediana de **", sprintf("%.2f", mediana_v7), "**, moda en **", moda_v7,
"** y desviación estándar de **", sprintf("%.2f", sd(sum_taplst)), "**. Valores atípicos: **", atip_txt, "**."
))En n = 250 registros válidos de
Suma_Tapas_Plástico (sum_taplst), la
cantidad de tapas de plástico rígido o blando recolectadas fluctúa entre
0 y 25, con media de
13.01, mediana de 13.00, moda en
12 y desviación estándar de 7.49.
Valores atípicos: No existen.