Use the fpp2 package on R studio
For each of the following series make a graph of the data, describe the main features and, if transforming seems appropriate, do so and describe the effect.
a) Monthly total of people on unemployed benefits in Australia (January 1956 - July 1992) [data set dole].
b) Monthly total of accidental deaths in the United States (January 1973 - December 1978) [data set usdeaths].
c) Quarterly production of bricks (in millions of units) at Portland, Australia (March 1956 - September 1994) [data set bricksq].
if (!require("fma")) install.packages("fma")
library(fma) find_dataset <- function(string, pkg) { sets <- data(package=pkg)$results[, c('Item', 'Title')] row <- grep(string, sets[, 'Title']) df <- data.frame("Dataset"=sets[row, 'Item'], "Description"=sets[row, 'Title'], row.names=NULL) return(df) } plot_TimeSeries <- function(ts, i=1:12, l=month.abb, x, y, desc) { par(mfrow=c(2, 2), oma=c(0, 0, 1, 0)) plot(ts, ylab=y, xlab=x, main="Time Plot") seasonplot(ts, ylab=y, xlab=x, main="Seasonal Plot", col=1:20, pch=19) monthplot(ts, ylab=y, xlab=x, xaxt="n", main="Seasonal Subseries Plot") axis(1, at=i, labels=l, cex=0.8) title(desc, outer=TRUE) lambda <- BoxCox.lambda(ts) title <- paste0("Box-Cox Transformation (", round(lambda, 3), ")") plot(BoxCox(ts, lambda), ylab="", main=title) plot(decompose(ts)) }
First the function named find_dataset() created above searches for datasets in a specified package by keyword. Then the function named plot_TimeSeries() created above takes the dataset, periods, period labels, and data description as inputs. The function then outputs a Time Plot, Seasonal Plot, Seasonal Subseries Plot, Box-Cox transformed Time Plot, and a Decomposition Plot. The Time Plot is a line graph that plots each observed value against the time of the observation, with a single line connecting each observation across the entire period. The Seasonal Plot is also a line graph that plots each observed value against the time of the observation, but with seasons in the x-axis and separate lines connecting the observations for a given year across seasons. The Seasonal Subseries Plot is another line graph that plots each observed value against the time of the observation, but with seasons in the x-axis and separate lines connecting the observations for a given season across years–plus a line in each season representing the mean for each season. The Box-Cox transformation which is used to normalize data and improve forecasting is implemented using a λλ parameter calculated by the BoxCox() function and then plotted using a Time Plot. The Decomposition Plot decomposes and plots the observed values, the underlying trend, seasonality, and randomness of the time series data.
#a
find_dataset("Australia", "fma")
plot_TimeSeries(dole / 1000, 1:12, month.abb, "Month", "Claims (Thousands)", "People on Unemployment in Australia (January 1956-July 1992)")
#b
find_dataset("death", "fma")
plot_TimeSeries(usdeaths, 1:12, month.abb, "Month", "Accidental Deaths", "Accidental Deaths in U.S. (January 1973-December 1978)")
#c
find_dataset("brick", "fma")
plot_TimeSeries(bricksq, 1:4, c('Q1','Q2','Q3','Q4'), "Month", "Bricks (Millions)", "Bricks Produced in Portland, Australia (March 1956-September 1994)")
Get Answers For Free
Most questions answered within 1 hours.