##### UNIVERSIDAD CENTRAL DEL ECUADOR #####
#### AUTOR: MARTIN SARMIENTO ####
### CARRERA: INGENIERÍA EN PETRÓLEOS #####
#### MODELO DE REGRESIÓN POLINÓMICA ####
## DATASET ##
setwd("~/R REGRESION/POLINOMICA")
# Cargar dataset
Datos <- read.csv("DataSet_prov.csv", sep = ";", fileEncoding = "latin1")
## Estructura de los datos
str(Datos)## 'data.frame': 5075 obs. of 30 variables:
## $ FID_ : int 0 2 3 4 5 6 10 11 12 13 ...
## $ OBJECTID : int 127 129 130 131 132 133 137 138 139 140 ...
## $ code : chr "00127-ARG-P" "00129-ARG-G" "00130-ARG-P" "00131-ARG-P" ...
## $ plant_name : chr "Aconcagua solar farm" "Altiplano 200 Solar Power Plant" "Altiplano 200 Solar Power Plant" "Anchoris solar farm" ...
## $ country : chr "Argentina" "Argentina" "Argentina" "Argentina" ...
## $ operational_status : chr "announced" "operating" "operating" "construction" ...
## $ longitude : chr "-68,8713" "-66,895798" "-66,926102" "-68,915001" ...
## $ latitude : chr "-32,998501" "-24,1392" "-24,073999" "-33,330101" ...
## $ elevation : int 929 4000 4000 937 865 858 570 1612 665 3989 ...
## $ area : chr "250,337006" "4397290" "5774,399902" "645,163025" ...
## $ size : chr "Small" "Big" "Small" "Small" ...
## $ slope : chr "0,574179" "1,60257" "6,24265" "0,902748" ...
## $ slope_type : chr "Plano o casi plano" "Plano o casi plano" "Moderado" "Plano o casi plano" ...
## $ curvature : chr "0,000795" "-0,002781" "-0,043699" "0,002781" ...
## $ curvature_type : chr "Superficies planas o intermedias" "Superficies planas o intermedias" "Superficies cóncavas / Valles" "Superficies planas o intermedias" ...
## $ aspect : chr "55,124672" "188,707367" "270,913513" "108,434952" ...
## $ aspect_type : chr "Northeast" "South" "West" "East" ...
## $ dist_to_road : chr "127,2827045" "56014,95403" "52696,78572" "335,9280031" ...
## $ ambient_temperature : chr "12,6" "6,8" "6,8" "13,1" ...
## $ ghi : chr "6,11" "8,012" "7,878" "6,119" ...
## $ humidity : chr "53,74" "53,74" "53,74" "53,74" ...
## $ wind_speed : chr "3,7789" "7,02062" "8,32836" "3,87037" ...
## $ wind_direction : chr "55,099998" "55,099998" "55,099998" "55,099998" ...
## $ dt_wind : chr "Northeast" "Northeast" "Northeast" "Northeast" ...
## $ solar_aptitude : chr "0,746197" "0,8" "0,726996" "0,595309" ...
## $ solar_aptitude_rounded: int 7 8 7 6 7 7 7 8 7 8 ...
## $ solar_aptittude_class : chr "Alta" "Alta" "Alta" "Media" ...
## $ capacity : chr "25" "101" "107" "180" ...
## $ optimal_tilt : int 31 26 26 31 33 30 31 29 31 27 ...
## $ pv_potential : chr "4,983" "6,389" "6,392" "4,969" ...
##
## Adjuntando el paquete: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
# Selección de variables
datos_filtrados <- Datos %>%
select(ambient_temperature, pv_potential) %>%
mutate(
ambient_temperature = as.numeric(gsub(",", ".", ambient_temperature)),
pv_potential = as.numeric(gsub(",", ".", pv_potential))
) %>%
filter(
!is.na(ambient_temperature),
!is.na(pv_potential),
ambient_temperature > 0,
pv_potential > 0
)
# Verificación de tipos
str(datos_filtrados)## 'data.frame': 5075 obs. of 2 variables:
## $ ambient_temperature: num 12.6 6.8 6.8 13.1 11.4 ...
## $ pv_potential : num 4.98 6.39 6.39 4.97 5 ...
# Eliminación de outliers (1% - 99%)
lim_x <- quantile(datos_filtrados$ambient_temperature, c(0.01, 0.99))
lim_y <- quantile(datos_filtrados$pv_potential, c(0.01, 0.99))
datos_limpios <- datos_filtrados %>%
filter(
ambient_temperature >= lim_x[1] & ambient_temperature <= lim_x[2],
pv_potential >= lim_y[1] & pv_potential <= lim_y[2]
)
x <- datos_limpios$ambient_temperature
y <- datos_limpios$pv_potentialplot(jitter(x), jitter(y),
main = "Gráfica N°1: Potencial fotovoltaico (kWh/kWp) vs Temperatura Ambiente (°C)",
xlab = "Temperatura Ambiente (°C)",
ylab = "Potencial Fotovoltaico (kWh/kWp)",
col = rgb(0, 0, 1, 0.3),
pch = 20) **y=β0+β1x+β2x2**
##
## Call:
## lm(formula = y ~ x + I(x^2))
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.92625 -0.12751 0.01723 0.14568 1.38015
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 5.5652697 0.1404390 39.628 < 2e-16 ***
## x -0.0806274 0.0126924 -6.352 2.31e-10 ***
## I(x^2) 0.0016746 0.0002815 5.949 2.89e-09 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.2844 on 4895 degrees of freedom
## Multiple R-squared: 0.0113, Adjusted R-squared: 0.01089
## F-statistic: 27.96 on 2 and 4895 DF, p-value: 8.42e-13
plot(jitter(x), jitter(y),
main = "Gráfica N°2: Modelo de regresión polinómica",
xlab = "Temperatura Ambiente (°C)",
ylab = "Potencial Fotovoltaico (kWh/kWp)",
col = rgb(0, 0, 1, 0.3),
pch = 20)
x_ord <- sort(x)
y_pred <- predict(modelo_polinomico, newdata = data.frame(x = x_ord))
lines(x_ord, y_pred, col = "red", lwd = 2)b0 <- coef(modelo_polinomico)[1]
b1 <- coef(modelo_polinomico)[2]
b2 <- coef(modelo_polinomico)[3]
ecuacion <- paste0(
"y = ", round(b0, 4),
" + ", round(b1, 4), "x",
" + ", round(b2, 6), "x²"
)
ecuacion## [1] "y = 5.5653 + -0.0806x + 0.001675x²"
tabla_resumen <- data.frame(
Variable = c("Temperatura Ambiente (°C)", "Potencial Fotovoltaico (kWh/kWp)"),
Tipo = c("Independiente", "Dependiente"),
Pearson = c("", round(r, 2)),
R2 = c("", round(r2, 2)),
Intercepto = c("", round(b0, 3)),
Beta1 = c("", round(b1, 4)),
Beta2 = c("", round(b2, 6)),
Ecuación = c("", ecuacion)
)
tabla_resumen %>%
gt() %>%
tab_header(
title = md("**Tabla N°1: Resumen del Modelo de Regresión Polinómica**")
) %>%
tab_source_note(
source_note = "Autor: Martin Sarmiento"
) %>%
cols_align(
align = "center",
everything()
)| Tabla N°1: Resumen del Modelo de Regresión Polinómica | |||||||
| Variable | Tipo | Pearson | R2 | Intercepto | Beta1 | Beta2 | Ecuación |
|---|---|---|---|---|---|---|---|
| Temperatura Ambiente (°C) | Independiente | ||||||
| Potencial Fotovoltaico (kWh/kWp) | Dependiente | -6.44 | 1.13 | 5.565 | -0.0806 | 0.001675 | y = 5.5653 + -0.0806x + 0.001675x² |
| Autor: Martin Sarmiento | |||||||
¿Cuál es el potencial fotovoltaico para una temperatura ambiente de 25 °C?
## (Intercept)
## 4.596188
Entre la temperatura ambiente y el potencial fotovoltaico existe una relación no lineal que puede representarse mediante un modelo de regresión polinómica de segundo grado. El coeficiente de determinación indica que una proporción significativa de la variabilidad del potencial fotovoltaico es explicada por la temperatura ambiente. Esto sugiere que la temperatura influye de manera importante en el rendimiento fotovoltaico, aunque existen otros factores adicionales no considerados en el modelo.