Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ipi.df <- read_csv('data/ipi.csv')
- #----------------------------------------------------------------------------
- # Exercise 1. Transform ipi.df from:
- #
- # date ipi
- # <chr> <dbl>
- # 2017M11 104
- # to:
- #
- # date ipi
- # <date> <dbl>
- # 2017-11-01 104
- #----------------------------------------------------------------------------
- # Sol:
- ipi.df %<>%
- separate(date, into = c("year", "month"), sep = "M") %>%
- mutate(date = as.Date(paste(year, month, 01, sep = "-"))) %>%
- select(date, ipi)
- #----------------------------------------------------------------------------
- # Exercise 2. Plot the data as a time series using ggplot2
- #----------------------------------------------------------------------------
- ipi.df %>%
- ggplot(aes(x = date, y = ipi)) +
- geom_line(size = 1, color = palette_light()[[1]]) +
- geom_smooth(method = "loess") +
- labs(title = "Indice De Produccion Industrial De Cantabria", x = "", y = "IPI") +
- scale_y_continuous() +
- scale_x_date(date_breaks = "1 year", date_labels = "%Y") +
- theme_tq()
- #----------------------------------------------------------------------------
- # Exercise 3. Using ggplot, plot ipi.df IPI series with the the
- # short_term_mean and the long_term_mean
- #----------------------------------------------------------------------------
- ipi.df %>%
- mutate(short_mean = short_term_mean(ipi),
- long_term_mean = long_term_mean(ipi)) %>%
- gather(key = "indice", value ='val', -date) %>%
- ggplot(aes(x = date, y = val, color=indice)) +
- geom_line(size = .5, color = palette_light()[[1]]) +
- geom_smooth(method = "loess") +
- labs(title = "Indice De Produccion Industrial De Cantabria", x = "", y = "IPI") +
- scale_y_continuous() +
- scale_x_date(date_breaks = "1 year", date_labels = "%Y") +
- theme_tq()
- #----------------------------------------------------------------------------
- # Exercise 4. Fit a Holt-Winters leaving all parameter in blank.
- # Get the proposed α, β and γ.
- # Check the final sum of squared errors achieved in optimizing
- #----------------------------------------------------------------------------
- fit_hw <- HoltWinters(ipi_train)
- round(fit_hw$alpha, 2)
- round(fit_hw$beta, 2)
- round(fit_hw$gamma, 2)
- plot(fit_hw)
- fit_hw$SSE
Add Comment
Please, Sign In to add comment