Download some monthly Australian retail data from http://robjhyndman.com/data/retail.xlsx. These represent retail sales in various categories for different Australian states, and are stored in a MS-Excel file.
You can read the data into R with the following script:
Series ID | Description |
---|---|
23367261 | Turnover ; New South Wales ; Supermarket and grocery stores ; |
23383763 | Turnover ; New South Wales ; Liquor retailing ; |
23914912 | Turnover ; New South Wales ; Other specialised food retailing ; |
25180347 | Turnover ; New South Wales ; Food retailing ; |
25190644 | Turnover ; New South Wales ; Furniture, floor coverings, houseware and textile goods retailing ; |
25570285 | Turnover ; New South Wales ; Electrical and electronic goods retailing ; |
25893076 | Turnover ; New South Wales ; Hardware, building and garden supplies retailing ; |
26021927 | Turnover ; New South Wales ; Household goods retailing ; |
26096129 | Turnover ; New South Wales ; Clothing retailing ; |
26435934 | Turnover ; New South Wales ; Footwear and other personal accessory retailing ; |
26877708 | Turnover ; New South Wales ; Clothing, footwear and personal accessory retailing ; |
26963817 | Turnover ; New South Wales ; Department stores ; |
27004783 | Turnover ; New South Wales ; Newspaper and book retailing ; |
27307395 | Turnover ; New South Wales ; Other recreational goods retailing ; |
A3349401C | Turnover ; New South Wales ; Pharmaceutical, cosmetic and toiletry goods retailing ; |
A3349873A | Turnover ; New South Wales ; Other retailing n.e.c. ; |
A3349872X | Turnover ; New South Wales ; Other retailing ; |
A3349709X | Turnover ; New South Wales ; Cafes, restaurants and catering services ; |
A3349792X | Turnover ; New South Wales ; Takeaway food services ; |
A3349789K | Turnover ; New South Wales ; Cafes, restaurants and takeaway food services ; |
A3349555V | Turnover ; New South Wales ; Total (Industry) ; |
A3349565X | Turnover ; Victoria ; Supermarket and grocery stores ; |
A3349414R | Turnover ; Victoria ; Liquor retailing ; |
A3349799R | Turnover ; Victoria ; Other specialised food retailing ; |
A3349642T | Turnover ; Victoria ; Food retailing ; |
A3349413L | Turnover ; Victoria ; Furniture, floor coverings, houseware and textile goods retailing ; |
A3349564W | Turnover ; Victoria ; Electrical and electronic goods retailing ; |
A3349416V | Turnover ; Victoria ; Hardware, building and garden supplies retailing ; |
A3349643V | Turnover ; Victoria ; Household goods retailing ; |
A3349483V | Turnover ; Victoria ; Clothing retailing ; |
A3349722T | Turnover ; Victoria ; Footwear and other personal accessory retailing ; |
A3349727C | Turnover ; Victoria ; Clothing, footwear and personal accessory retailing ; |
A3349641R | Turnover ; Victoria ; Department stores ; |
A3349639C | Turnover ; Victoria ; Newspaper and book retailing ; |
A3349415T | Turnover ; Victoria ; Other recreational goods retailing ; |
A3349349F | Turnover ; Victoria ; Pharmaceutical, cosmetic and toiletry goods retailing ; |
A3349563V | Turnover ; Victoria ; Other retailing n.e.c. ; |
A3349350R | Turnover ; Victoria ; Other retailing ; |
A3349640L | Turnover ; Victoria ; Cafes, restaurants and catering services ; |
A3349566A | Turnover ; Victoria ; Takeaway food services ; |
A3349417W | Turnover ; Victoria ; Cafes, restaurants and takeaway food services ; |
A3349352V | Turnover ; Victoria ; Total (Industry) ; |
A3349882C | Turnover ; Queensland ; Supermarket and grocery stores ; |
A3349561R | Turnover ; Queensland ; Liquor retailing ; |
A3349883F | Turnover ; Queensland ; Other specialised food retailing ; |
A3349721R | Turnover ; Queensland ; Food retailing ; |
A3349478A | Turnover ; Queensland ; Furniture, floor coverings, houseware and textile goods retailing ; |
A3349637X | Turnover ; Queensland ; Electrical and electronic goods retailing ; |
A3349479C | Turnover ; Queensland ; Hardware, building and garden supplies retailing ; |
A3349797K | Turnover ; Queensland ; Household goods retailing ; |
A3349477X | Turnover ; Queensland ; Clothing retailing ; |
A3349719C | Turnover ; Queensland ; Footwear and other personal accessory retailing ; |
A3349884J | Turnover ; Queensland ; Clothing, footwear and personal accessory retailing ; |
A3349562T | Turnover ; Queensland ; Department stores ; |
A3349348C | Turnover ; Queensland ; Newspaper and book retailing ; |
A3349480L | Turnover ; Queensland ; Other recreational goods retailing ; |
A3349476W | Turnover ; Queensland ; Pharmaceutical, cosmetic and toiletry goods retailing ; |
A3349881A | Turnover ; Queensland ; Other retailing n.e.c. ; |
A3349410F | Turnover ; Queensland ; Other retailing ; |
A3349481R | Turnover ; Queensland ; Cafes, restaurants and catering services ; |
A3349718A | Turnover ; Queensland ; Takeaway food services ; |
A3349411J | Turnover ; Queensland ; Cafes, restaurants and takeaway food services ; |
A3349638A | Turnover ; Queensland ; Total (Industry) ; |
A3349654A | Turnover ; South Australia ; Supermarket and grocery stores ; |
A3349499L | Turnover ; South Australia ; Liquor retailing ; |
A3349902A | Turnover ; South Australia ; Other specialised food retailing ; |
A3349432V | Turnover ; South Australia ; Food retailing ; |
A3349656F | Turnover ; South Australia ; Furniture, floor coverings, houseware and textile goods retailing ; |
A3349361W | Turnover ; South Australia ; Electrical and electronic goods retailing ; |
A3349501L | Turnover ; South Australia ; Hardware, building and garden supplies retailing ; |
A3349503T | Turnover ; South Australia ; Household goods retailing ; |
A3349360V | Turnover ; South Australia ; Clothing retailing ; |
A3349903C | Turnover ; South Australia ; Footwear and other personal accessory retailing ; |
A3349905J | Turnover ; South Australia ; Clothing, footwear and personal accessory retailing ; |
A3349658K | Turnover ; South Australia ; Department stores ; |
A3349575C | Turnover ; South Australia ; Newspaper and book retailing ; |
A3349428C | Turnover ; South Australia ; Other recreational goods retailing ; |
A3349500K | Turnover ; South Australia ; Pharmaceutical, cosmetic and toiletry goods retailing ; |
A3349577J | Turnover ; South Australia ; Other retailing n.e.c. ; |
A3349433W | Turnover ; South Australia ; Other retailing ; |
A3349576F | Turnover ; South Australia ; Cafes, restaurants and catering services ; |
A3349574A | Turnover ; South Australia ; Takeaway food services ; |
A3349816F | Turnover ; South Australia ; Cafes, restaurants and takeaway food services ; |
A3349815C | Turnover ; South Australia ; Total (Industry) ; |
A3349744F | Turnover ; Western Australia ; Supermarket and grocery stores ; |
A3349823C | Turnover ; Western Australia ; Liquor retailing ; |
A3349508C | Turnover ; Western Australia ; Other specialised food retailing ; |
A3349742A | Turnover ; Western Australia ; Food retailing ; |
A3349661X | Turnover ; Western Australia ; Furniture, floor coverings, houseware and textile goods retailing ; |
A3349660W | Turnover ; Western Australia ; Electrical and electronic goods retailing ; |
A3349909T | Turnover ; Western Australia ; Hardware, building and garden supplies retailing ; |
A3349824F | Turnover ; Western Australia ; Household goods retailing ; |
A3349507A | Turnover ; Western Australia ; Clothing retailing ; |
A3349580W | Turnover ; Western Australia ; Footwear and other personal accessory retailing ; |
A3349825J | Turnover ; Western Australia ; Clothing, footwear and personal accessory retailing ; |
A3349434X | Turnover ; Western Australia ; Department stores ; |
A3349822A | Turnover ; Western Australia ; Newspaper and book retailing ; |
A3349821X | Turnover ; Western Australia ; Other recreational goods retailing ; |
A3349581X | Turnover ; Western Australia ; Pharmaceutical, cosmetic and toiletry goods retailing ; |
A3349908R | Turnover ; Western Australia ; Other retailing n.e.c. ; |
A3349743C | Turnover ; Western Australia ; Other retailing ; |
A3349910A | Turnover ; Western Australia ; Cafes, restaurants and catering services ; |
A3349435A | Turnover ; Western Australia ; Takeaway food services ; |
A3349365F | Turnover ; Western Australia ; Cafes, restaurants and takeaway food services ; |
A3349746K | Turnover ; Western Australia ; Total (Industry) ; |
A3349370X | Turnover ; Tasmania ; Supermarket and grocery stores ; |
A3349754K | Turnover ; Tasmania ; Liquor retailing ; |
A3349670A | Turnover ; Tasmania ; Other specialised food retailing ; |
A3349764R | Turnover ; Tasmania ; Food retailing ; |
A3349916R | Turnover ; Tasmania ; Furniture, floor coverings, houseware and textile goods retailing ; |
A3349589T | Turnover ; Tasmania ; Electrical and electronic goods retailing ; |
A3349590A | Turnover ; Tasmania ; Hardware, building and garden supplies retailing ; |
A3349765T | Turnover ; Tasmania ; Household goods retailing ; |
A3349371A | Turnover ; Tasmania ; Clothing retailing ; |
A3349588R | Turnover ; Tasmania ; Footwear and other personal accessory retailing ; |
A3349763L | Turnover ; Tasmania ; Clothing, footwear and personal accessory retailing ; |
A3349372C | Turnover ; Tasmania ; Department stores ; |
A3349442X | Turnover ; Tasmania ; Newspaper and book retailing ; |
A3349591C | Turnover ; Tasmania ; Other recreational goods retailing ; |
A3349671C | Turnover ; Tasmania ; Pharmaceutical, cosmetic and toiletry goods retailing ; |
A3349669T | Turnover ; Tasmania ; Other retailing n.e.c. ; |
A3349521W | Turnover ; Tasmania ; Other retailing ; |
A3349443A | Turnover ; Tasmania ; Cafes, restaurants and catering services ; |
A3349835L | Turnover ; Tasmania ; Takeaway food services ; |
A3349520V | Turnover ; Tasmania ; Cafes, restaurants and takeaway food services ; |
A3349841J | Turnover ; Tasmania ; Total (Industry) ; |
A3349925T | Turnover ; Northern Territory ; Supermarket and grocery stores ; |
A3349450X | Turnover ; Northern Territory ; Liquor retailing ; |
A3349679W | Turnover ; Northern Territory ; Other specialised food retailing ; |
A3349527K | Turnover ; Northern Territory ; Food retailing ; |
A3349526J | Turnover ; Northern Territory ; Furniture, floor coverings, houseware and textile goods retailing ; |
A3349598V | Turnover ; Northern Territory ; Electrical and electronic goods retailing ; |
A3349766V | Turnover ; Northern Territory ; Hardware, building and garden supplies retailing ; |
A3349600V | Turnover ; Northern Territory ; Household goods retailing ; |
A3349680F | Turnover ; Northern Territory ; Clothing retailing ; |
A3349378T | Turnover ; Northern Territory ; Footwear and other personal accessory retailing ; |
A3349767W | Turnover ; Northern Territory ; Clothing, footwear and personal accessory retailing ; |
A3349451A | Turnover ; Northern Territory ; Department stores ; |
A3349924R | Turnover ; Northern Territory ; Newspaper and book retailing ; |
A3349843L | Turnover ; Northern Territory ; Other recreational goods retailing ; |
A3349844R | Turnover ; Northern Territory ; Pharmaceutical, cosmetic and toiletry goods retailing ; |
A3349376L | Turnover ; Northern Territory ; Other retailing n.e.c. ; |
A3349599W | Turnover ; Northern Territory ; Other retailing ; |
A3349377R | Turnover ; Northern Territory ; Cafes, restaurants and catering services ; |
A3349779F | Turnover ; Northern Territory ; Takeaway food services ; |
A3349379V | Turnover ; Northern Territory ; Cafes, restaurants and takeaway food services ; |
A3349842K | Turnover ; Northern Territory ; Total (Industry) ; |
A3349532C | Turnover ; Australian Capital Territory ; Supermarket and grocery stores ; |
A3349931L | Turnover ; Australian Capital Territory ; Liquor retailing ; |
A3349605F | Turnover ; Australian Capital Territory ; Other specialised food retailing ; |
A3349688X | Turnover ; Australian Capital Territory ; Food retailing ; |
A3349456L | Turnover ; Australian Capital Territory ; Furniture, floor coverings, houseware and textile goods retailing ; |
A3349774V | Turnover ; Australian Capital Territory ; Electrical and electronic goods retailing ; |
A3349848X | Turnover ; Australian Capital Territory ; Hardware, building and garden supplies retailing ; |
A3349457R | Turnover ; Australian Capital Territory ; Household goods retailing ; |
A3349851L | Turnover ; Australian Capital Territory ; Clothing retailing ; |
A3349604C | Turnover ; Australian Capital Territory ; Footwear and other personal accessory retailing ; |
A3349608L | Turnover ; Australian Capital Territory ; Clothing, footwear and personal accessory retailing ; |
A3349609R | Turnover ; Australian Capital Territory ; Department stores ; |
A3349773T | Turnover ; Australian Capital Territory ; Newspaper and book retailing ; |
A3349852R | Turnover ; Australian Capital Territory ; Other recreational goods retailing ; |
A3349775W | Turnover ; Australian Capital Territory ; Pharmaceutical, cosmetic and toiletry goods retailing ; |
A3349776X | Turnover ; Australian Capital Territory ; Other retailing n.e.c. ; |
A3349607K | Turnover ; Australian Capital Territory ; Other retailing ; |
A3349849A | Turnover ; Australian Capital Territory ; Cafes, restaurants and catering services ; |
A3349850K | Turnover ; Australian Capital Territory ; Takeaway food services ; |
A3349606J | Turnover ; Australian Capital Territory ; Cafes, restaurants and takeaway food services ; |
A3349932R | Turnover ; Australian Capital Territory ; Total (Industry) ; |
A3349862V | Turnover ; Total (State) ; Supermarket and grocery stores ; |
A3349462J | Turnover ; Total (State) ; Liquor retailing ; |
A3349463K | Turnover ; Total (State) ; Other specialised food retailing ; |
A3349334R | Turnover ; Total (State) ; Food retailing ; |
A3349863W | Turnover ; Total (State) ; Furniture, floor coverings, houseware and textile goods retailing ; |
A3349781T | Turnover ; Total (State) ; Electrical and electronic goods retailing ; |
A3349861T | Turnover ; Total (State) ; Hardware, building and garden supplies retailing ; |
A3349626T | Turnover ; Total (State) ; Household goods retailing ; |
A3349617R | Turnover ; Total (State) ; Clothing retailing ; |
A3349546T | Turnover ; Total (State) ; Footwear and other personal accessory retailing ; |
A3349787F | Turnover ; Total (State) ; Clothing, footwear and personal accessory retailing ; |
A3349333L | Turnover ; Total (State) ; Department stores ; |
A3349860R | Turnover ; Total (State) ; Newspaper and book retailing ; |
A3349464L | Turnover ; Total (State) ; Other recreational goods retailing ; |
A3349389X | Turnover ; Total (State) ; Pharmaceutical, cosmetic and toiletry goods retailing ; |
A3349461F | Turnover ; Total (State) ; Other retailing n.e.c. ; |
A3349788J | Turnover ; Total (State) ; Other retailing ; |
A3349547V | Turnover ; Total (State) ; Cafes, restaurants and catering services ; |
A3349388W | Turnover ; Total (State) ; Takeaway food services ; |
A3349870V | Turnover ; Total (State) ; Cafes, restaurants and takeaway food services ; |
A3349396W | Turnover ; Total (State) ; Total (Industry) ; |
Select one of the time series as follows (but replace the column name with your own chosen column):
myts
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
1982 17.3 18.1 18.1 18.9 19.0 18.4 20.9 22.4 29.7
1983 22.9 20.8 23.5 21.7 21.4 20.8 21.3 22.6 22.4 22.9 24.0 33.5
1984 22.2 20.8 21.9 20.4 20.6 20.4 19.3 20.4 20.5 21.4 23.5 29.6
1985 23.8 21.6 23.2 22.3 22.4 20.8 20.7 21.8 21.9 23.4 24.9 32.4
1986 25.8 24.7 26.9 23.5 24.2 22.4 22.5 23.9 23.6 24.7 26.9 34.2
1987 28.1 25.9 26.4 25.5 25.4 24.0 26.4 26.4 27.7 28.6 28.5 38.7
1988 31.0 27.9 29.1 28.0 26.2 25.8 28.5 28.2 31.0 29.7 34.5 51.3
1989 22.4 23.4 25.1 22.4 22.5 22.4 22.5 23.5 23.1 22.8 27.1 44.5
1990 22.7 23.9 26.4 25.8 25.1 24.0 23.6 25.3 24.5 26.9 29.3 45.7
1991 24.3 22.3 25.1 22.5 25.0 22.8 23.4 26.4 24.2 26.7 28.9 42.6
1992 27.3 26.4 29.3 29.0 27.0 26.1 28.5 27.0 28.7 30.8 29.7 51.8
1993 28.3 26.5 28.5 28.1 26.6 23.1 25.1 25.2 26.5 27.8 28.1 47.8
1994 24.8 25.5 30.9 27.1 27.5 27.5 25.7 25.0 26.9 28.4 28.8 46.8
1995 26.4 25.2 28.7 26.5 27.9 28.8 27.7 28.8 30.1 28.3 32.8 52.5
1996 27.6 28.5 30.9 30.2 30.5 30.2 33.5 35.4 36.5 39.7 41.6 64.3
1997 39.4 37.2 41.4 39.4 42.1 39.8 42.1 44.5 43.5 46.8 51.5 82.8
1998 46.0 43.9 47.1 46.5 49.7 44.5 52.7 52.6 53.8 51.6 60.0 93.8
1999 56.7 54.1 59.3 54.2 56.3 53.8 56.7 56.3 60.6 65.7 69.1 110.0
2000 54.8 56.7 60.6 56.5 54.5 62.8 57.6 62.1 60.6 67.3 75.7 114.9
2001 65.3 62.0 70.1 67.0 69.6 65.9 62.5 62.8 64.1 71.1 77.0 119.1
2002 68.7 60.9 70.4 60.1 63.6 58.6 66.6 70.3 69.9 74.0 80.6 120.1
2003 75.5 68.8 72.7 75.2 74.1 73.0 77.4 76.3 78.2 80.8 87.8 135.6
2004 85.7 81.5 87.3 83.5 81.2 78.5 79.2 79.3 80.3 90.4 91.3 144.9
2005 76.4 75.7 87.5 86.9 82.8 82.6 92.1 94.9 94.7 85.9 95.3 139.7
2006 91.0 84.5 96.8 95.4 89.9 92.2 92.2 96.9 98.5 94.3 98.6 159.9
2007 94.0 93.0 102.7 90.5 88.6 87.5 89.7 90.3 97.1 103.5 109.1 154.3
2008 104.4 88.6 98.0 91.2 92.1 91.0 92.2 99.9 102.8 121.3 135.9 204.4
2009 134.9 123.0 128.1 116.6 122.6 115.1 122.1 121.6 129.1 143.0 145.6 198.8
2010 134.8 117.1 138.3 125.6 124.5 121.0 132.4 135.3 143.5 161.2 167.8 232.1
2011 160.7 135.0 149.5 151.1 136.8 129.6 148.0 149.1 155.3 161.3 172.6 260.8
2012 176.6 159.2 171.1 159.2 153.8 148.8 144.6 149.6 149.6 157.0 179.3 268.7
2013 168.3 152.4 180.2 145.7 145.3 139.2 146.6 150.5 149.1 163.2 176.5 273.8
Explore your chosen retail time series using the following functions:
autoplot
, ggseasonplot
, ggsubseriesplot
, gglagplot
, ggAcf
Can you spot any seasonality, cyclicity and trend? What do you learn about the series?
ap <- autoplot(myts)+
theme_yaz()
seas <- ggseasonplot(myts)+
theme_yaz()
subs <- ggsubseriesplot(myts)+
theme_yaz()
lag <- gglagplot(myts)+
theme_yaz()
acf <- ggAcf(myts)+
theme_yaz()
pacf <- ggPacf(myts)+
theme_yaz()
library(gridExtra)
grid.arrange(ap, subs, seas, lag, acf, pacf, nrow = 3)
Liquor sales exhibit annual seasonality where sales spike during December (around the holidays) and are otherwise flat. The lag plot, partial autocorrelation plot, and subseries plot each show strong correlations with 12 month seasons. That said, there is also a general upward trend over time since 1992.
Repeat for the following series:
bicoal
, chicken
, dole
, usdeaths
, bricksq
, lynx
, ibmclose
Use the help files to find out what the series are.
The bicoal data is not seasonal (to the point where ggseasonalplot
threw an error). There may be some cyclicality around a four year lag, but it’s weak if at all existent.
library(fma)
a <- autoplot(bicoal)+ theme_yaz()
# b <- ggseasonplot(bicoal)+theme_yaz()
c <- ggsubseriesplot(bicoal)+theme_yaz()
d <- ggPacf(bicoal)+theme_yaz()
grid.arrange(a,c,d, nrow = 2)
The chicken data is not seasonal (again, to the point where ggseasonalplot
threw an error). The overall trend is negative between 1950 and 2000.
a <- autoplot(chicken)+ theme_yaz()
# b <- ggseasonplot(chicken)+theme_yaz()
c <- ggsubseriesplot(chicken)+theme_yaz()
d <- ggPacf(chicken)+theme_yaz()
grid.arrange(a,c,d, nrow = 2)
The dole data has a general positive trend indicating either an increase in population or an increase in the generosity of Austrailia’s welfare state (or both). There appears to have been a shift in seasonality in recent years. Before the spike in enrollment, there were no seasonal trends - welfare receipt was similar year-round. In recent years, seasonality has shifted towards earlier in the year. This may reflect the seasonality of job availability in retail.
a <- autoplot(dole)+ theme_yaz()
b <- ggseasonplot(dole)+theme_yaz()+theme(legend.position = 'none')
c <- ggsubseriesplot(dole)+theme_yaz()
d <- ggPacf(dole)+theme_yaz()
grid.arrange(a,b,c,d, nrow = 2)
Data on accidental deaths in the US in the 1970s indicates a seasonal trend in the summers with a peak in July of every year. On a brighter note, the sheer number of deaths appears to have a slightly negative trend, which should be viewed positively in light of the fact that the US population is continuously growing.
a <- autoplot(usdeaths)+ theme_yaz()
b <- ggseasonplot(usdeaths)+theme_yaz()
c <- ggsubseriesplot(usdeaths)+theme_yaz()
d <- ggPacf(usdeaths)+theme_yaz()
grid.arrange(a,b,c,d, nrow = 2)
The bricksq data has a seasonal trend with peaks in Q2 and Q3. This doesn’t make a ton of sense since those quarters are winter in Austrailia and I would assume brick production wouldl heavily correlate with building. Perhaps building season is in winter in Austrailia due to teh summer heat?
a <- autoplot(bricksq)+ theme_yaz()
b <- ggseasonplot(bricksq)+theme_yaz()+theme(legend.position = 'none')
c <- ggsubseriesplot(bricksq)+theme_yaz()
d <- ggPacf(bricksq)+theme_yaz()
grid.arrange(a,b,c,d, nrow = 2)
Lynx population growth may be cyclical but it’s not seasonal. The trend in population size is also relatively flat.
a <- autoplot(lynx)+ theme_yaz()
# b <- ggseasonplot(lynx)+theme_yaz()
c <- ggsubseriesplot(lynx)+theme_yaz()
d <- ggPacf(lynx)+theme_yaz()
grid.arrange(a,c,d, nrow = 2)
Lastly, IBM closing prices are trending downward in this time series with no clear seasonal trend. There may be some cyclicality, but that is unclear based on this data.
a <- autoplot(ibmclose)+ theme_yaz()
# b <- ggseasonplot(ibmclose)+theme_yaz()
c <- ggsubseriesplot(ibmclose)+theme_yaz()
d <- ggPacf(ibmclose)+theme_yaz()
grid.arrange(a,c,d, nrow = 2)
The arrivals
data set comprises quarterly international arrivals (in thousands) to Australia from Japan, New Zealand, UK and the US. Use autoplot and ggseasonplot and compare the differences between the arrivals from these four countries. Can you identify any unusual observations?
I couldn’t find the arrivals
data set so I used the woolyrnq
data set instead. Generally woollen yarn peaks in either Q2 or Q3, but that is not really consistent from year to year. It looks like Q3 is the peak for about half of the years and Q2 is the peak for another half.
grid.arrange(
autoplot(woolyrnq)+theme_yaz(),
ggseasonplot(woolyrnq)+theme_yaz(),
nrow = 1
)
1 = B 2 = C 3 = D 4 = A
Electricity consumption was recorded for a small town on 12 consecutive days. The following maximum temperatures (degrees Celsius) and consumption (megawatt-hours) were recorded for each day. TODO: change the econsumption to a ts of 12 concecutive days - change the lm to tslm below
library(GGally)
ggpairs(econsumption)+
theme_yaz()
lm.fit <- tslm(Mwh ~ temp, data = ts(econsumption))
library(gridExtra)
grid.arrange(
data.frame(Mwh = econsumption$Mwh, error = residuals(lm.fit))%>%
ggplot(aes(Mwh, error))+
geom_point(color = yaz_cols[1])+
theme_yaz()+
geom_hline(yintercept = 0, linetype = 'dashed'),
data.frame(error = residuals(lm.fit))%>%
ggplot(aes(x = ' ', y = error))+
geom_boxplot(fill = yaz_cols[1])+
labs(y = 'error', x = element_blank())+
theme_yaz()
, nrow = 1, widths = c(3,1)
)
forecast(lm.fit, newdata=data.frame(temp=c(10,35)))
Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
13 18.74795 17.27010 20.22579 16.34824 21.14766
14 15.11902 13.50469 16.73335 12.49768 17.74035
autoplot(ts(econsumption$Mwh)) +
forecast::autolayer(forecast(lm.fit, newdata=data.frame(temp=c(10))), PI=TRUE, series="10 Degrees") +
forecast::autolayer(forecast(lm.fit, newdata=data.frame(temp=c(35))), PI=TRUE, series="35 Degrees")+
labs(title = 'Consumption Forecast', y = 'Electricity Consumption',
x = element_blank())+
theme_yaz()+
scale_color_manual(name = 'Possible Temperature', values = yaz_cols[c(3,4)])
Data set olympic
contains the winning times (in seconds) for the men’s 400 meters final in each Olympic Games from 1896 to 2012.
olympic%>%head()
ggplot(olympic, aes(Year, time))+
geom_point()+
theme_yaz()+
labs(y = 'Seconds',
title = 'Men\'s 400M Time (seconds): Olympic Games from 1896 to 2012')
olympic.fit <- tslm(time~Year, data = ts(olympic))
summary(olympic.fit)
Call:
tslm(formula = time ~ Year, data = ts(olympic))
Residuals:
Min 1Q Median 3Q Max
-1.5215 -0.7037 -0.1642 0.4952 3.7141
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 196.079876 14.177031 13.83 5.09e-12 ***
Year -0.076790 0.007278 -10.55 7.51e-10 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 1.089 on 21 degrees of freedom
Multiple R-squared: 0.8413, Adjusted R-squared: 0.8337
F-statistic: 111.3 on 1 and 21 DF, p-value: 7.515e-10
grid.arrange(
ggplot(data.frame(year = olympic$Year, error = olympic.fit$residuals),
aes(year, error))+
geom_point(color = yaz_cols[1])+
theme_yaz()+
geom_hline(yintercept = 0, linetype = 'dashed'),
data.frame(error = residuals(olympic.fit))%>%
ggplot(aes(x = ' ', y = error))+
geom_boxplot(fill = yaz_cols[1])+
labs(y = 'error', x = element_blank())+
theme_yaz()
, nrow = 1, widths = c(3,1)
)
forecast(olympic.fit, newdata=data.frame(Year = years))
Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
24 42.49977 40.94361 44.05593 40.05401 44.94554
25 42.19261 40.62355 43.76167 39.72657 44.65866
26 41.88545 40.30266 43.46825 39.39782 44.37308
27 41.57829 39.98095 43.17563 39.06780 44.08879
new_years <- data.frame(Year= c(24, 25, 26, 27),
time = c(44, 43.75 ,43.94 , 43.03))
autoplot(ts(olympic$time, frequency = 1))+
geom_point()+
ylim(0,55)+
autolayer(forecast(olympic.fit, newdata= data.frame(Year = years)), PI=TRUE)+
labs(y = 'Olympic Times', x = 'Olympic Games Since 1896',
title = 'Prediction Quality Demonstration')+
geom_point(data = new_years, aes(Year, time))+
theme_yaz()
Type easter(ausbeer) and interpret what you see. Easter always occurs in the first or second quarter of the year. The date is close enough to the border of the quarter that occasionally the holiday falls partially in Q1 and partially in Q2 (as happened in 1956).
library(fpp)
easter(ausbeer)%>%
head(20)
Qtr1 Qtr2 Qtr3 Qtr4
1956 0.67 0.33 0.00 0.00
1957 0.00 1.00 0.00 0.00
1958 0.00 1.00 0.00 0.00
1959 1.00 0.00 0.00 0.00
1960 0.00 1.00 0.00 0.00
Show that a 3×5 MA is equivalent to a 7-term weighted moving average with weights of 0.067, 0.133, 0.200, 0.200, 0.200, 0.133, and 0.067.
The plastics data set consists of the monthly sales (in thousands) of product A for a plastics manufacturer for five years. * Plot the time series of sales of product A. Can you identify seasonal fluctuations and/or a trend-cycle? There is a general upward trend over the course of the years covered by this data. Additionally, there does appear to be a seasonal trend where most plastics are sold around the fall and early winter, which may coincide with holiday gift purchasing.
Recall your retail time series data (from Exercise 1 in Section ??). Decompose the series using X11. Does it reveal any outliers, or unusual features that you had not noticed previously? The x11 decomposition enveils a few outliers in the 1990s and mid 2000s that were not easy to see in the initial plotting of the data! Additionally, we can see that seasonal effects start to increase in teh 1990s leading to a more general updard trend going forward.