#### UNIVERSIDAD CENTRAL DEL ECUADOR ######
#### AUTOR: JHONNY JOSÉ CATUCUAMBA CALCAN ####
#### CARRERA: INGENIERÍA AMBIENTAL ####
### VARIABLE: TOTAL_VEG ####
### MODELO DE REGRESIÓN LINEAL #####
setwd("/cloud/project")
datos <- read.csv("Conaf_Data_Chile_2017.csv")
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
###################### ESTADÍSTICA Multivariable ###############################
plot(1, type = "n", axes = FALSE, xlab = "", ylab = "") # Crear un gráfico vacío
text(x = 1, y = 1,
labels = "ESTADÍSTICA MULTIVARIABLE",
cex = 2, # Tamaño del texto (ajustable)
col = "blue", # Color del texto
font =6) #tipo

total_veg<- datos$total_veg
total_veg<- as.numeric(gsub(",", ".", total_veg))
sup_a <- datos$sup_t_a
sup_a <- as.numeric(gsub(",", ".", sup_a))
length(total_veg); length(sup_a)
## [1] 5234
## [1] 5234
tabla <- data.frame(total_veg,sup_a)
# Depuramos la tabla
tabla_limpia <- tabla[!apply(tabla, 1, function(fila) {
any(is.na(fila) | fila == 0 | fila == "")
}), ]
length(tabla_limpia$total_veg); length(tabla_limpia$sup_a)
## [1] 4549
## [1] 4549
# Conjetura de modelo matemático
plot(1, type = "n", axes = FALSE, xlab = "", ylab = "") # Crear un gráfico vacío
text(x = 1, y = 1,
labels = "Modelo Lineal",
cex = 2, # Tamaño del texto
col = "blue",
font =6,
lwd=2)

# Modelo Lineal
x <- tabla_limpia$total_veg
y <-tabla_limpia$sup_a
# Tabla pares de valores
tabla <- data.frame(x,y)
length(x); length(y)
## [1] 4549
## [1] 4549
#Gráfica de la regresión
plot(x,y, col = 4, main ="Gráfica Nº 6.1: Diagrama de dispersión de Superficie Afectada
en función de la Vegetación Total",
xlab ="Vegetación Total (ha)",
ylab = "Sperficie Afectada Total (ha)")

# Regresio lineal
regresion_lineal <- lm(y~x)
regresion_lineal
##
## Call:
## lm(formula = y ~ x)
##
## Coefficients:
## (Intercept) x
## -62.954 3.336
# Cálculo de parámetros
a <- regresion_lineal$coefficients[2]
b <- regresion_lineal$coefficients[1]
#Formamos la ecuación
plot(1, type = "n", axes = FALSE, xlab = "", ylab = "") # Crear un gráfico vacío
text(x = 1, y = 1,
labels = " Ecuación Lineal \n Y = ax + b \n Y = 3.34 x - 63",
cex = 2, # Tamaño del texto (ajustable)
col = "blue", # Color del texto
font =6) #tipo

# Gráfica
plot(x,y ,
col = "deepskyblue",
main = "Gráfica Nº 6.2: Diagrama de dispersión con la línea de regresión",
xlab = "Vegetación total (ha)",
ylab = "Superficie total afectada (ha)",
pch = 16)
abline(regresion_lineal, col="red")

# Test de Pearson
r <- cor(x, y)
print(paste("Correlación de Pearson: ", round(r, 4)))
## [1] "Correlación de Pearson: 0.932"
# Coeficinte de determinación
r2 <- (r^2) * 100
print(paste("Coeficinte de determinación: ", round(r2, 2), "%"))
## [1] "Coeficinte de determinación: 86.86 %"
# Restricciones
# X y Y no puede ser negativa
# y=0
# (0) = 3.34*(x) - 63
x=63/3.34
x
## [1] 18.86228
# Estimaciones
sup_a50 <- 3.34*50 - 63
sup_a50
## [1] 104
plot(1, type = "n", axes = FALSE, xlab = "", ylab = "") # Crear un gráfico vacío
text(x = 1, y = 1,
labels = "¿Que cantidad de Superficie total
afectada se espera cuando se
tenga 50(ha) de Vegetación total?
\n R= 104 (ha)",
cex = 2, # Tamaño del texto (ajustable)
col = "blue", # Color del texto
font = 6)

# CONCLUSIONES
plot(1, type = "n", axes = FALSE, xlab = "", ylab = "") # Crear un gráfico vacío
text(x = 1, y = 1,
labels = "CONCLUSIONES",
cex = 2, # Tamaño del texto (ajustable)
col = "blue", # Color del texto
font = 6)

library(knitr)
Tabla_resumen <- data.frame(Variables = c("x", "y"),
Modelo = c("Vegetación total (ha)", "Superficie total afectada (ha)"),
Restricciones = c("x > 18.86 (ha)","y > 0 (ha)"),
Coeficiente_pearson = c("0.93 ", ""),
Coeficiente_determinacion = c("86.86 % ", "13.14%"),
Estimacion = c("Y = 3.34 x - 63", ""))
colnames(Tabla_resumen) <- c("Variables ", "Nombres ", "Restricciones",
"Coef. Pearson" , "Coef. Determinación", "ecuación")
kable(Tabla_resumen, align = 'c', caption = "Resumen del Modelo Lineal")
Resumen del Modelo Lineal
| x |
Vegetación total (ha) |
x > 18.86 (ha) |
0.93 |
86.86 % |
Y = 3.34 x - 63 |
| y |
Superficie total afectada (ha) |
y > 0 (ha) |
|
13.14% |
|
###### Entre el total veg y la superficie total de los incendios de Chile en 2017 existe una
###### relación de Regresión simple lineal representada por Y = 3.34 x - 63 siendo X el total veg en (ha)
##### Y la superficie total (ha) donde la superficie total es influenciada en un "86.86 % "y "13.14%"se debe a otras causas
##### y aprueban el test de pearson con un 93% y con restricciones "x > 18.86 (ha)","y > 0 (ha)"