# UNIVERSIDAD CENTRAL DEL ECUADOR
# Facultad de Ingeniería en Geología, Minas, Petroleos y Ambiental
# Ingeniería Ambiental
# Autor: Domenica Yepez
# Variable : Continua matorral
# Directorio de trabajo
setwd("C:/Users/HP/OneDrive - Universidad Central del Ecuador/SEMESTRE III/Estadistica/Incendios en Chile/Datos")
# Cargar los datos
library(readr)
datos <- read_delim("Conaf_Data_Chile_2017.csv",
delim = ";", escape_double = FALSE, trim_ws = TRUE)
## Rows: 5234 Columns: 30
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ";"
## chr (5): temporada, ambito, nombre_inc, inicio_c, combus_i
## dbl (23): Column1, codreg, codprov, codcom, numero, utm_este, utm_norte, cau...
## num (2): long, lat
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
# Extraer la variable matorral
matorral <-na.omit(as.numeric(datos$matorral))
# Analizar la variable por el diagrama de caja
options(scipen = 999)
Caja_matorral<- boxplot(matorral, horizontal = T,
main = "Gráfica N°: Distribución de Superficie de matorral afectada en Chile",
xlab = " Superficie (ha) ",
col = "#B5EAD7",
pch = 1)

#valores de cero de matorral
matorral_cero<-subset(matorral, matorral==0)
length(matorral_cero)
## [1] 1637
#valores mayores de cero de matorral
matorral.1<- subset(matorral, matorral>0)
Caja_matorral.1<- boxplot(matorral.1, horizontal=T,
main = "Gráfica N°: Distribución de Superficie de matorral
mayor a cero afectada en Chile",
xlab = " Superficie (ha)",
col = "#FFDAC1",
pch = 1)

length(matorral.1)
## [1] 3597
#se divide los valores mayores de cero en comunes y no comunes
matorral.1_comunes<- subset(matorral.1,matorral.1 < min(Caja_matorral.1$out))
caja_mat_comunes<- boxplot(matorral.1_comunes, horizontal=T,
main = "Gráfica: Diastribución de Superficie de matorral
comunes afectada en Chile",
xlab = "Superficie (ha)",
col = "#D6E0F0",
pch = 1)

matorral.1_outliers<- subset(matorral.1,matorral.1 >= min(Caja_matorral.1$out) & matorral.1 < 200000)
caja_mat_outliers<- boxplot(matorral.1_outliers, horizontal=T,
main= "Gráfica: Distribución de Superficie de matorral
no comunes afectada en Chile",
xlab= "Superficie (ha)",
col= "#FFDAC1",
phc= 1)

# Estadística descriptiva para la variable matorral común
min <- min(matorral.1_comunes )
max <- max(matorral.1_comunes )
R <- max-min
K <- floor(1+3.33*log10(length(matorral.1_comunes )))
A <- (R/K)
lim_inf <- seq(from=min,to=max-A,by=A)
lim_sup <- seq(from=min+A,to=max+A,by=A)[1:K]
MC <- (lim_inf+lim_sup)/2
ni <- c()
for (i in 1:K) {
if (i != K) {
ni[i] <- length(subset(matorral.1_comunes,
matorral.1_comunes >= lim_inf[i] & matorral.1_comunes < lim_sup[i]))
} else {
ni[i] <- length(subset(matorral.1_comunes,
matorral.1_comunes >= lim_inf[i] & matorral.1_comunes <= lim_sup[i]))
}
}
sum(ni)
## [1] 3061
hi <- ni/sum(ni)*100
sum(hi)
## [1] 100
Ni_asc <- cumsum(ni)
Hi_asc <- cumsum(hi)
Ni_desc <- rev(cumsum(rev(ni)))
Hi_desc <- rev(cumsum(rev(hi)))
TDF_matorral <- data.frame(round(lim_inf,2),
round(lim_sup,2),
round(MC,2),ni,
round(hi,2),
Ni_asc,
Ni_desc,
round(Hi_asc,2),
round(Hi_desc,2))
colnames(TDF_matorral) <- c("Lim inf","Lim sup","MC","ni","hi(%)",
"Ni asc","Hi asc(%)","Ni desc","Hi desc(%)")
totales <- c(lim_inf = "TOTAL", lim_sup = "-", MC = "-", ni = sum(ni), hi = sum(hi),
Ni_asc = "-", Ni_desc = "-", Hi_asc = "-", Hi_desc = "-")
TDF_matorral <- rbind(TDF_matorral, totales)
TDF_matorral
## Lim inf Lim sup MC ni hi(%) Ni asc Hi asc(%) Ni desc Hi desc(%)
## 1 1 5.92 3.46 1625 53.09 1625 3061 53.09 100
## 2 5.92 10.83 8.38 482 15.75 2107 1436 68.83 46.91
## 3 10.83 15.75 13.29 278 9.08 2385 954 77.92 31.17
## 4 15.75 20.67 18.21 156 5.1 2541 676 83.01 22.08
## 5 20.67 25.58 23.12 147 4.8 2688 520 87.81 16.99
## 6 25.58 30.5 28.04 101 3.3 2789 373 91.11 12.19
## 7 30.5 35.42 32.96 61 1.99 2850 272 93.11 8.89
## 8 35.42 40.33 37.88 63 2.06 2913 211 95.16 6.89
## 9 40.33 45.25 42.79 38 1.24 2951 148 96.41 4.84
## 10 45.25 50.17 47.71 55 1.8 3006 110 98.2 3.59
## 11 50.17 55.08 52.62 23 0.75 3029 55 98.95 1.8
## 12 55.08 60 57.54 32 1.05 3061 32 100 1.05
## 13 TOTAL - - 3061 100 - - - -
#simplificar la tabla de distribucion de frecuencia con el histograma
Hist_densidad <- hist(matorral.1_comunes ,
main="Gráfica N°:Distribución de superficie de matorral
afectada en Chile para la elaboración de la TDF",
xlab = "Superficie (ha)",
ylab= "Cantidad", col ="#CBAACB")

k.1 <- length(Hist_densidad$breaks)
Li<- Hist_densidad$breaks[1:(length(Hist_densidad$breaks) - 1)]
Ls <- Hist_densidad$breaks[2:length(Hist_densidad$breaks)]
ni.1 <- Hist_densidad$counts
sum(ni.1)
## [1] 3061
MC.1<- Hist_densidad$mids
hi.1 <- (ni.1/sum(ni.1))
sum(hi.1)
## [1] 1
Ni_asc.1<- cumsum(ni.1)
Hi_asc.1 <- cumsum(hi.1)
Ni_desc.1 <- rev(cumsum(rev(ni.1)))
Hi_desc.1 <- rev(cumsum(rev(hi.1)))
TDF_matorral.1 <- data.frame(Li = round(Li, 2),
Ls = round(Ls, 2),
MC.1 = round(MC.1, 2),
ni.1 = ni.1,
hi.1 = round(hi.1 * 100, 2),
Ni_asc.1 = Ni_asc.1,
Hi_asc.1 = round(Hi_asc.1 * 100, 2),
Ni_desc.1 = Ni_desc.1,
Hi_desc.1 = round(Hi_desc.1 * 100, 2))
colnames(TDF_matorral.1) <- c("Lim inf","Lim sup","MC","ni","hi(%)",
"Ni asc","Hi asc(%)","Ni desc","Hi desc(%)")
totales <- c(Li = "TOTAL", Ls = "-", MC.1 = "-", ni.1 = sum(ni.1), hi.1 = sum(hi.1*100),
Ni_asc.1= "-", Ni_desc.1 = "-", Hi_asc.1 = "-", Hi_desc.1 = "-")
TDF_matorral.1 <- rbind(TDF_matorral.1, totales)
TDF_matorral.1
## Lim inf Lim sup MC ni hi(%) Ni asc Hi asc(%) Ni desc Hi desc(%)
## 1 0 5 2.5 1625 53.09 1625 53.09 3061 100
## 2 5 10 7.5 482 15.75 2107 68.83 1436 46.91
## 3 10 15 12.5 278 9.08 2385 77.92 954 31.17
## 4 15 20 17.5 156 5.1 2541 83.01 676 22.08
## 5 20 25 22.5 147 4.8 2688 87.81 520 16.99
## 6 25 30 27.5 101 3.3 2789 91.11 373 12.19
## 7 30 35 32.5 61 1.99 2850 93.11 272 8.89
## 8 35 40 37.5 63 2.06 2913 95.16 211 6.89
## 9 40 45 42.5 38 1.24 2951 96.41 148 4.84
## 10 45 50 47.5 55 1.8 3006 98.2 110 3.59
## 11 50 55 52.5 23 0.75 3029 98.95 55 1.8
## 12 55 60 57.5 32 1.05 3061 100 32 1.05
## 13 TOTAL - - 3061 100 - - - -
##################### Gráficas ###############################
# Histograma con la rergla de Sturgest###
breaks_sturges <- c(lim_inf, tail(lim_sup, 1))
hist(matorral.1_comunes, breaks = breaks_sturges,
main = "Gráfica N°: Distribución de Superficie de matorral
comunes afectadas en Chile ",
col = "salmon",
xlab = "Superficie (ha)",
ylab = "Cantidad",
xaxt = "n")
axis(side = 1, at = breaks_sturges, labels = round(breaks_sturges, 1), las = 1, cex.axis = 0.8)

# Histograma de ni que genera Rstudio
# Local
hist(matorral.1_comunes,
main = "Gráfica N°: Distribución de Superficie de matorral
comunes afectadas en Chile",
col = "skyblue",
xlab = "Superficie (ha)",
ylab = "Cantidad")

# Gobal
hist(matorral.1_comunes,
main = "Gráfica N°: Distribución de Superficie de matorral
comunes afectadas en Chile",
col = "salmon",
xlab = "Superficie (ha)",
ylab = "Cantidad",
ylim=c(0,3061))

# Histograma de hi que genera Rstudio
#Local
barplot(hi.1*100,space=0,
col = "skyblue",
main ="Gráfica N°: Distribución de Superficie de matorral
comunes afectadas en Chile",
ylab="Porcentaje (%)",
xlab="Superficie (ha)",
names.arg = MC.1)

# Global
barplot(hi.1*100,space=0,
col = "salmon",
main ="Gráfica N°: Distribución de Superficie de matorral
comunes afectadas en Chile",
ylab="Porcentaje (%)",
xlab="Superficie (ha)",
ylim = c(0,100),
names.arg = MC.1)

# Ojivas Ni_asc Ni_dsc global y local ####
plot(MC.1, Ni_desc.1,
main = "Gráfica N°: Ojiva acumulada absoluta de Superficie de matorral
comunes afectada en Chile",
xlab = " Superficie (ha)",
ylab = "Cantidad",
col = "salmon",
type = "o",
lwd = 3,
pch = 16,
ylim = c(0,3061))
lines(MC.1, Ni_asc.1,
col = "blue",
type = "o",
pch = 16,
lwd = 3)

# Ojivas Hi_asc y Hi_dsc global y local ###
plot(MC.1, Hi_desc.1*100,
main = "Gráfica N°: Ojiva acumulada relativa de Superficie de matorral
comunes afectada en Chile",
xlab = " Superficies (ha)",
ylab = "Porcentaje (%)",
col = "salmon",
type = "o",
lwd = 3,
pch = 16,
ylim = c(0,100))
lines(MC.1, Hi_asc.1*100,
col = "blue",
type = "o",
pch = 16,
lwd = 3)

### Indicadores ###
# Tendencia central
## Media aritmética
x <- mean(matorral.1_comunes)
x
## [1] 10.91637
## Mediana
Me <- median(matorral.1_comunes)
Me
## [1] 5
# Disperción
## varianza
V<-var(matorral.1_comunes)
V
## [1] 164.7564
## Deviación estandar
desv <- sd(matorral.1_comunes)
desv
## [1] 12.83575
### coeficiente variabilidad ####
CV <- (desv/x)*100
CV
## [1] 117.5826
# FORMA
## Asimetria
library(e1071)
## Warning: package 'e1071' was built under R version 4.4.3
As <- skewness(matorral.1_comunes)
As
## [1] 1.822749
# Curtosis
Ku<- kurtosis(matorral.1_comunes)
Ku
## [1] 2.837857
outliers<- Caja_matorral.1$out
outliers
## [1] 435 1407 159 100 130 780 70 100 90 432
## [11] 150 88 62 20000 100 559 75 609 2205 109
## [21] 130 9246 213 20103 71 500 1756 74 131 7810
## [31] 197 500 305 62 91 950 212 667 374 335
## [41] 284 76 100 85 190 100 9869 138 1664 95
## [51] 440 6408 1672 8816 3786 1141 275 564 12254 1515
## [61] 5219 80 194 39609 13536 650 562 403 200 100
## [71] 235 100 178 500 352 307 79 300 107 193
## [81] 70 70 1250 75 3819 1380 125 21531 63 378
## [91] 100 65 1590 583 373 107 8357 925 200 144
## [101] 1624 128 71 253 75 200 174 80 80 500
## [111] 70 108 709 321 18129 115 75 159 68 122
## [121] 96 178 850 230 100 9930 3000 910 2000 100
## [131] 820 110 430 9870 1800 560 100 120 500 22860
## [141] 170 7960 37530 105130 43340 460 8160 500 18130 190
## [151] 460 217 2500 100 90 500 30001 196 568 92
## [161] 90 882 155 65 70 90 70 190 730 120
## [171] 3304 740 800 80 61 100 170 300 140 214
## [181] 150 205 500 120 155 991606 300 500 150 120
## [191] 200 230459 130 8491 32052 131683 90 4000 75 100
## [201] 250 250 80 150 1350 85 70 150 90 500
## [211] 79 62 1666 318 132 226 631 437 85 356
## [221] 732 120 225 716 75 74 182 91 150 506
## [231] 120 162 626 500 281 106 201 249 277 2742
## [241] 172 210 651 334 1125 462 234 208 2902 1000
## [251] 1400 210 26253 308 880 160 540 2410 80 14656
## [261] 216 1230 19220 1980 4960 70 14672 16395 150 1365
## [271] 1240 2030 338 2900 744 2800 80 2796 14988 16938
## [281] 500 100 2000 70 388 300 660 120 7655 1893
## [291] 100 2000 35540 6750 27989 6168 3914 956 1520 780
## [301] 150 115 99 100 75 105 366 94 1045 230
## [311] 71 100 120 500 500 203215 4960 129387 43513 115781
## [321] 14223 65 2489 164 101 1761 941 126 10019 121
## [331] 74 700 105135 8395 232 723 65 156 1224 116
## [341] 125 102 547 97 347 425 61 128 375 254
## [351] 158 775 68 2105 95 82 92 144 574 67
## [361] 116 125 144 157 75 71 75 311 76 101
## [371] 74 249 81 75 79 136 242 175 75 571
## [381] 64 659 184 75 65 75 103 1200 204 375
## [391] 125 167 75 75 70 225 175 283 215 85
## [401] 115 385 64 345 147 175 265 75 75 216
## [411] 532 125 97 75 82 84 95 1000 80 85
## [421] 85 84 75 128 73 100 600 72 62 601
## [431] 69 67 80 73 97 153 67 73 217 143
## [441] 967 660 79 97 1356 100 2000 660 500 33641
## [451] 70 517 95 2162 1000 123 100 205 5470 956
## [461] 2262 14116 20449 2391 3913 33754 495 19287 10732 75
## [471] 24364 200 3970 115 90 315 823 407 1100 81
## [481] 69 238 1838 255 260 80 112 125 81 62
## [491] 8176 416 235 233 1353 122 551 27775 3427 322
## [501] 335 802 27997 295 87 63 300 63 700 2234
## [511] 100 204 61 174 120 300 189 2500 145 68
## [521] 400 100 65 4001 70 307 209 260 150 231
## [531] 189 96 101 144 74 100
# tabla de indicadores de la variable
tabla_indicadores <- data.frame(
Variable = "Latitud",
Rango = paste0("{", round(min(matorral.1_comunes)), "-", round(max(matorral.1_comunes)), "}"),
Media = round(x, 2),
Mediana = round(Me, 2),
Moda = "0-5",
Varianza = round(V, 2),
Desviacion = round(desv, 2),
Coeficiente_Variacion = round(CV, 2),
Asimetria = round(As, 2),
Curtosis = round(Ku, 2),
Valores_Atipicos = paste(length(outliers), "entre [", min(outliers), "-", max(outliers), "]")
)
library(knitr)
kable(tabla_indicadores, align = 'c', caption = "Tabla: Conclusiones de la variable Matorral")
Tabla: Conclusiones de la variable Matorral
| Latitud |
{1-60} |
10.92 |
5 |
0-5 |
164.76 |
12.84 |
117.58 |
1.82 |
2.84 |
536 entre [ 61 - 991606 ] |