Email             :
Instagram     : https://www.instagram.com/putriangelinaw
RPubs            : https://rpubs.com/putriangelinaw/



1 Exercise 1

1. Use the help function to explore what the series gafa_stock, PBS, vic_elec and pelt represent.

?gafa_stock
?PBS
?vic_elec
?pelt

for more information:

  1. gafa_stock
  2. PBS
  3. vic_elec
  4. pelt

1.2 B

b. What is the time interval of each series?

The time interval of gafa_stock is daily, PBS is monthly, vic_elec is half-hourly, and pelt is annualy.

2 Exercise 2

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

## # A tsibble: 1 x 8 [!]
## # Key:       Symbol [1]
##   Symbol Date        Open  High   Low Close Adj_Close  Volume
##   <chr>  <date>     <dbl> <dbl> <dbl> <dbl>     <dbl>   <dbl>
## 1 AMZN   2018-09-05 2038. 2040. 1990. 1995.     1995. 8220600
## # A tsibble: 1 x 8 [!]
## # Key:       Symbol [1]
##   Symbol Date        Open  High   Low Close Adj_Close  Volume
##   <chr>  <date>     <dbl> <dbl> <dbl> <dbl>     <dbl>   <dbl>
## 1 AMZN   2018-09-04 2026. 2050.  2013 2040.     2040. 5721100
## # A tsibble: 1 x 8 [!]
## # Key:       Symbol [1]
##   Symbol Date        Open  High   Low Close Adj_Close  Volume
##   <chr>  <date>     <dbl> <dbl> <dbl> <dbl>     <dbl>   <dbl>
## 1 AMZN   2018-09-04 2026. 2050.  2013 2040.     2040. 5721100
## # A tsibble: 1 x 8 [!]
## # Key:       Symbol [1]
##   Symbol Date        Open  High   Low Close Adj_Close  Volume
##   <chr>  <date>     <dbl> <dbl> <dbl> <dbl>     <dbl>   <dbl>
## 1 AMZN   2018-09-04 2026. 2050.  2013 2040.     2040. 5721100

3 Exercise 3

3. Download the file tute1.csv here, 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.

3.1 A

a. You can read the data into R with the following script:

3.2 B

b. Convert the data to time series

4 Exercise 4

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

4.1 A

a. Install the USgas package.

4.2 B

b. Create a tsibble from us_total with year as the index and state as the key.

4.3 C

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).

5 Exercise 5

5. Follow the instructions below:

5.1 A

a. Download tourism.xlsx here and read it into R using readxl::read_excel().

5.2 B

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

5.3 C

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

5.4 D

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

6 Exercise 6

6. Create time plots of the following four time series: Bricks from aus_production, Lynx from pelt, Close from gafa_stock, Demand from vic_elec.

6.1 A

a. Use ? (or help()) to find out about the data in each series.

?aus_production
?pelt
?gafa_stock
?vic_elec

for more information;

  1. aus_production
  2. pelt
  3. gafa_stock
  4. vic_elec

7 Exercise 7

7. The aus_arrivals data set comprises quarterly international arrivals to Australia from Japan, New Zealand, UK and the US.

7.2 B

b. Can you identify any unusual observations?

  • The international arrivals to Australia from the four countries have different trends; while cyclic patterns are observed over time.
    • Japan: The arrivals increase from 1980 to 2006, and decrease since then, which is a bidirectional trend.
    • New Zealand: There is a clearly increasing trend.
    • UK: The arrivals increase from 1980 to 2005, while start decreasing slightly from 2006. The fluctuation increases over time.
    • US: There is a clearly increasing trend, while the increasing rate decreases since 2002.

8 Exercise 8

8. Monthly Australian retail data is provided in aus_retail. Select one of the time series as follows (but choose your own seed value):

8.1 A

a. Explore your chosen retail time series using the following functions:

  • autoplot(),
  • gg_season(),
  • gg_subseries(),
  • gg_lag(),
  • ACF() %>% autoplot()

8.2 B

b. Can you spot any seasonality, cyclicity and trend? What do you learn about the series?

  • From the autoplot, we can see a clear seasonal or cyclic pattern in the time series, and a upward trend.

    • The seasonal plot shows that there are indeed seasonal patterns. The plot also reveals that there is a typical big jump every year in December, and a drop in February. Sales begin to increase in the fall, peaking between November and December, then decreasing after January, likely to coincide with holiday shopping and sales for Christmas.

    • The seasonal subseries offers a new perspective on seasonality by showing the monthly mean values. We see a large increase from November to December and a decrease from December to February, but also a small, decreasing trend in turnover from January to June and a similar increase from July to November, before the big spike from November to December.

  • In this lag graph, the data is difficult to analyze. We can see some negative and positive relationships, but due to the high number of graphs and the fact that this is a monthly graph, it’s hard to tell much different.

    • The ACF shows powerful, statistically significant autocorrelation, showing that the lagged values get a linear relationship. The small drop in the amount of the ACF over time supports a pattern, as does seasonality with spikes at 12 and 24, the December increase.

10 Exercise 10

10. The following time plots and ACF plots correspond to four different time series. Your task is to match each time plot in the first row with one of the ACF plots in the second row.

  1. B
  2. A
  3. D
  4. C

11 Exercise 11

11. The aus_livestock data contains the monthly total number of pigs slaughtered in Victoria, Australia, from Jul 1972 to Dec 2018. Use filter() to extract pig slaughters in Victoria between 1990 and 1995. Use autoplot() and ACF() for this data. How do they differ from white noise? If a longer period of data is used, what difference does it make to the ACF?

12 Exercise 12

12. Use the following code to compute the daily changes in Google closing stock prices.

12.1 A

a. Why was it necessary to re-index the tsibble?

Because when we use filter for the GOOG, the interval for GOOG by Date will be scrambled, misleading, and are not the same for each row. So we need to re-index which is used to row sequence number hence the interval for each row is same.

12.3 C

c. Do the changes in the stock prices look like white noise?

There are total 30 lags, 5% of 30;

## [1] 1.5

If there are more than 1.5 lags that out of the bound, the data series isn’t white noises. From the plot above, we can see that there are 4 lags that out of the bound, hence the data series isn’t white noises.