library(readr)
library(ggplot2)
library(dplyr)
library(tsibble)
library(caTools)
library(fabletools)

`%>%` <- magrittr::`%>%`

VehicleSales <- read_delim("C:/Users/simon/Desktop/ACR_VehicleSales/VehicleSales.csv", 
                           delim = ";", escape_double = FALSE, col_types = cols(Date = col_date(format = "%d.%m.%Y"), 
                                                                                Sales = col_number()), trim_ws = TRUE)

plot(VehicleSales$Date,VehicleSales$Sales,col="purple",main="Predaj aut od roku 1976 až 2023",xlab = "Rok",ylab = "Cena")

VehicleSales <- VehicleSales[399:493,]
plot(VehicleSales$Date,VehicleSales$Sales,col="purple",main="Predaj aut od roku 2009 až 2016",xlab = "Rok",ylab = "Cena")

Popis dát

Zvolený časový rad predstavuje celkový počet predaných vozidiel v rokoch 2010 až 2016. Dáta som našla na stránke https://fred.stlouisfed.org/series/.

Zobrazenie

qplot(x = Date, y = Sales, data = VehicleSales, main = "Total Vehicle Sales",xlab ="" ,ylab = "Millions of units")

table<-c("length","min","max","median","mean","sd") %>% 
  sapply(function(x) eval(call(x, VehicleSales$Sales))) %>% 
  round(2) %>% 
  rbind()
head(table)
##   length  min  max median  mean   sd
## .     95 9.38 18.8  15.72 14.95 2.66

Rozdelenie na trénovaciu a validačnú vzorku

VehicleSales <- VehicleSales %>% 
  dplyr::mutate(Date = yearmonth(Date))
    
VehicleSales <- VehicleSales %>% 
  dplyr::mutate(
    sample = ifelse(Date < yearmonth("2015-01-01"), "train", "valid"),  # rozdelenie
    sample = factor(sample, levels = unique(sample))  # zafixovanie poradia
  ) %>% 
  tsibble::as_tsibble(index = Date, key = sample) 
feasts::autoplot(VehicleSales , Sales)