This report presents solutions for the time series analysis questions. Each question includes R code, outputs, and explanatory notes.
Part 1a: Use autoplot() to Plot Each Series
library(fpp2)
## Warning: package 'fpp2' was built under R version 4.1.3
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
## -- Attaching packages ---------------------------------------------- fpp2 2.5 --
## v ggplot2 3.5.1 v fma 2.5
## v forecast 8.23.0 v expsmooth 2.3
## Warning: package 'fma' was built under R version 4.1.3
## Warning: package 'expsmooth' was built under R version 4.1.3
##
# Frequency of each series
frequency(gold) # Typically 1 (daily data)
## [1] 1
frequency(woolyrnq) # Quarterly data, frequency = 4
## [1] 4
frequency(gas) # Monthly data, frequency = 12
## [1] 12
Part 1b: Find the Frequency of Each Series
# Use autoplot() to plot each series
autoplot(gold) + ggtitle("Gold Prices")
# Use autoplot() to plot each series
autoplot(woolyrnq) + ggtitle("Wool Yarn Production")
# Use autoplot() to plot each series
autoplot(gas) + ggtitle("Gas Production")
Part 1c: Use which.max() to Find the Outlier in the gold Series
# Find the observation with the maximum value in the gold series
which.max(gold)
## [1] 770
outlier_index <- which.max(gold)
outlier_index
## [1] 770
gold[770]
## [1] 593.7
outlier_value <- gold[outlier_index]
outlier_value
## [1] 593.7
# Print the result
cat("The outlier is at index:", outlier_index, "with value:", outlier_value, "\n")
## The outlier is at index: 770 with value: 593.7