class: center, middle, inverse, title-slide .title[ # Análisis de Serie de Tiempo: Temperatura en Ucrania ] .subtitle[ ## 2015 - 2020 ] .author[ ### Sebastian Mendez ] .date[ ### 2025-11-19 ] --- # 1. Carga de librerías ``` r library(readr) library(dplyr) library(janitor) library(tibble) library(tsibble) library(lubridate) library(ggplot2) library(feasts) library(GGally) library(tidyverse) library(slider) ``` --- # Cargue de dataset ``` r df <- read_csv("C:/Users/sebas/OneDrive/Desktop/series_tiempo_final/city_temperature.csv") ``` ``` ## Rows: 2906327 Columns: 8 ## ── Column specification ──────────────────────────────────────────────────────── ## Delimiter: "," ## chr (4): Region, Country, State, City ## dbl (4): Month, Day, Year, AvgTemperature ## ## ℹ 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. ``` ``` r # filtramos df_filtrado <- df |> filter(Country == "Ukraine", Year >= 2015 & Year <= 2020,AvgTemperature != -99) ``` --- # Conversion a tsible ``` r df_ts <- df_filtrado |> mutate( fecha = make_date(Year, Month, Day) ) |> as_tsibble(index = fecha) df_ts ``` ``` ## # A tsibble: 1,947 x 9 [1D] ## Region Country State City Month Day Year AvgTemperature fecha ## <chr> <chr> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <date> ## 1 Europe Ukraine <NA> Kiev 1 1 2015 27.9 2015-01-01 ## 2 Europe Ukraine <NA> Kiev 1 2 2015 34.3 2015-01-02 ## 3 Europe Ukraine <NA> Kiev 1 3 2015 36.6 2015-01-03 ## 4 Europe Ukraine <NA> Kiev 1 4 2015 32.9 2015-01-04 ## 5 Europe Ukraine <NA> Kiev 1 5 2015 30.3 2015-01-05 ## 6 Europe Ukraine <NA> Kiev 1 6 2015 14.5 2015-01-06 ## 7 Europe Ukraine <NA> Kiev 1 7 2015 8.2 2015-01-07 ## 8 Europe Ukraine <NA> Kiev 1 8 2015 7.7 2015-01-08 ## 9 Europe Ukraine <NA> Kiev 1 9 2015 24 2015-01-09 ## 10 Europe Ukraine <NA> Kiev 1 10 2015 34.3 2015-01-10 ## # ℹ 1,937 more rows ``` --- # Agregacion Mensual ``` r df_mensual <- df_ts |> mutate(fecha_mensual = yearmonth(fecha)) |> index_by(fecha_mensual) |> summarise( AvgTemperature = mean(AvgTemperature, na.rm = TRUE) ) df_mensual ``` ``` ## # A tsibble: 65 x 2 [1M] ## fecha_mensual AvgTemperature ## <mth> <dbl> ## 1 2015 Jan 30.6 ## 2 2015 Feb 29.9 ## 3 2015 Mar 40.4 ## 4 2015 Apr 48.5 ## 5 2015 May 60.2 ## 6 2015 Jun 67.9 ## 7 2015 Jul 70.6 ## 8 2015 Aug 71.2 ## 9 2015 Sep 63.4 ## 10 2015 Oct 43.7 ## # ℹ 55 more rows ``` class: middle, center, fullscreen --- # Visualizacion General de la serie ``` r autoplot(df_mensual, AvgTemperature) + labs( title = "Serie Mensual de Temperatura Promedio", x = "Fecha", y = "Temperatura Promedio" ) + theme_minimal(base_size = 12) ``` <img src="presentacion_final_files/figure-html/unnamed-chunk-5-1.png" height="60%" style="display: block; margin: auto;" /> --- # Grafico estacional ``` r gg_season(df_mensual, AvgTemperature) + labs( title = "Estacionalidad Mensual de la Temperatura", x = "Mes", y = "Temperatura Promedio" ) + theme_minimal() ``` <img src="presentacion_final_files/figure-html/unnamed-chunk-6-1.png" height="60%" style="display: block; margin: auto;" /> --- # ACF ``` r df_mensual |> ACF(AvgTemperature) |> autoplot() + labs(title = "ACF de la temperatura mensual", y = "Autocorrelación", x = "Rezago") ``` <img src="presentacion_final_files/figure-html/unnamed-chunk-7-1.png" height="60%" style="display: block; margin: auto;" /> --- # PACF ``` r df_mensual |> PACF(AvgTemperature) |> autoplot() + labs(title = "PACF de la temperatura mensual", y = "Autocorrelación parcial", x = "Rezago") ``` <img src="presentacion_final_files/figure-html/unnamed-chunk-8-1.png" height="60%" style="display: block; margin: auto;" /> --- # Descomposicion de la serie ``` r dcmp <- df_mensual |> model( stl = STL(AvgTemperature) ) components(dcmp) |> autoplot() ``` <img src="presentacion_final_files/figure-html/unnamed-chunk-9-1.png" height="60%" style="display: block; margin: auto;" /> --- # Promedio Movil ``` r temp_ma12 <- df_mensual |> mutate(`12-MA` = slider::slide_dbl( AvgTemperature, mean, .before = 6, .after = 6, complete = TRUE )) ``` --- ``` r temp_ma12 |> autoplot(AvgTemperature) + geom_line(aes(y = `12-MA`), colour = "#D55E00") + labs( y = "Temperatura promedio", title = "Promedio móvil de 12 periodos (12-MA)" ) ``` <img src="presentacion_final_files/figure-html/unnamed-chunk-11-1.png" height="60%" style="display: block; margin: auto;" /> --- # Transformaciones matematicas Transformaciones Matemáticas En este caso no aplicamos transformaciones, porque la serie de temperatura es estable y fácil de interpretar. Logarítmica: Hay valores cercanos a cero y deformaría la serie. Raíz cuadrada: La variabilidad es baja; no aporta mejora. Inversa (1/x): Invierte el comportamiento natural y complica la lectura. Exponencial: Amplifica innecesariamente los valores. Box-Cox: Útil para estabilizar varianza, pero nuestra serie no presenta varianza creciente ni patrones que lo justifiquen. La serie no muestra problemas de escala ni varianza, por lo que no es necesario transformar. --- # Conclusiones La serie de temperatura muestra estacionalidad clara y estable, lo que facilita su modelado. No se requieren transformaciones matemáticas fuertes: la varianza es estable y la escala es uniforme. El análisis confirma que la predicción a corto y mediano plazo es confiable, pero el largo plazo presenta mayor incertidumbre. La combinación de descomposición, ACF/PACF y suavizamiento permite un modelo robusto y explicable. --- ## <center>✨🌌 **¡GRACIAS!** 🌌✨</center> <br> <!-- Fondo con estrellas simuladas --> <div style=" background: radial-gradient(circle at 50% 20%, rgba(255,255,255,0.25), transparent 70%), url('https://raw.githubusercontent.com/AndersonBY/MiniStars/master/stars-bg.png'); background-size: cover; padding: 60px 20px; border-radius: 20px; box-shadow: 0 0 35px rgba(80,120,255,0.45); "> <div style="text-align:center; font-size:34px; font-weight:bold; color:white; text-shadow:0 0 20px rgba(100,150,255,0.8);"> Gracias por tu atención </div> <br><br> <div style="text-align:center; font-style:italic; font-size:24px; color:#d6e4ff; text-shadow:0 0 12px rgba(200,200,255,0.6);"> “Las matemáticas son el lenguaje con el que Dios ha escrito el universo.” </div> <div style="text-align:center; font-size:18px; margin-top:8px; color:#b5c7ff; text-shadow:0 0 8px rgba(180,180,255,0.5);"> — Galileo Galilei </div> </div> <br><br>