library(tidyverse)
## Warning: package 'ggplot2' was built under R version 4.3.2
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.3 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ ggplot2 3.4.4 ✔ tibble 3.2.1
## ✔ lubridate 1.9.2 ✔ tidyr 1.3.0
## ✔ purrr 1.0.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(ggplot2)
library(forecast)
## Warning: package 'forecast' was built under R version 4.3.2
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
library(fma)
## Warning: package 'fma' was built under R version 4.3.2
library(fpp2)
## Warning: package 'fpp2' was built under R version 4.3.2
## ── Attaching packages ────────────────────────────────────────────── fpp2 2.5 ──
## ✔ expsmooth 2.3
## Warning: package 'expsmooth' was built under R version 4.3.2
##
help(woolyrnq)
## starting httpd help server ... done
help(gold)
help(gas)
autoplot(gold)
autoplot(woolyrnq)
autoplot(gas)
paste("Gold Frequency:", frequency(gold))
## [1] "Gold Frequency: 1"
paste("woolyrnq Frequency:", frequency(woolyrnq))
## [1] "woolyrnq Frequency: 4"
paste("Gas Frequency:",frequency(gas))
## [1] "Gas Frequency: 12"
paste("The outlier is on day: ", which.max(gold))
## [1] "The outlier is on day: 770"
tute1 <- read_csv("https://raw.githubusercontent.com/nealxun/forecasting_principle_and_practices/master/extrafiles/tute1.csv")
## New names:
## Rows: 100 Columns: 4
## ── Column specification
## ──────────────────────────────────────────────────────── Delimiter: "," chr
## (1): ...1 dbl (3): Sales, AdBudget, GDP
## ℹ 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.
## • `` -> `...1`
view(tute1)
mytimeseries_no_facets <- ts(tute1[,-1], start = 1981, frequency = 4)
autoplot(mytimeseries_no_facets)
mytimeseries <- ts(tute1[,-1], start = 1981, frequency = 4)
autoplot(mytimeseries, facets = TRUE)
retaildata <- readxl::read_excel("retail.xlsx", skip = 1)
head(retaildata)
## # A tibble: 6 × 190
## `Series ID` A3349335T A3349627V A3349338X A3349398A A3349468W
## <dttm> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 1982-04-01 00:00:00 303. 41.7 63.9 409. 65.8
## 2 1982-05-01 00:00:00 298. 43.1 64 405. 65.8
## 3 1982-06-01 00:00:00 298 40.3 62.7 401 62.3
## 4 1982-07-01 00:00:00 308. 40.9 65.6 414. 68.2
## 5 1982-08-01 00:00:00 299. 42.1 62.6 404. 66
## 6 1982-09-01 00:00:00 305. 42 64.4 412. 62.3
## # ℹ 184 more variables: A3349336V <dbl>, A3349337W <dbl>, A3349397X <dbl>,
## # A3349399C <dbl>, A3349874C <dbl>, A3349871W <dbl>, A3349790V <dbl>,
## # A3349556W <dbl>, A3349791W <dbl>, A3349401C <dbl>, A3349873A <dbl>,
## # A3349872X <dbl>, A3349709X <dbl>, A3349792X <dbl>, A3349789K <dbl>,
## # A3349555V <dbl>, A3349565X <dbl>, A3349414R <dbl>, A3349799R <dbl>,
## # A3349642T <dbl>, A3349413L <dbl>, A3349564W <dbl>, A3349416V <dbl>,
## # A3349643V <dbl>, A3349483V <dbl>, A3349722T <dbl>, A3349727C <dbl>, …
myts <- ts(retaildata[,"A3349468W"], frequency = 12, start = c(1982, 4))
autoplot(myts)
ggseasonplot(myts)
ggsubseriesplot(myts)
ggAcf(myts)
gglagplot(myts)
help(bicoal)
help(chicken)
help(dole)
help(usdeaths)
help(lynx)
help(goog)
help(writing)
help(fancy)
help(a10)
help(h02)
autoplot(bicoal)
autoplot(chicken)
autoplot(dole)
autoplot(usdeaths)
autoplot(lynx)
autoplot(goog) + ggtitle("Google Stock Price") + ylab("Closing Price") + xlab("Day")
autoplot(writing)
autoplot(fancy)
autoplot(a10)
autoplot(h02)
ggAcf(a10)
# Question 5
ggseasonplot(writing)
ggseasonplot(fancy)
ggseasonplot(a10)
ggseasonplot(h02)
ggsubseriesplot(writing)
ggsubseriesplot(fancy)
ggsubseriesplot(a10)
ggsubseriesplot(h02)