This preview shows pages 1–4. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Introductory Time Series with R: Selected solutions from odd numbered exercises Paul Cowpertwait & Andrew Metcalfe August 5, 2009 Chapter 1 Solutions 1. The data can be read into R and the plots obtained using the following code. In the plots it will be seen that the chocolate production series exhibits an increasing trend – this will be particular clear in the plot of the aggregated series. In addition, the boxplot will indicate that production tends to reach a minimum in January (possibly following postChristmas sales). > www = "http://www.massey.ac.nz/~pscowper/ts/cbe.dat" > cbe = read.table(www, head=T) > choc.ts < ts(cbe[,1], st=1958, fr=12) > plot(choc.ts) > plot(aggregate(choc.ts)) > boxplot(choc.ts ~ cycle(choc.ts)) 3. Below the data are entered into R and LI and PI found. > q0 < c(0.33, 2000, 40, 3, 2) > p0 < c(18000, 0.8, 40, 80, 200) > qt < c(0.5, 1500, 20, 2, 1) > pt < c(20000, 1.6, 60, 120, 360) > LI < sum(q0 * pt)/sum(q0 * p0) > PI < sum(qt * pt)/sum(qt * p0) > c(LI, PI) [1] 1.358 1.250 1 (a) From the R code we see that PI t = 1 . 250. (b) LI t uses the quantities from the base year, which is earlier than quantities used in PI t . PI is usually less than LI because people tend to move away from items that show sharp price increases to substitutes that have not shown such steep price increases. In this case the cost of new cars has increased by a factor of 1.11, whereas the cost of servicing has increased by a factor of 1.50 and the cost of petrol has doubled. People have tended to buy more new cars thus reducing the costs of servicing and petrol consumption. (c) The code below calculates the IrvingFisher index. > sqrt(LI * PI) [1] 1.303 Chapter 2 Solutions 1. (a) The code below reads the data in and then produces a scatter plot and calculates the correlation between the x and y variables. The plot indicates an almost quadratic relationship, which is not reflected in the value of the correlation (since correlation is a mea sure of linear relationship). > www = "http://www.massey.ac.nz/~pscowper/ts/varnish.dat" > varnish = read.table(www, head=T) > plot(varnish) > cor(varnish) x y x 1.0000000 0.2528782 y 0.2528782 1.0000000 (b) There is a clear pattern but it is nonlinear resulting in small correlation. > www = "http://www.massey.ac.nz/~pscowper/ts/guesswhat.dat" > guesswhat = read.table(www, head=T) > plot(guesswhat) > cor(guesswhat) x y x 1.00000000 0.06457764 y 0.06457764 1.00000000 3. (a) The data can be read into R as follows and a plot of the decom posed series obtained from plot(decompose()) . 2 > www = "http://www.massey.ac.nz/~pscowper/ts/global.dat" > global = scan(www) > global.ts = ts(global, st=1856, fr=12) > global.decom = decompose(global.ts) > plot(global.decom) Since the data are ‘global’ temperature we would not expect to observe substantial seasonal variation. This is supported by the close standard deviations and a boxplot (from the code below)....
View Full
Document
 Spring '11
 opp
 Math

Click to edit the document details