Consider the GDP information in global_economy. Plot the GDP per capita for each country over time. Which country has the highest GDP per capita? How has this changed over time?
Based on the graph and calculations, the country with the top GDP per capita is Monaco and Liechtenstein, with Liechenstein having the most change over time.
global_economy %>%
autoplot(GDP/Population) +
labs(title= "GDP per capita", y = "$US") +
theme(legend.position = 'none')
## Warning: Removed 3242 row(s) containing missing values (geom_path).
global_economy %>%
mutate(GDP_per_capita = GDP/Population) %>%
arrange(desc(GDP_per_capita)) %>%
select(Country, Year, GDP_per_capita) %>%
top_n(10)
## Warning: Current temporal ordering may yield unexpected results.
## i Suggest to sort by `Country`, `Year` first.
## Warning: Current temporal ordering may yield unexpected results.
## i Suggest to sort by `Country`, `Year` first.
## Warning: Current temporal ordering may yield unexpected results.
## i Suggest to sort by `Country`, `Year` first.
## Selecting by GDP_per_capita
## # A tsibble: 10 x 3 [1Y]
## # Key: Country [2]
## Country Year GDP_per_capita
## <fct> <dbl> <dbl>
## 1 Monaco 2014 185153.
## 2 Monaco 2008 180640.
## 3 Liechtenstein 2014 179308.
## 4 Liechtenstein 2013 173528.
## 5 Monaco 2013 172589.
## 6 Monaco 2016 168011.
## 7 Liechtenstein 2015 167591.
## 8 Monaco 2007 167125.
## 9 Liechtenstein 2016 164993.
## 10 Monaco 2015 163369.
For each of the following series, make a graph of the data. If transforming seems appropriate, do so and describe the effect.
United States GDP from global_economy. Slaughter of Victorian “Bulls, bullocks and steers” in aus_livestock. Victorian Electricity Demand from vic_elec. Gas production from aus_production.
The GDP series has a large variance so a log transformation seems appropriate. The log transformation flattens the graph and shows the same trend of each country.
# a
global_economy %>%
autoplot(GDP) +
theme(legend.position = 'none') +
labs(title = 'GDP')
## Warning: Removed 3242 row(s) containing missing values (geom_path).
global_economy %>%
autoplot(log(GDP)) +
theme(legend.position = 'none') +
labs(title = 'GDP with Log Transformation')
## Warning: Removed 3242 row(s) containing missing values (geom_path).
# b
aus_livestock %>%
autoplot(Count) +
labs(title = 'Austrailian Livestock Count') +
theme(legend.position = 'none')
# c
vic_elec %>%
autoplot(Demand) +
labs(title = 'Electricity Demand')
# d
aus_production %>%
autoplot(Gas) +
labs(title = 'Gas Production')
Why is a Box-Cox transformation unhelpful for the canadian_gas data?
The Box-Cox transformation does not help with the Canadian data because the trend is apparant without the transformation.
canadian_gas %>%
autoplot(Volume) +
labs(title = 'Volume of Canadian Gas')
lambda <- canadian_gas %>%
features(Volume, features = guerrero) %>%
pull(lambda_guerrero)
canadian_gas %>%
autoplot(box_cox(Volume, lambda)) +
labs(title = 'Canadian Gas Volume')
What Box-Cox transformation would you select for your retail data (from Exercise 8 in Section 2.10)?
I would use the Box-Cox transformation on the Monthly accidental graph has the seasonal pattern are apparant on both extremes.
For the following series, find an appropriate Box-Cox transformation in order to stabilise the variance. Tobacco from aus_production, Economy class passengers between Melbourne and Sydney from ansett, and Pedestrian counts at Southern Cross Station from pedestrian.
lambda_tobacco <- aus_production %>%
features(Tobacco, features = guerrero) %>%
pull(lambda_guerrero)
aus_production %>%
autoplot(box_cox(Tobacco, lambda_tobacco)) +
labs(y = '',
title = latex2exp::TeX(paste0(
'Transformed Tobacco with $\\lambda$ = ',
round(lambda_tobacco,2)
)))
## Warning: Removed 24 row(s) containing missing values (geom_path).
lambda_pass <- ansett %>%
filter(Class == 'Economy' & Airports == 'MEL-SYD') %>%
features(Passengers, features = guerrero) %>%
pull(lambda_guerrero)
ansett %>%
filter(Class == 'Economy' & Airports == 'MEL-SYD') %>%
autoplot(box_cox(Passengers, lambda_pass)) +
labs(y = '',
title = latex2exp::TeX(paste0(
'Transformed Passenger with $\\lambda$ = ',
round(lambda_pass,2)
)))
lambda_ped <- pedestrian %>%
filter(Sensor == 'Southern Cross Station') %>%
features(Sensor, features = guerrero) %>%
pull(lambda_guerrero)
pedestrian %>%
filter(Sensor == 'Southern Cross Station') %>%
autoplot(box_cox(Count, lambda_ped)) +
labs(y = '',
title = latex2exp::TeX(paste0(
'Transformed Station Passenger Count with $\\lambda$ = ',
round(lambda_ped,2)
)))
Consider the last five years of the Gas data from aus_production.
gas <- tail(aus_production, 5*4) %>% select(Gas)
The gas series has an upward trend wwith seasonalilty.
gas %>%
autoplot() +
labs(title = 'Gas Series')
## Plot variable not specified, automatically selected `.vars = Gas`
gas %>%
model(
classical_decomposition(Gas, type = 'multiplicative')
) %>%
components() %>%
autoplot() +
labs(title = 'Classical Multiplicative Decompisition of Gas')
## Warning: Removed 2 row(s) containing missing values (geom_path).
### c Yes, there is an upward trend with seasonality plus randomness.
dcmp <- gas %>%
model(stl = STL(Gas))
components(dcmp) %>%
as_tsibble() %>%
autoplot(Gas, color = 'gray') +
geom_line(aes(y=trend), color = '#D55E00') +
labs(title = 'Gas: Seaonsonal adjusted data')
### e Changing one of the observations to 300 change the direction of the trend line and increases the seasonal affect. The trend line begins with a decrease and then returns to a slight upward trend.
gas2 <- gas
gas2[2,1] <- 300
dcmp <- gas2 %>%
model(stl = STL(Gas))
components(dcmp) %>%
as_tsibble() %>%
autoplot(Gas, color = 'gray') +
geom_line(aes(y=trend), color = '#D55E00') +
labs(title = 'Gas2: Seaonsonal adjusted data')
### f Yes, it does make a difference where the outlier is located. Trends can completely change directions depending where the outlier is located. In the previous example, the outlier is located earlier in the series and turns the trend line into a v shape.
Figures 3.19 and 3.20 show the result of decomposing the number of persons in the civilian labour force in Australia each month from February 1978 to August 1995.
Write about 3–5 sentences describing the results of the decomposition. Pay particular attention to the scales of the graphs in making your interpretation.
The decomposition highlights the upward trend, seasonal pattern within a year, and the remaining values pf the civilian labor force in Austrailia. The series looks to be consistant through out with the exception in 1991/1992. The remainder graph highlists the larage impact that thhe values in 1991/1992 have on the series.
Is the recession of 1991/1992 visible in the estimated components?
Yes, the trend line increases sharply from 1985 to 1990 and flattens at 1991/1992. Additionally, the remainder has a large variance from end of 1990 to 1992.