Homework1

Please submit exercises 2.1, 2.2, 2.3, 2.4, 2.5 and 2.8 from the Hyndman online Forecasting book.

Exercise 2.1

Explore the following four time series: Bricks from aus_production, Lynx from pelt, Close from gafa_stock, Demand from vic_elec.

Solution

The time interval for Bricks from aus_production is yearly quarter, spanning from 1956 to 2010.

1.- Install and load the fpp3 package

if (!require("fpp3")) install.packages("fpp3")
## Loading required package: fpp3
## Warning: package 'fpp3' was built under R version 4.4.3
## Registered S3 method overwritten by 'tsibble':
##   method               from 
##   as_tibble.grouped_df dplyr
## ── Attaching packages ──────────────────────────────────────────── fpp3 1.0.2 ──
## ✔ tibble      3.2.1     ✔ tsibble     1.1.6
## ✔ dplyr       1.1.4     ✔ tsibbledata 0.4.1
## ✔ tidyr       1.3.1     ✔ feasts      0.4.2
## ✔ lubridate   1.9.3     ✔ fable       0.4.1
## ✔ ggplot2     3.5.1
## Warning: package 'tsibble' was built under R version 4.4.3
## Warning: package 'tsibbledata' was built under R version 4.4.3
## Warning: package 'feasts' was built under R version 4.4.3
## Warning: package 'fabletools' was built under R version 4.4.3
## Warning: package 'fable' was built under R version 4.4.3
## ── Conflicts ───────────────────────────────────────────────── fpp3_conflicts ──
## ✖ lubridate::date()    masks base::date()
## ✖ dplyr::filter()      masks stats::filter()
## ✖ tsibble::intersect() masks base::intersect()
## ✖ tsibble::interval()  masks lubridate::interval()
## ✖ dplyr::lag()         masks stats::lag()
## ✖ tsibble::setdiff()   masks base::setdiff()
## ✖ tsibble::union()     masks base::union()
library(fpp3)

2.- Explore the four time series for each dataset

  • Bricks from aus_production, The Bricks series represents the quarterly production per year of bricks in Australia.
print(aus_production)
## # A tsibble: 218 x 7 [1Q]
##    Quarter  Beer Tobacco Bricks Cement Electricity   Gas
##      <qtr> <dbl>   <dbl>  <dbl>  <dbl>       <dbl> <dbl>
##  1 1956 Q1   284    5225    189    465        3923     5
##  2 1956 Q2   213    5178    204    532        4436     6
##  3 1956 Q3   227    5297    208    561        4806     7
##  4 1956 Q4   308    5681    197    570        4418     6
##  5 1957 Q1   262    5577    187    529        4339     5
##  6 1957 Q2   228    5651    214    604        4811     7
##  7 1957 Q3   236    5317    227    603        5259     7
##  8 1957 Q4   320    6152    222    582        4735     6
##  9 1958 Q1   272    5758    199    554        4608     5
## 10 1958 Q2   233    5641    229    620        5196     7
## # ℹ 208 more rows
autoplot(aus_production, Bricks) +
  labs(title = "Year Quarterly Production of Bricks in Australia",
       x = "Year",
       y = "Bricks Produced")
## Warning: Removed 20 rows containing missing values or values outside the scale range
## (`geom_line()`).

In this plot we can see the Year quarterly production of bricks in Australia from 1956 to 2010. y-axis: number of bricks produced x-axis: represents the quarter and years

library(dplyr)
aus_production2 <- aus_production |> 
  mutate(Quarter = as.Date(Quarter))|> 
  select(Quarter, Bricks)
summary(aus_production2)
##     Quarter               Bricks     
##  Min.   :1956-01-01   Min.   :187.0  
##  1st Qu.:1969-07-24   1st Qu.:349.0  
##  Median :1983-02-15   Median :417.0  
##  Mean   :1983-02-15   Mean   :405.5  
##  3rd Qu.:1996-09-08   3rd Qu.:475.0  
##  Max.   :2010-04-01   Max.   :589.0  
##                       NA's   :20

From the summary, we can see that the Bricks variable has a minimum value of 187, a maximum value of 589, ranges from 1956-01-01 to 2010-04-01.

  • Lynx from pelt, The Lynx series represents the annual number of lynx trappings in Canada from 1821 to 1934.
print(pelt|> as_tibble()|> select(Year, Lynx))
## # A tibble: 91 × 2
##     Year  Lynx
##    <dbl> <dbl>
##  1  1845 30090
##  2  1846 45150
##  3  1847 49150
##  4  1848 39520
##  5  1849 21230
##  6  1850  8420
##  7  1851  5560
##  8  1852  5080
##  9  1853 10170
## 10  1854 19600
## # ℹ 81 more rows
summary(pelt)
##       Year           Hare             Lynx      
##  Min.   :1845   Min.   :  1800   Min.   : 3190  
##  1st Qu.:1868   1st Qu.: 12730   1st Qu.:11840  
##  Median :1890   Median : 40970   Median :29590  
##  Mean   :1890   Mean   : 45406   Mean   :28337  
##  3rd Qu.:1912   3rd Qu.: 71405   3rd Qu.:42520  
##  Max.   :1935   Max.   :152650   Max.   :79350

From the summary, we can see that the Lynx variable has a minimum value of 3190 , a maximum value of 79350 .

autoplot(pelt, Lynx) +
  labs(title = "Annual Number of Lynx Trappings in Canada",
       x = "Year",
       y = "Number of Lynx Trapped")

In this plot we can see the annual number of lynx trappings in Canada from 1821 to 1934. y-axis: number of lynx trapped x-axis: represents the years

  • Close from gafa_stock, The Close series represents the daily closing prices of Google, Amazon, Facebook, and Apple stocks from 2015 to 2020.
print(gafa_stock|> as_tibble()|> select(Symbol, Date, Close))
## # A tibble: 5,032 × 3
##    Symbol Date       Close
##    <chr>  <date>     <dbl>
##  1 AAPL   2014-01-02  79.0
##  2 AAPL   2014-01-03  77.3
##  3 AAPL   2014-01-06  77.7
##  4 AAPL   2014-01-07  77.1
##  5 AAPL   2014-01-08  77.6
##  6 AAPL   2014-01-09  76.6
##  7 AAPL   2014-01-10  76.1
##  8 AAPL   2014-01-13  76.5
##  9 AAPL   2014-01-14  78.1
## 10 AAPL   2014-01-15  79.6
## # ℹ 5,022 more rows
summary(gafa_stock|> select(Symbol, Date, Close))
##     Symbol               Date                Close        
##  Length:5032        Min.   :2014-01-02   Min.   :  53.53  
##  Class :character   1st Qu.:2015-04-02   1st Qu.: 118.54  
##  Mode  :character   Median :2016-06-30   Median : 259.51  
##                     Mean   :2016-07-01   Mean   : 465.56  
##                     3rd Qu.:2017-09-29   3rd Qu.: 744.79  
##                     Max.   :2018-12-31   Max.   :2039.51

From the summary, we can see that the Close variable has a minimum value of 53.53, a maximum value of 2039, ranges from 2014-01-02 to 2018-12-31.

autoplot(gafa_stock, Close) +
  labs(title = "Daily Closing Prices of Google, Amazon, Facebook, and Apple Stocks (2014-2018)",
       x = "Date",
       y = "Closing Price (USD)")

In this plot we can see the daily closing prices of Google, Amazon, Facebook, and Apple stocks from 2014 to 2018. y-axis: closing price in USD x-axis: represents the dates

  • Demand from vic_elec, The Demand series represents the half-hourly electricity demand in Victoria, Australia, from 2012 to 2014.
print(vic_elec|> as_tibble()|> select(Time, Demand))
## # A tibble: 52,608 × 2
##    Time                Demand
##    <dttm>               <dbl>
##  1 2012-01-01 00:00:00  4383.
##  2 2012-01-01 00:30:00  4263.
##  3 2012-01-01 01:00:00  4049.
##  4 2012-01-01 01:30:00  3878.
##  5 2012-01-01 02:00:00  4036.
##  6 2012-01-01 02:30:00  3866.
##  7 2012-01-01 03:00:00  3694.
##  8 2012-01-01 03:30:00  3562.
##  9 2012-01-01 04:00:00  3433.
## 10 2012-01-01 04:30:00  3359.
## # ℹ 52,598 more rows
summary(vic_elec|> select(Time, Demand))
##       Time                         Demand    
##  Min.   :2012-01-01 00:00:00   Min.   :2858  
##  1st Qu.:2012-09-30 22:52:30   1st Qu.:3969  
##  Median :2013-07-01 22:45:00   Median :4635  
##  Mean   :2013-07-01 22:45:00   Mean   :4665  
##  3rd Qu.:2014-04-01 23:37:30   3rd Qu.:5244  
##  Max.   :2014-12-31 23:30:00   Max.   :9345

From the summary, we can see that the Demand variable has a minimum value of 2858 , a maximum value of 9345 , ranges from 2012-01-01 00:00:00 to 2014-12-31 23:30:0.

# Plot the Demand series
autoplot(vic_elec, Demand) +
  labs(title = "Half-Hourly Electricity Demand in Victoria, Australia (2012-2014)",
       x = "Time",
       y = "Electricity Demand (MW)")

In this plot we can see the half-hourly electricity demand in Victoria, Australia, from 2012 to 2014. y-axis: electricity demand in megawatts (MW) x-axis: represents the time

Exercise 2.2

Use filter() to find what days corresponded to the peak closing price for each of the four stocks in gafa_stock.

Solution

The peak closing prices for each stock in gafa_stock are as follows:

peak_prices <- gafa_stock |>
  group_by(Symbol) |>
  filter(Close == max(Close)) |>
  select(Symbol, Date, Close)
print(peak_prices)
## # A tsibble: 4 x 3 [!]
## # Key:       Symbol [4]
## # Groups:    Symbol [4]
##   Symbol Date       Close
##   <chr>  <date>     <dbl>
## 1 AAPL   2018-10-03  232.
## 2 AMZN   2018-09-04 2040.
## 3 FB     2018-07-25  218.
## 4 GOOG   2018-07-26 1268.

Exercise 2.3

Download the file tute1.csv from the book website, open it in Excel (or some other spreadsheet application), and review its contents. You should find four columns of information. Columns B through D each contain a quarterly series, labelled Sales, AdBudget and GDP. Sales contains the quarterly sales for a small company over the period 1981-2005. AdBudget is the advertising budget and GDP is the gross domestic product. All series have been adjusted for inflation.

Solution

  1. Load csv file
tute1 <- read.csv("https://bit.ly/fpptute1")
#View(tute1)
  1. Convert the data to time series
mytimeseries <- tute1 |>
  mutate(Quarter = yearquarter(Quarter)) |>
  as_tsibble(index = Quarter)
print(mytimeseries)
## # A tsibble: 100 x 4 [1Q]
##    Quarter Sales AdBudget   GDP
##      <qtr> <dbl>    <dbl> <dbl>
##  1 1981 Q1 1020.     659.  252.
##  2 1981 Q2  889.     589   291.
##  3 1981 Q3  795      512.  291.
##  4 1981 Q4 1004.     614.  292.
##  5 1982 Q1 1058.     647.  279.
##  6 1982 Q2  944.     602   254 
##  7 1982 Q3  778.     531.  296.
##  8 1982 Q4  932.     608.  272.
##  9 1983 Q1  996.     638.  260.
## 10 1983 Q2  908.     582.  280.
## # ℹ 90 more rows

c.Construct time series plots of each of the three series

mytimeseries |>
  pivot_longer(-Quarter) |>
  ggplot(aes(x = Quarter, y = value, colour = name)) +
  geom_line() +
  facet_grid(name ~ ., scales = "free_y")

Check what happens when you don’t include facet_grid().

mytimeseries |>
  pivot_longer(-Quarter) |>
  ggplot(aes(x = Quarter, y = value, colour = name)) +
  geom_line()

when facet_grid(name ~ ., scales = “free_y”) is not included, all three series are plotted on the same graph, which can make it difficult to compare their trends and patterns due to differences in scale. The lines may overlap or be hard to distinguish, especially if one series has much larger values than the others. This can lead to misinterpretation of the data.

Exercise 2.4

The USgas package contains data on the demand for natural gas in the US.

Solution

  1. Install the USgas package.
if (!require("USgas")) install.packages("USgas")
## Loading required package: USgas
## Warning: package 'USgas' was built under R version 4.4.3
  1. Create a tsibble from us_total with year as the index and state as the key.
library(USgas)
us_total <- as_tsibble(us_total, index = year, key = state)
print(us_total)
## # A tsibble: 1,266 x 3 [1Y]
## # Key:       state [53]
##     year state        y
##    <int> <chr>    <int>
##  1  1997 Alabama 324158
##  2  1998 Alabama 329134
##  3  1999 Alabama 337270
##  4  2000 Alabama 353614
##  5  2001 Alabama 332693
##  6  2002 Alabama 379343
##  7  2003 Alabama 350345
##  8  2004 Alabama 382367
##  9  2005 Alabama 353156
## 10  2006 Alabama 391093
## # ℹ 1,256 more rows

c.Plot the annual natural gas consumption by state for the New England area (comprising the states of Maine, Vermont, New Hampshire, Massachusetts, Connecticut and Rhode Island).

library(ggplot2)
nds <- us_total |>
  filter(state %in% c("Maine", "Vermont", "New Hampshire", "Massachusetts", "Connecticut", "Rhode Island"))|>
  rename(consumption = y)
ggplot(nds, aes(x = year, y = consumption, color = state)) +
  geom_line() +
  labs(title = "Annual Natural Gas Consumption in New England States",
       x = "Year",
       y = "Natural Gas Consumption (in million cubic feet)") +
  theme_minimal()

Exercise 2.5

Solution

  1. Download tourism.xlsx from the book website and read it into R using readxl::read_excel().

a.1. Install and load the readxl package

if (!require("readxl")) install.packages("readxl")
## Loading required package: readxl
library(readxl)

a.2. Read the tourism.xlsx file into R

In order to load the data into a dataset and because I cant pass a URL in read_excel(), I will first download the file to the currently working directory. After that I will use read_excel to open the file.

download.file("https://otexts.com/fpp3/extrafiles/tourism.xlsx",
              "tourism.xlsx", mode = "wb")
tourism <- read_excel("tourism.xlsx")
print(tourism)
## # A tibble: 24,320 × 5
##    Quarter    Region   State           Purpose  Trips
##    <chr>      <chr>    <chr>           <chr>    <dbl>
##  1 1998-01-01 Adelaide South Australia Business  135.
##  2 1998-04-01 Adelaide South Australia Business  110.
##  3 1998-07-01 Adelaide South Australia Business  166.
##  4 1998-10-01 Adelaide South Australia Business  127.
##  5 1999-01-01 Adelaide South Australia Business  137.
##  6 1999-04-01 Adelaide South Australia Business  200.
##  7 1999-07-01 Adelaide South Australia Business  169.
##  8 1999-10-01 Adelaide South Australia Business  134.
##  9 2000-01-01 Adelaide South Australia Business  154.
## 10 2000-04-01 Adelaide South Australia Business  169.
## # ℹ 24,310 more rows

b.Create a tsibble which is identical to the tourism tsibble from the tsibble package.

b.1. Load the tsibble and dplyr packages

library(tsibble)

b.2 Creating a tsibble from the tourism data, ensuring we have keys and index properly set.

library(dplyr)
tourism_rebuilt <- tourism |>
  mutate(Quarter = yearquarter(as.Date(Quarter))) |>       
  as_tsibble(key = c(Region, State, Purpose),      
             index = Quarter)
print(tourism_rebuilt)
## # A tsibble: 24,320 x 5 [1Q]
## # Key:       Region, State, Purpose [304]
##    Quarter Region   State           Purpose  Trips
##      <qtr> <chr>    <chr>           <chr>    <dbl>
##  1 1998 Q1 Adelaide South Australia Business  135.
##  2 1998 Q2 Adelaide South Australia Business  110.
##  3 1998 Q3 Adelaide South Australia Business  166.
##  4 1998 Q4 Adelaide South Australia Business  127.
##  5 1999 Q1 Adelaide South Australia Business  137.
##  6 1999 Q2 Adelaide South Australia Business  200.
##  7 1999 Q3 Adelaide South Australia Business  169.
##  8 1999 Q4 Adelaide South Australia Business  134.
##  9 2000 Q1 Adelaide South Australia Business  154.
## 10 2000 Q2 Adelaide South Australia Business  169.
## # ℹ 24,310 more rows

c.Find what combination of Region and Purpose had the maximum number of overnight trips on average.

  • group_by(Region, Purpose) : Groups the data by Region and Purpose
  • summarise(avg_trips = mean(Trips, na.rm = TRUE)) : Calculates the average number of Trips for each group, ignoring any missing values
  • filter(avg_trips == max(avg_trips)) : Filters the results to keep only the group(s) with the maximum average number of Trips
max_avg_trips <- tourism_rebuilt |>
  group_by(Region, Purpose) |>
  summarise(avg_trips = mean(Trips, na.rm = TRUE)) |>
  filter(avg_trips == max(avg_trips))

print(max_avg_trips)
## # A tsibble: 76 x 4 [1Q]
## # Key:       Region, Purpose [76]
## # Groups:    Region [76]
##    Region                     Purpose  Quarter avg_trips
##    <chr>                      <chr>      <qtr>     <dbl>
##  1 Adelaide                   Visiting 2017 Q1     270. 
##  2 Adelaide Hills             Visiting 2002 Q4      81.1
##  3 Alice Springs              Holiday  1998 Q3      76.5
##  4 Australia's Coral Coast    Holiday  2014 Q3     198. 
##  5 Australia's Golden Outback Business 2017 Q3     174. 
##  6 Australia's North West     Business 2016 Q3     297. 
##  7 Australia's South West     Holiday  2016 Q1     612. 
##  8 Ballarat                   Visiting 2004 Q1     103. 
##  9 Barkly                     Holiday  1998 Q3      37.9
## 10 Barossa                    Holiday  2006 Q1      51.0
## # ℹ 66 more rows

d.Create a new tsibble which combines the Purposes and Regions, and just has total trips by State.

total_trips_by_state <- tourism_rebuilt |>
  as_tibble() |> 
  group_by(State, Quarter) |>
  summarise(total_trips = sum(Trips, na.rm = TRUE), .groups = "drop") |>
  as_tsibble(index = Quarter, key = State)

print(total_trips_by_state)
## # A tsibble: 640 x 3 [1Q]
## # Key:       State [8]
##    State Quarter total_trips
##    <chr>   <qtr>       <dbl>
##  1 ACT   1998 Q1        551.
##  2 ACT   1998 Q2        416.
##  3 ACT   1998 Q3        436.
##  4 ACT   1998 Q4        450.
##  5 ACT   1999 Q1        379.
##  6 ACT   1999 Q2        558.
##  7 ACT   1999 Q3        449.
##  8 ACT   1999 Q4        595.
##  9 ACT   2000 Q1        600.
## 10 ACT   2000 Q2        557.
## # ℹ 630 more rows

e.Plot the total trips by State.

library(ggplot2)
ggplot(total_trips_by_state, aes(x = Quarter, y = total_trips, color = State)) +
  geom_line() +
  labs(title = "Total Overnight Trips per State",
       x = "Quarter",
       y = "Total Overnight Trips") +
  theme_minimal()

Exercise 2.8

Use the following graphics functions: autoplot(), gg_season(), gg_subseries(), gg_lag(), ACF() and explore features from the following time series: “Total Private” Employed from us_employment, Bricks from aus_production, Hare from pelt, “H02” Cost from PBS, and Barrels from us_gasoline.

a.Can you spot any seasonality, cyclicity and trend? a.1. Load necessary libraries

library(fpp3)
library(ggplot2)

a.2. Define a function to create the plots for each time series

A function will be created to generate the required plots for each time series. This function will take a tsibble and the name of the value column as inputs, and produce the six specified plots.

plot_time_series <- function(data, value_col, title) {
  p1 <- autoplot(data, !!sym(value_col)) +
    labs(title = paste("Autoplot of ", title),
         x = "Time",
         y = value_col)
  
  p2 <- gg_season(data, !!sym(value_col)) +
    labs(title = paste("Seasonal Plot of ", title),
         x = "Season",
         y = value_col)
  
  p3 <- gg_subseries(data, !!sym(value_col)) +
    labs(title = paste("Subseries Plot of ", title),
         x = "Season",
         y = value_col)
  
  p4 <- gg_lag(data, !!sym(value_col), lags = 1:12) +
    labs(title = paste("Lag Plot of ", title),
         x = paste(value_col, "Lagged"),
         y = value_col)
  
  p5 <- data |>
    ACF(!!sym(value_col)) |>
    autoplot() +
    labs(title = paste("ACF of", title),
         x = "Lag",
         y = "ACF")
  
  list(p1, p2, p3, p4, p5)
}

Total Private Employed from us_employment

plot_time_series(us_employment |> filter(Title == "Total Private"), "Employed", "Total Private Employed")
## Warning: `gg_season()` was deprecated in feasts 0.4.2.
## ℹ Please use `ggtime::gg_season()` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## Warning: `gg_subseries()` was deprecated in feasts 0.4.2.
## ℹ Please use `ggtime::gg_subseries()` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## Warning: `gg_lag()` was deprecated in feasts 0.4.2.
## ℹ Please use `ggtime::gg_lag()` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## [[1]]

## 
## [[2]]

## 
## [[3]]

## 
## [[4]]

## 
## [[5]]

Autoplot of Total Private Employed plot, we can observe a strong growth in private employment, rising from about 25,000 in 1939 to over 125,000 in 2020. The series is not seasonal, it shows a clear upward trend with some fluctuations, particularly around the 2010.

Seasonal Plot of Total Private Employed plot, we can see that there are No strong seasonal variations, the lines are mostly flat across months, indicating that employment levels do not vary significantly by month.

Subseries Plot of Total Private Employed plot, strong upward trend, the blue lines are almost at the same level across months, indicating that there is no significant seasonal variation in employment levels.

Lag Plot of Total Private Employed plot, we can observe a strong positive correlation between the current employment levels and those from previous months and shows no meaningful seasonality.

ACF of Total Private Employed plot, The ACF confirms that Total Private Employed is a non stationary, trend dominated time series with very strong persistence. Each month’s value is highly correlated with many months before it. There is no seasonal structure.

Bricks from aus_production

plot_time_series(aus_production, "Bricks", "Bricks from aus_production")
## Warning: Removed 20 rows containing missing values (gg_lag).
## [[1]]
## Warning: Removed 20 rows containing missing values or values outside the scale range
## (`geom_line()`).

## 
## [[2]]
## Warning: Removed 20 rows containing missing values or values outside the scale range
## (`geom_line()`).

## 
## [[3]]
## Warning: Removed 5 rows containing missing values or values outside the scale range
## (`geom_line()`).

## 
## [[4]]

## 
## [[5]]

Autoplot of Bricks from aus_production plot, The series shows a strong upward trend until around 1980, followed by a volatile decline, with visible business cycles but no obvious seasonal pattern in the plot.

Seasonal Plot of Bricks from aus_production plot, Shows quarterly brick production by year with clear seasonality, production tends to peak in Q2–Q3 and decline in Q4 and Q1.

Subseries Plot of Bricks from aus_production plot, Breaks the data into separate panels for each quarter, and it confirms higher averanges in Q2 and Q3. The blue lines can determinate that seasonal difference exist.

Lag Plot of Bricks from aus_production plot, Each panel shows the relationship between bricks production and its lagged values with strong positive autocorelation.

ACF of Total Bricks from aus_production plot, ACF declines slowly, the series is no stationary.

Hare from pelt

plot_time_series2 <- function(data, value_col, title) {
  p1 <- autoplot(data, !!sym(value_col)) +
    labs(title = paste("Autoplot of ", title),
         x = "Time",
         y = value_col)
  
  
  p3 <- gg_subseries(data, !!sym(value_col)) +
    labs(title = paste("Subseries Plot of ", title),
         x = "Season",
         y = value_col)
  
  p4 <- gg_lag(data, !!sym(value_col), lags = 1:12) +
    labs(title = paste("Lag Plot of ", title),
         x = paste(value_col, "Lagged"),
         y = value_col)
  
  p5 <- data |>
    ACF(!!sym(value_col)) |>
    autoplot() +
    labs(title = paste("ACF of", title),
         x = "Lag",
         y = "ACF")
  
  list(p1,  p3, p4, p5)
}
plot_time_series2(pelt, "Hare", "Hare from pelt")
## [[1]]

## 
## [[2]]

## 
## [[3]]

## 
## [[4]]

Autoplot of Hare from pelt, Strong cyclical pattern with peaks about every 10 years

Seasonal Plot of Hare from pelt, sesonal plot couldnt be generated because the data is annual, so there is no seasonality to display.

Subseries Plot of Hare from pelt, breaks series into panels by season in this case by years.The blue line marks the mean, showing that populations often surge well above and crash well below the average.

Lag Plot of Hare from pelt, Shows non linear relationships, evidence of oscillatory (moving up and down in a repeating pattern) population cycles (regular rises and falls in the size of a population).

ACF of Total Hare from pelt, the hare population cycle is about 10 years long, but you see a strong negative dip at 5 years. The negative dip at lags 3 to 6 tells us populations crash within 3 to 6 years of a peak. The positive bump around lag 9 to 10 indicates populations tend to recover and peak again after 10 years.

H02 Cost from PBS

library(dplyr)
library(tsibble)

PBS_filter <- PBS |>
  filter(ATC2 == "H02") |>
  as_tibble() |>                              
  group_by(Month) |>
  summarise(H02_Cost = sum(Cost, na.rm = TRUE), .groups = "drop") |>
  as_tsibble(index = Month)   

#print(PBS_filter)

plot_time_series(PBS_filter, "H02_Cost", "H02 Cost from PBS")
## [[1]]

## 
## [[2]]

## 
## [[3]]

## 
## [[4]]

## 
## [[5]]

Autoplot of H02 Cost from PBS, Shows total H02 costs over time, with a clear upward trend from approximately 1992 to 2005, followed by a decline and stabilization around 2007. With a strong repeated seasonal pattern within each year: costs fall early in the year, then climb towards year end.

Seasonal Plot of H02 Cost from PBS, Each line is one year, aligned by months to show seasonal patterns. The plot reveals a consistent seasonal pattern where costs are lowest in February to March and peak towards the end of the year, indicating strong seasonality.

Subseries Plot of H02 Cost from PBS, This plot confirms months of February to March are systematically lower than other months.

Lag Plot of H02 Cost from PBS, Seasonal coloring shows monthly values line up consistently, supporting strong annual seasonality

ACF of Total H02 Cost from PBS, Evidence of both trend and seasonality

Barrels from us_gasoline

library(dplyr)
library(tsibble)
#print(us_gasoline)

us_gasoline_quarterly <- us_gasoline |>
  index_by(Quarter = yearquarter(Week)) |>   
  summarise(Barrels = sum(Barrels, na.rm = TRUE))

plot_time_series(us_gasoline_quarterly, "Barrels", "Barrels from us_gasoline")
## [[1]]

## 
## [[2]]

## 
## [[3]]

## 
## [[4]]

## 
## [[5]]

Autoplot of Barrels from us_gasoline, Shows a long term upward trend with short term fluctuations.

Seasonal Plot of Barrels from us_gasoline, Lower consumption in the first quarter, and higher in the second quarterly approximately, indicating strong seasonality.

Subseries Plot of Barrels from us_gasoline, Confirms seasonal pattern with Q1 systematically lower than other quarters.

Lag Plot of Barrels from us_gasoline, Quarterly gasoline consumption shows high persistence, meaning current values are strongly tied to past values. The diagonal clustering and seasonal color bands reveal a clear annual seasonal cycle (low in winter, high in summer) that repeats consistently.

ACF of Barrels from us_gasoline, Autocorrelations are positive and fairly strong at lags 1 to 4, indicating quarterly persistence. The ACF also shows a seasonal pattern with peaks at lags 4, 8, 12 and 16 confirming an annual seasonal cycle in gasoline consumption.

b.What do you learn about the series?

  • Total Private Employed from us_employment:This series shows a strong long-term upward trend in private employment, with little evidence of seasonal effects. Employment levels are highly persistent, as current values are strongly influenced by past values, reflecting cycles.

  • Bricks from aus_production: This series exhibits a clear seasonal pattern, with higher brick production in the second and third quarters of the year. There is also a long term trend.

  • Hare from pelt: This series displays pronounced cyclical behavior, with population peaks occurring roughly every 10 years. The population levels are highly variable, with significant fluctuations above and below the average. The series is non stationary, as indicated by the ACF.

  • H02 Cost from PBS: This series shows a clear upward trend in costs over time, with a strong seasonal pattern where costs are lowest in February to March and peak towards the end of the year.The ACF indicates persistence and annual seasonality.

  • Barrels from us_gasoline:This series demonstrates a long term upward trend in gasoline consumption, with strong seasonality. Consumption tends to be lowest in the first quarter (winter) and highest in the second and third quarters (spring and summer).

c.What can you say about the seasonal patterns?

  • Total Private Employed : No meaningful seasonal patterns are visible. Employment growth is mainly driven by a long term upward trend and cyclical recessions, not by systematic annual fluctuations.

  • Bricks from aus_production: Strong seasonality is evident. Production tends to be higher in Q2 and Q3 and lower in Q1 and Q4.

  • Hare from pelt: The series does not show annual seasonality, but instead exhibits multi year cycles (around 10 years).

  • H02 Cost from PBS: Clear and consistent annual seasonality. Costs are lowest in February to March and rise steadily to peak in November–December, repeating each year.

  • Barrels from us_gasoline:Strong annual seasonality. Consumption dips in Q1 (winter) and rises in Q2–Q3 (spring/summer), before tapering off slightly in Q4.

d.Can you identify any unusual years?

  • Total Private Employed from us_employment: No significant seasonal patterns are observed in this series.

  • Bricks from aus_production: The seasonal pattern is characterized by higher production in the second and third quarters, likely due to favorable weather conditions for construction during these months.

  • Hare from pelt: No seasonal patterns are observed in this annual series.

  • H02 Cost from PBS: The seasonal pattern shows lower costs in February to March, possibly due to lower demand for medications during these months, and higher costs towards the end of the year, potentially due to increased healthcare needs during winter.

  • Barrels from us_gasoline: The seasonal pattern indicates lower gasoline consumption in the first quarter, likely due to reduced travel during winter months, and higher consumption in the second quarter, possibly due to increased travel during summer.