# Configuración
knitr::opts_chunk$set(echo = TRUE)
# importar datos
datos <- read.csv("Focos de Calor 2021.csv",
header = T, sep = ",", dec = ".")
#Estructura de los datos
str(datos)
## 'data.frame': 22476 obs. of 12 variables:
## $ ACQ_DATE : chr "20/11/2021" "20/11/2021" "06/08/2021" "10/06/2021" ...
## $ DPA_DESPRO: chr "ZAMORA CHINCHIPE" "ZAMORA CHINCHIPE" "ZAMORA CHINCHIPE" "ZAMORA CHINCHIPE" ...
## $ DPA_DESCAN: chr "CHINCHIPE" "CHINCHIPE" "CHINCHIPE" "CHINCHIPE" ...
## $ DPA_DESPAR: chr "CHITO" "CHITO" "PUCAPAMBA" "PUCAPAMBA" ...
## $ LATITUDE : num -4.98e+15 -4.97e+15 -4.96e+15 -4.96e+15 -4.96e+15 ...
## $ LONGITUDE : num -7.90e+16 -7.90e+16 -7.91e+16 -7.91e+16 -7.92e+16 ...
## $ BRIGHTNESS: num 3.55e+17 3.42e+17 3.32e+17 3.31e+17 3.28e+17 ...
## $ SCAN : num 5.1e+14 5.1e+14 1.5e+14 5.4e+14 5.0e+14 ...
## $ TRACK : num 4.9e+14 4.9e+14 3.8e+14 4.2e+14 4.9e+14 ...
## $ INSTRUMENT: chr "VIIRS" "VIIRS" "VIIRS" "VIIRS" ...
## $ VERSION : chr "2.0NRT" "2.0NRT" "2.0NRT" "2.0NRT" ...
## $ FRP : num 1.21e+16 6.87e+15 3.77e+15 5.50e+15 2.90e+15 ...
table(is.na(datos$LONGITUDE))
##
## FALSE
## 22476
Longitud <- as.numeric(as.character(datos$LONGITUDE))
table(is.na(Longitud))
##
## FALSE
## 22476
# Paso 3: Verifica cuántos se perdieron
cat("Total original:", length(datos$LONGITUDE), "\n")
## Total original: 22476
cat("Convertidos correctamente:", sum(!is.na(Longitud)), "\n")
## Convertidos correctamente: 22476
cat("Perdidos (NA):", sum(is.na(Longitud)), "\n")
## Perdidos (NA): 0
Longitud <- na.omit(Longitud)
Longitud <- Longitud / 1e6
summary(Longitud)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -8.090e+10 -8.020e+10 -7.980e+10 -7.945e+10 -7.920e+10 -7.530e+10
head(datos$LONGITUDE, 10)
## [1] -7.90e+16 -7.90e+16 -7.91e+16 -7.91e+16 -7.92e+16 -7.91e+16 -7.93e+16
## [8] -7.93e+16 -7.91e+16 -7.91e+16
# Tomemos el valor y dividimos por 1e15 para intentar acercarlo a -79
val <- -79000000000000000
val_grados <- val / 1e15
print(val_grados) # -79
## [1] -79
Longitud_correcta <- as.numeric(as.character(datos$LONGITUDE)) / 1e15
summary(Longitud_correcta)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -80.90 -80.20 -79.80 -79.45 -79.20 -75.30
length(Longitud_correcta)
## [1] 22476
k<-1+(3.3*log10(length(Longitud_correcta)))
k<-floor(k)
k
## [1] 15
min<-min(Longitud_correcta)
max<-max(Longitud_correcta)
R<-max-min
R
## [1] 5.6
A<-R/k
A
## [1] 0.3733333
Li <- round(seq(from = min, to = max - A, by = A), 2)
Li
## [1] -80.90 -80.53 -80.15 -79.78 -79.41 -79.03 -78.66 -78.29 -77.91 -77.54
## [11] -77.17 -76.79 -76.42 -76.05 -75.67
Ls <- round(seq(from = min + A, to = max, by = A), 2)
Ls
## [1] -80.53 -80.15 -79.78 -79.41 -79.03 -78.66 -78.29 -77.91 -77.54 -77.17
## [11] -76.79 -76.42 -76.05 -75.67 -75.30
MC<-round((Li+Ls)/2,2)
MC
## [1] -80.72 -80.34 -79.97 -79.60 -79.22 -78.84 -78.47 -78.10 -77.72 -77.36
## [11] -76.98 -76.61 -76.24 -75.86 -75.48
ni12<- numeric(length(Li))
for (i in 1:length(Li)) {
if (i < length(Li)) {
ni12[i] <- sum(Longitud_correcta >= Li[i] & Longitud_correcta < Ls[i])
} else {
ni12[i] <- sum(Longitud_correcta >= Li[i] & Longitud_correcta <= Ls[i])
}
}
intervalos <- cut(Longitud_correcta, breaks = c(Li, max(Longitud_correcta)), include.lowest = TRUE, right = TRUE)
ni12 <- table(intervalos)
sum(ni12)
## [1] 22476
hi12<- ni12/sum(ni12)*100
sum(hi12)
## [1] 100
Ni12_asc <- cumsum(ni12)
Ni12_dsc <- rev(cumsum(rev(ni12)))
Hi12_asc <- round(cumsum(hi12), 2)
Hi12_dsc <- round(rev(cumsum(rev(hi12))), 2)
TDFLongitud <-data.frame(Li, Ls, MC, ni12, hi12, Ni12_asc, Ni12_dsc, Hi12_dsc, Hi12_dsc)
TDFLongitud
## Li Ls MC intervalos Freq intervalos.1 Freq.1
## [-80.9,-80.5] -80.90 -80.53 -80.72 [-80.9,-80.5] 596 [-80.9,-80.5] 2.6517174
## (-80.5,-80.2] -80.53 -80.15 -80.34 (-80.5,-80.2] 5924 (-80.5,-80.2] 26.3570030
## (-80.2,-79.8] -80.15 -79.78 -79.97 (-80.2,-79.8] 5200 (-80.2,-79.8] 23.1357893
## (-79.8,-79.4] -79.78 -79.41 -79.60 (-79.8,-79.4] 3930 (-79.8,-79.4] 17.4853177
## (-79.4,-79] -79.41 -79.03 -79.22 (-79.4,-79] 1330 (-79.4,-79] 5.9174230
## (-79,-78.7] -79.03 -78.66 -78.84 (-79,-78.7] 267 (-79,-78.7] 1.1879338
## (-78.7,-78.3] -78.66 -78.29 -78.47 (-78.7,-78.3] 2727 (-78.7,-78.3] 12.1329418
## (-78.3,-77.9] -78.29 -77.91 -78.10 (-78.3,-77.9] 187 (-78.3,-77.9] 0.8319986
## (-77.9,-77.5] -77.91 -77.54 -77.72 (-77.9,-77.5] 801 (-77.9,-77.5] 3.5638014
## (-77.5,-77.2] -77.54 -77.17 -77.36 (-77.5,-77.2] 76 (-77.5,-77.2] 0.3381385
## (-77.2,-76.8] -77.17 -76.79 -76.98 (-77.2,-76.8] 538 (-77.2,-76.8] 2.3936644
## (-76.8,-76.4] -76.79 -76.42 -76.61 (-76.8,-76.4] 467 (-76.8,-76.4] 2.0777718
## (-76.4,-76] -76.42 -76.05 -76.24 (-76.4,-76] 368 (-76.4,-76] 1.6373020
## (-76,-75.7] -76.05 -75.67 -75.86 (-76,-75.7] 45 (-76,-75.7] 0.2002136
## (-75.7,-75.3] -75.67 -75.30 -75.48 (-75.7,-75.3] 20 (-75.7,-75.3] 0.0889838
## Ni12_asc Ni12_dsc Hi12_dsc Hi12_dsc.1
## [-80.9,-80.5] 596 22476 100.00 100.00
## (-80.5,-80.2] 6520 21880 97.35 97.35
## (-80.2,-79.8] 11720 15956 70.99 70.99
## (-79.8,-79.4] 15650 10756 47.86 47.86
## (-79.4,-79] 16980 6826 30.37 30.37
## (-79,-78.7] 17247 5496 24.45 24.45
## (-78.7,-78.3] 19974 5229 23.26 23.26
## (-78.3,-77.9] 20161 2502 11.13 11.13
## (-77.9,-77.5] 20962 2315 10.30 10.30
## (-77.5,-77.2] 21038 1514 6.74 6.74
## (-77.2,-76.8] 21576 1438 6.40 6.40
## (-76.8,-76.4] 22043 900 4.00 4.00
## (-76.4,-76] 22411 433 1.93 1.93
## (-76,-75.7] 22456 65 0.29 0.29
## (-75.7,-75.3] 22476 20 0.09 0.09
total_ni12 <- sum(ni12)
total_hi12 <- 100
lengths <- sapply(list(Li, Ls, MC, ni12, hi12, Ni12_asc, Ni12_dsc, Hi12_dsc), length)
names(lengths) <- c("Li", "Ls", "MC", "ni", "hi", "Ni_asc", "Ni_dsc", "Hi_dsc")
print(lengths)
## Li Ls MC ni hi Ni_asc Ni_dsc Hi_dsc
## 15 15 15 15 15 15 15 15
# Generación de tabla con columnas correctamente nombradas
TDFLongitud <- data.frame(
Li = Li,
Ls = Ls,
MC = MC,
ni12 = as.numeric(ni12),
hi12 = as.numeric(hi12),
Ni12_asc = as.numeric(Ni12_asc),
Ni12_dsc = as.numeric(Ni12_dsc),
Hi12_asc = as.numeric(Hi12_asc),
Hi12_dsc = as.numeric(Hi12_dsc)
)
# Crear fila "Total" con mismos tipos
fila_total <- data.frame(
Li = NA,
Ls = NA,
MC = NA,
ni12 = total_ni12,
hi12 = total_hi12,
Ni12_asc = NA,
Ni12_dsc = NA,
Hi12_asc = NA,
Hi12_dsc = NA
)
# Unir sin errores
TDFLongitudCompleto <- rbind(TDFLongitud, fila_total)
# Crear la tabla
library(gt)
tabla_Longitud<-TDFLongitudCompleto %>%
gt() %>%
tab_header(
title = md("**Tabla Nro. 12**"),
subtitle = md("**Tabla de distribución de Frecuencias simples y acumuladas
de la Longitud de los Focos de calor**")
) %>%
tab_source_note(
source_note = md("*Autor:Grupo1*")
) %>%
tab_options(
table.border.top.color = "black",
table.border.bottom.color = "black",
table.border.top.style = "solid",
table.border.bottom.style = "solid",
column_labels.border.top.color = "black",
column_labels.border.bottom.color = "black",
column_labels.border.bottom.width = px(2),
row.striping.include_table_body = TRUE,
heading.border.bottom.color = "black",
heading.border.bottom.width = px(2),
table_body.hlines.color = "gray",
table_body.border.bottom.color = "black"
) %>%
tab_style(
style = cell_text(weight = "bold"),
locations = cells_body(
rows = Li == "Total"
)
)
tabla_Longitud
| Tabla Nro. 12 | ||||||||
| **Tabla de distribución de Frecuencias simples y acumuladas
de la Longitud de los Focos de calor** |
||||||||
| Li | Ls | MC | ni12 | hi12 | Ni12_asc | Ni12_dsc | Hi12_asc | Hi12_dsc |
|---|---|---|---|---|---|---|---|---|
| -80.90 | -80.53 | -80.72 | 596 | 2.6517174 | 596 | 22476 | 2.65 | 100.00 |
| -80.53 | -80.15 | -80.34 | 5924 | 26.3570030 | 6520 | 21880 | 29.01 | 97.35 |
| -80.15 | -79.78 | -79.97 | 5200 | 23.1357893 | 11720 | 15956 | 52.14 | 70.99 |
| -79.78 | -79.41 | -79.60 | 3930 | 17.4853177 | 15650 | 10756 | 69.63 | 47.86 |
| -79.41 | -79.03 | -79.22 | 1330 | 5.9174230 | 16980 | 6826 | 75.55 | 30.37 |
| -79.03 | -78.66 | -78.84 | 267 | 1.1879338 | 17247 | 5496 | 76.74 | 24.45 |
| -78.66 | -78.29 | -78.47 | 2727 | 12.1329418 | 19974 | 5229 | 88.87 | 23.26 |
| -78.29 | -77.91 | -78.10 | 187 | 0.8319986 | 20161 | 2502 | 89.70 | 11.13 |
| -77.91 | -77.54 | -77.72 | 801 | 3.5638014 | 20962 | 2315 | 93.26 | 10.30 |
| -77.54 | -77.17 | -77.36 | 76 | 0.3381385 | 21038 | 1514 | 93.60 | 6.74 |
| -77.17 | -76.79 | -76.98 | 538 | 2.3936644 | 21576 | 1438 | 96.00 | 6.40 |
| -76.79 | -76.42 | -76.61 | 467 | 2.0777718 | 22043 | 900 | 98.07 | 4.00 |
| -76.42 | -76.05 | -76.24 | 368 | 1.6373020 | 22411 | 433 | 99.71 | 1.93 |
| -76.05 | -75.67 | -75.86 | 45 | 0.2002136 | 22456 | 65 | 99.91 | 0.29 |
| -75.67 | -75.30 | -75.48 | 20 | 0.0889838 | 22476 | 20 | 100.00 | 0.09 |
| NA | NA | NA | 22476 | 100.0000000 | NA | NA | NA | NA |
| Autor:Grupo1 | ||||||||
#Graficas
#HISTOGRAMA LOCAL ni
HistogramaSturgers<-hist(Longitud_correcta, main="Gráfica No 12.1: Distribución de Longitud ",
ylab="Cantidad", xlab="Longitud (°)"
,breaks = seq(min, max, A), col="blue")
#HISTOGRAMA GLOBAL ni
HistogramaSturgers<-hist(Longitud_correcta, main="Gráfica No 12.2: Distribución de Longitud ",
ylab="Cantidad", xlab="Longitud (°)"
,breaks = seq(min, max, A), col="blue",
ylim=c(0,length(Longitud_correcta)))
#HISTOGRAMA LOCAL hi
barplot(TDFLongitud$hi12, space=0, main="Gráfica No 12.3: Distribución de Longitud", ylab="Porcentaje (%)", xlab="Longitud (°)",
col="blue", names.arg = TDFLongitud$MC,2)
#HISTOGRAMA GLOBAL hi
barplot(TDFLongitud$hi12, space=0, main="Gráfica No 12.4: Distribución de Longitud",
ylab="Porcentaje (%)", xlab="Longitud (°)",
col="blue", names.arg = TDFLongitud$MC,2, ylim=c(0,100))
#ojivas Niasc_dsc-Hiasc_dsc
#Graficar la ojiva (Ni_asc/dsc)
x_min <- min(c(Li, Ls))
x_max <- max(c(Li, Ls))
plot(Ls, Ni12_asc, type="o", xlim=c(x_min, x_max), xlab="Longitud (°)",
main="Gráfica No 12.5: Ojivas Ascendentes y Descendentes de Frecuencias Absolutas de Longitud",
ylab="Frecuencia", col="red")
lines(Li, Ni12_dsc, col="blue", type="o")
#Graficar la ojiva (Hi_asc/dsc)
plot(Ls, Hi12_asc, type="o", xlim=c(x_min, x_max), xlab="Longitud (°)",
main="Gráfica No 12.6: Ojivas Ascendentes y Descendentes de
Frecuencias Relativas de Longitud "
, ylab="Frecuencia", col="red")
lines(Li, Hi12_dsc, col="blue", type="o")
cajaBigotes<-boxplot(Longitud_correcta, horizontal=T, col="brown",
main="Gráfica No 12.7: Distribución de frecuencia para la longitud", xlab="Longitud (°)")
#INDICADORES
#POSICION
#MEDIA ARITMETICA
x12<-sum(Longitud_correcta)/(length(Longitud_correcta))
x12
## [1] -79.44604
#MEDIANA
Me12<-median(MC)
Me12
## [1] -78.1
#MODA
modal_index12 <- which.max(ni12)
modal_index12
## (-80.5,-80.2]
## 2
#DISPERSION
#DESVIACIÓN ESTÁNDAR
sd12<-sd(Longitud_correcta)
sd12
## [1] 1.066839
#COEFICIENTE DE VARIACIÓN
CV12 <- ((sd12 / x12) * 100)
CV12
## [1] -1.342848
#FORMA
#COEFICIENTE DE ASIMETRÍA
#install.packages("e1071")
library(e1071)
## Warning: package ’e1071’ was built under R version 4.4.3
As12<-skewness(Longitud_correcta)
As12
## [1] 1.384038
## [1] -1.386749
#COEFICIENTE DE CURTOSIS
K12<-kurtosis(Longitud_correcta)
K12
## [1] 1.199926
#outliers
outliers<-cajaBigotes$out
min(outliers)
## [1] -77.6
12
## [1] 12
max(outliers)
## [1] -75.3
length(outliers)
## [1] 1600