#------------------ UNIVERSIDAD CENTRAL DEL ECUADOR
##-----Facultad de Ingeniería en Geología, Minas, Petróleos y Ambiental 
###-----------------Carrera de Ingeniería Ambiental

# Proyecto: Estudio de Residuos y Reciclaje en la India
# Etapa: Estadistica Descriptiva
# Integrantes: Jazmin Guañuna, Nayely Perugachi, Helen Taipe, Gabriela Usiña
# Fecha: 26/5/2025

#VARIABLE CUALITATIVA ORDINAL: TIPO DE RESIDUO

#Carga de datos
library(readr)

datos <- read.csv("Waste_Management_and_Recycling_India.csv",,
                  header = TRUE,
                  sep = ",",
                  dec = ".")
str(datos)
## 'data.frame':    850 obs. of  13 variables:
##  $ City.District                    : chr  "Mumbai" "Mumbai" "Mumbai" "Mumbai" ...
##  $ Waste.Type                       : chr  "Plastic" "Organic" "E-Waste" "Construction" ...
##  $ Waste.Generated..Tons.Day.       : int  6610 1181 8162 8929 5032 7456 7118 9189 8609 6632 ...
##  $ Recycling.Rate....               : int  68 56 53 56 44 73 37 57 48 71 ...
##  $ Population.Density..People.km..  : int  11191 11191 11191 11191 11191 11191 11191 11191 11191 11191 ...
##  $ Municipal.Efficiency.Score..1.10.: int  9 5 8 5 7 9 6 10 8 6 ...
##  $ Disposal.Method                  : chr  "Composting" "Composting" "Incineration" "Landfill" ...
##  $ Cost.of.Waste.Management....Ton. : int  3056 2778 3390 1498 2221 3195 3686 1791 1681 2311 ...
##  $ Awareness.Campaigns.Count        : int  14 12 13 14 16 6 14 12 20 12 ...
##  $ Landfill.Name                    : chr  "Mumbai Landfill" "Mumbai Landfill" "Mumbai Landfill" "Mumbai Landfill" ...
##  $ Landfill.Location..Lat..Long.    : chr  "22.4265, 77.4931" "22.4265, 77.4931" "22.4265, 77.4931" "22.4265, 77.4931" ...
##  $ Landfill.Capacity..Tons.         : int  45575 45575 45575 45575 45575 45575 45575 45575 45575 45575 ...
##  $ Year                             : int  2019 2019 2019 2019 2019 2020 2020 2020 2020 2020 ...
# ORDENAR NIVELES
orden_residuos <- c("Organic", "Plastic", "Construction", "E-Waste", "Hazardous")

# Extraer Variable Ordinal
tipo_residuo_ordenado <- factor(datos$Waste.Type,
                                levels = orden_residuos,
                                ordered = TRUE)
tipo_residuo_ordenado
##   [1] Plastic      Organic      E-Waste      Construction Hazardous   
##   [6] Plastic      Organic      E-Waste      Construction Hazardous   
##  [11] Plastic      Organic      E-Waste      Construction Hazardous   
##  [16] Plastic      Organic      E-Waste      Construction Hazardous   
##  [21] Plastic      Organic      E-Waste      Construction Hazardous   
##  [26] Plastic      Organic      E-Waste      Construction Hazardous   
##  [31] Plastic      Organic      E-Waste      Construction Hazardous   
##  [36] Plastic      Organic      E-Waste      Construction Hazardous   
##  [41] Plastic      Organic      E-Waste      Construction Hazardous   
##  [46] Plastic      Organic      E-Waste      Construction Hazardous   
##  [51] Plastic      Organic      E-Waste      Construction Hazardous   
##  [56] Plastic      Organic      E-Waste      Construction Hazardous   
##  [61] Plastic      Organic      E-Waste      Construction Hazardous   
##  [66] Plastic      Organic      E-Waste      Construction Hazardous   
##  [71] Plastic      Organic      E-Waste      Construction Hazardous   
##  [76] Plastic      Organic      E-Waste      Construction Hazardous   
##  [81] Plastic      Organic      E-Waste      Construction Hazardous   
##  [86] Plastic      Organic      E-Waste      Construction Hazardous   
##  [91] Plastic      Organic      E-Waste      Construction Hazardous   
##  [96] Plastic      Organic      E-Waste      Construction Hazardous   
## [101] Plastic      Organic      E-Waste      Construction Hazardous   
## [106] Plastic      Organic      E-Waste      Construction Hazardous   
## [111] Plastic      Organic      E-Waste      Construction Hazardous   
## [116] Plastic      Organic      E-Waste      Construction Hazardous   
## [121] Plastic      Organic      E-Waste      Construction Hazardous   
## [126] Plastic      Organic      E-Waste      Construction Hazardous   
## [131] Plastic      Organic      E-Waste      Construction Hazardous   
## [136] Plastic      Organic      E-Waste      Construction Hazardous   
## [141] Plastic      Organic      E-Waste      Construction Hazardous   
## [146] Plastic      Organic      E-Waste      Construction Hazardous   
## [151] Plastic      Organic      E-Waste      Construction Hazardous   
## [156] Plastic      Organic      E-Waste      Construction Hazardous   
## [161] Plastic      Organic      E-Waste      Construction Hazardous   
## [166] Plastic      Organic      E-Waste      Construction Hazardous   
## [171] Plastic      Organic      E-Waste      Construction Hazardous   
## [176] Plastic      Organic      E-Waste      Construction Hazardous   
## [181] Plastic      Organic      E-Waste      Construction Hazardous   
## [186] Plastic      Organic      E-Waste      Construction Hazardous   
## [191] Plastic      Organic      E-Waste      Construction Hazardous   
## [196] Plastic      Organic      E-Waste      Construction Hazardous   
## [201] Plastic      Organic      E-Waste      Construction Hazardous   
## [206] Plastic      Organic      E-Waste      Construction Hazardous   
## [211] Plastic      Organic      E-Waste      Construction Hazardous   
## [216] Plastic      Organic      E-Waste      Construction Hazardous   
## [221] Plastic      Organic      E-Waste      Construction Hazardous   
## [226] Plastic      Organic      E-Waste      Construction Hazardous   
## [231] Plastic      Organic      E-Waste      Construction Hazardous   
## [236] Plastic      Organic      E-Waste      Construction Hazardous   
## [241] Plastic      Organic      E-Waste      Construction Hazardous   
## [246] Plastic      Organic      E-Waste      Construction Hazardous   
## [251] Plastic      Organic      E-Waste      Construction Hazardous   
## [256] Plastic      Organic      E-Waste      Construction Hazardous   
## [261] Plastic      Organic      E-Waste      Construction Hazardous   
## [266] Plastic      Organic      E-Waste      Construction Hazardous   
## [271] Plastic      Organic      E-Waste      Construction Hazardous   
## [276] Plastic      Organic      E-Waste      Construction Hazardous   
## [281] Plastic      Organic      E-Waste      Construction Hazardous   
## [286] Plastic      Organic      E-Waste      Construction Hazardous   
## [291] Plastic      Organic      E-Waste      Construction Hazardous   
## [296] Plastic      Organic      E-Waste      Construction Hazardous   
## [301] Plastic      Organic      E-Waste      Construction Hazardous   
## [306] Plastic      Organic      E-Waste      Construction Hazardous   
## [311] Plastic      Organic      E-Waste      Construction Hazardous   
## [316] Plastic      Organic      E-Waste      Construction Hazardous   
## [321] Plastic      Organic      E-Waste      Construction Hazardous   
## [326] Plastic      Organic      E-Waste      Construction Hazardous   
## [331] Plastic      Organic      E-Waste      Construction Hazardous   
## [336] Plastic      Organic      E-Waste      Construction Hazardous   
## [341] Plastic      Organic      E-Waste      Construction Hazardous   
## [346] Plastic      Organic      E-Waste      Construction Hazardous   
## [351] Plastic      Organic      E-Waste      Construction Hazardous   
## [356] Plastic      Organic      E-Waste      Construction Hazardous   
## [361] Plastic      Organic      E-Waste      Construction Hazardous   
## [366] Plastic      Organic      E-Waste      Construction Hazardous   
## [371] Plastic      Organic      E-Waste      Construction Hazardous   
## [376] Plastic      Organic      E-Waste      Construction Hazardous   
## [381] Plastic      Organic      E-Waste      Construction Hazardous   
## [386] Plastic      Organic      E-Waste      Construction Hazardous   
## [391] Plastic      Organic      E-Waste      Construction Hazardous   
## [396] Plastic      Organic      E-Waste      Construction Hazardous   
## [401] Plastic      Organic      E-Waste      Construction Hazardous   
## [406] Plastic      Organic      E-Waste      Construction Hazardous   
## [411] Plastic      Organic      E-Waste      Construction Hazardous   
## [416] Plastic      Organic      E-Waste      Construction Hazardous   
## [421] Plastic      Organic      E-Waste      Construction Hazardous   
## [426] Plastic      Organic      E-Waste      Construction Hazardous   
## [431] Plastic      Organic      E-Waste      Construction Hazardous   
## [436] Plastic      Organic      E-Waste      Construction Hazardous   
## [441] Plastic      Organic      E-Waste      Construction Hazardous   
## [446] Plastic      Organic      E-Waste      Construction Hazardous   
## [451] Plastic      Organic      E-Waste      Construction Hazardous   
## [456] Plastic      Organic      E-Waste      Construction Hazardous   
## [461] Plastic      Organic      E-Waste      Construction Hazardous   
## [466] Plastic      Organic      E-Waste      Construction Hazardous   
## [471] Plastic      Organic      E-Waste      Construction Hazardous   
## [476] Plastic      Organic      E-Waste      Construction Hazardous   
## [481] Plastic      Organic      E-Waste      Construction Hazardous   
## [486] Plastic      Organic      E-Waste      Construction Hazardous   
## [491] Plastic      Organic      E-Waste      Construction Hazardous   
## [496] Plastic      Organic      E-Waste      Construction Hazardous   
## [501] Plastic      Organic      E-Waste      Construction Hazardous   
## [506] Plastic      Organic      E-Waste      Construction Hazardous   
## [511] Plastic      Organic      E-Waste      Construction Hazardous   
## [516] Plastic      Organic      E-Waste      Construction Hazardous   
## [521] Plastic      Organic      E-Waste      Construction Hazardous   
## [526] Plastic      Organic      E-Waste      Construction Hazardous   
## [531] Plastic      Organic      E-Waste      Construction Hazardous   
## [536] Plastic      Organic      E-Waste      Construction Hazardous   
## [541] Plastic      Organic      E-Waste      Construction Hazardous   
## [546] Plastic      Organic      E-Waste      Construction Hazardous   
## [551] Plastic      Organic      E-Waste      Construction Hazardous   
## [556] Plastic      Organic      E-Waste      Construction Hazardous   
## [561] Plastic      Organic      E-Waste      Construction Hazardous   
## [566] Plastic      Organic      E-Waste      Construction Hazardous   
## [571] Plastic      Organic      E-Waste      Construction Hazardous   
## [576] Plastic      Organic      E-Waste      Construction Hazardous   
## [581] Plastic      Organic      E-Waste      Construction Hazardous   
## [586] Plastic      Organic      E-Waste      Construction Hazardous   
## [591] Plastic      Organic      E-Waste      Construction Hazardous   
## [596] Plastic      Organic      E-Waste      Construction Hazardous   
## [601] Plastic      Organic      E-Waste      Construction Hazardous   
## [606] Plastic      Organic      E-Waste      Construction Hazardous   
## [611] Plastic      Organic      E-Waste      Construction Hazardous   
## [616] Plastic      Organic      E-Waste      Construction Hazardous   
## [621] Plastic      Organic      E-Waste      Construction Hazardous   
## [626] Plastic      Organic      E-Waste      Construction Hazardous   
## [631] Plastic      Organic      E-Waste      Construction Hazardous   
## [636] Plastic      Organic      E-Waste      Construction Hazardous   
## [641] Plastic      Organic      E-Waste      Construction Hazardous   
## [646] Plastic      Organic      E-Waste      Construction Hazardous   
## [651] Plastic      Organic      E-Waste      Construction Hazardous   
## [656] Plastic      Organic      E-Waste      Construction Hazardous   
## [661] Plastic      Organic      E-Waste      Construction Hazardous   
## [666] Plastic      Organic      E-Waste      Construction Hazardous   
## [671] Plastic      Organic      E-Waste      Construction Hazardous   
## [676] Plastic      Organic      E-Waste      Construction Hazardous   
## [681] Plastic      Organic      E-Waste      Construction Hazardous   
## [686] Plastic      Organic      E-Waste      Construction Hazardous   
## [691] Plastic      Organic      E-Waste      Construction Hazardous   
## [696] Plastic      Organic      E-Waste      Construction Hazardous   
## [701] Plastic      Organic      E-Waste      Construction Hazardous   
## [706] Plastic      Organic      E-Waste      Construction Hazardous   
## [711] Plastic      Organic      E-Waste      Construction Hazardous   
## [716] Plastic      Organic      E-Waste      Construction Hazardous   
## [721] Plastic      Organic      E-Waste      Construction Hazardous   
## [726] Plastic      Organic      E-Waste      Construction Hazardous   
## [731] Plastic      Organic      E-Waste      Construction Hazardous   
## [736] Plastic      Organic      E-Waste      Construction Hazardous   
## [741] Plastic      Organic      E-Waste      Construction Hazardous   
## [746] Plastic      Organic      E-Waste      Construction Hazardous   
## [751] Plastic      Organic      E-Waste      Construction Hazardous   
## [756] Plastic      Organic      E-Waste      Construction Hazardous   
## [761] Plastic      Organic      E-Waste      Construction Hazardous   
## [766] Plastic      Organic      E-Waste      Construction Hazardous   
## [771] Plastic      Organic      E-Waste      Construction Hazardous   
## [776] Plastic      Organic      E-Waste      Construction Hazardous   
## [781] Plastic      Organic      E-Waste      Construction Hazardous   
## [786] Plastic      Organic      E-Waste      Construction Hazardous   
## [791] Plastic      Organic      E-Waste      Construction Hazardous   
## [796] Plastic      Organic      E-Waste      Construction Hazardous   
## [801] Plastic      Organic      E-Waste      Construction Hazardous   
## [806] Plastic      Organic      E-Waste      Construction Hazardous   
## [811] Plastic      Organic      E-Waste      Construction Hazardous   
## [816] Plastic      Organic      E-Waste      Construction Hazardous   
## [821] Plastic      Organic      E-Waste      Construction Hazardous   
## [826] Plastic      Organic      E-Waste      Construction Hazardous   
## [831] Plastic      Organic      E-Waste      Construction Hazardous   
## [836] Plastic      Organic      E-Waste      Construction Hazardous   
## [841] Plastic      Organic      E-Waste      Construction Hazardous   
## [846] Plastic      Organic      E-Waste      Construction Hazardous   
## Levels: Organic < Plastic < Construction < E-Waste < Hazardous
# TDF
TDF_tipo_residuo_ordenado <- table(tipo_residuo_ordenado)
Tablafinal <- as.data.frame((TDF_tipo_residuo_ordenado))
hi <- (Tablafinal$Freq/sum(Tablafinal$Freq))*100
sum(hi)
## [1] 100
Tablafinal <- data.frame(Tablafinal, round(hi,2))
names(Tablafinal) <- c("Tipo_Residuo","ni","hi(%)")

# Crear la fila del total asegurando que los nombres coincidan
fila_total <- data.frame(
  Tipo_Residuo = "Total",
  ni = sum(Tablafinal$ni),
  hi = sum(Tablafinal$hi)
)


# Asegurar que los nombres de las columnas coincidan exactamente
names(fila_total) <- names(Tablafinal)

# Combinar con la tabla original
Tablafinal_con_total <- rbind(Tablafinal, fila_total)

# Mostrar Tabla Final
Tablafinal_con_total
##   Tipo_Residuo  ni hi(%)
## 1      Organic 170    20
## 2      Plastic 170    20
## 3 Construction 170    20
## 4      E-Waste 170    20
## 5    Hazardous 170    20
## 6        Total 850   100
#GDF LOCAL ni
barplot(Tablafinal$ni, main = "Gráfica No.16: 
Distribución de la Cantidad de Tipo de Residuo 
        en el Estudio de Residuos de la India",
        xlab = "Tipo de Residuo",
        ylab = "Cantidad",
        col = "blue3",
        names.arg = Tablafinal$Tipo_Residuo,
        las=1)

#GDF GLOBAL ni
barplot(Tablafinal$ni, main = "Gráfica No.17: 
Distribución de la Cantidad de Tipo de Residuo 
        en el Estudio de Residuos de la India",
        xlab = "Tipo de Residuo",
        ylab = "Cantidad", 
        col = "purple3",
        names.arg = Tablafinal$Tipo_Residuo,
        ylim = c(0,850),las=1)

#GDF LOCAL hi
barplot(Tablafinal$hi, main = "Gráfica No.18: 
Distribución del Porcentaje de Tipo de Residuo 
        en el Estudio de Residuos de la India",
        xlab = "Tipo de Residuo",
        ylab = "Porcentaje (%)", 
        col = "blue3",
        names.arg = Tablafinal$Tipo_Residuo,las=1)

#GDF GLOBAL hi
barplot(Tablafinal$hi,main="Gráfica No.19: 
Distribución del Porcentaje de Tipo de Residuo 
        en el Estudio de Residuos de la India",
        xlab = "Tipo de Residuo ",
        ylab = "Porcentaje(%)",
        names.arg = Tablafinal$Tipo_Residuo,las=1,
        col = "purple3",
        ylim=c(0,100))

#DIAGRAMA CIRCULAR
library(RColorBrewer)
colores <- brewer.pal(n = length(Tablafinal$`hi(%)`), name = "Set3")
pie(Tablafinal$hi,
    labels = paste(Tablafinal$hi,"%"),
    col=colores,
    main = "Gráfica No.20: 
    Porcentaje del Tipo de Residuo 
    en el Estudio de Residuos de la India")
legend("topright",legend=Tablafinal$Tipo_Residuo,
       fill = colores,
       title="Leyenda",
       cex = 0.6)

# Indicadores de Tendencia Central
library(e1071)

# MODA

Mo <- "-"

#Tabla de Indicadores
Variable <- "Tipo de Residuo"
Rango <- "{Orgánico, Plástico,Costrucción, Residuos Electrónicos, Peligroso}"
Mo <- "-"

# Crear tabla
Tabla_indicadores <- data.frame(Variable, Rango, Mo)

# Mostrar tabla
Tabla_indicadores
##          Variable
## 1 Tipo de Residuo
##                                                                Rango Mo
## 1 {Orgánico, Plástico,Costrucción, Residuos Electrónicos, Peligroso}  -