setwd("C:/Users/berg.UFAD/Documents/sta 6857/R") #Replace with your dir location # Example 1.1 (page 4) jj = scan("mydata/jj.dat") jj = ts(jj,start=1960, frequency=4) plot(jj, ylab="Quarterly Earnings per Share") # Example 1.2 (page 5) gtemp = scan("mydata/globtemp.dat") gtemp = ts(gtemp,start=1856) plot(gtemp) # Example 1.3 (page 6) speech = scan("mydata/speech.dat") ts.plot(speech) # Example 1.4 (page 6) nyse = scan("mydata/nyse.dat") nyse = ts(nyse,start=c(1984,33), frequency=365) plot(nyse) # Example 1.5 (page 7) soi = scan("mydata/soi.dat") recruit = scan("mydata/recruit.dat") soi = ts(soi,start=c(1950,6), frequency=12) recruit = ts(recruit,start=c(1950,6), frequency=12) par(mfcol=c(2,1)) plot(soi) plot(recruit) # Example 1.6 (page 9) fmri = read.table("mydata/fmri.dat") par(mfrow=c(2,1)) # sets up the graphics ts.plot(fmri[,2:5], lty=c(1,4), ylab="BOLD") ts.plot(fmri[,6:9], lty=c(1,4), ylab="BOLD") # Example 1.7 (page 9) x = matrix(scan("mydata/eq5exp6.dat"), ncol=2) par(mfrow=c(2,1)) plot.ts(x[,1], main="Earthquake", ylab="EQ5") plot.ts(x[,2], main="Explosion", ylab="EXP6") # Example 1.9 (page 13) w = rnorm(500,0,1) # 500 N(0,1) variates v = filter(w, sides=2, rep(1,3)/3) # moving average par(mfrow=c(2,1)) plot.ts(w) plot.ts(v) # Example 1.10 (page 14) w = rnorm(550,0,1) # 50 extra to avoid startup problems x = filter(w, filter=c(1,-.9), method="recursive") plot.ts(x[51:550]) # Example 1.11 (page 15) set.seed(154) w = rnorm(200,0,1) x = cumsum(w) wd = w +.2 xd = cumsum(wd) plot.ts(xd, ylim=c(-5,55)) lines(x) lines(.2*(1:200), lty="dashed") # Example 1.12 (page 16) t = 1:500 c = 2*cos(2*pi*t/50 + .6*pi) w = rnorm(500,0,1) par(mfrow=c(3,1)) plot.ts(c) plot.ts(c + w) plot.ts(c + 5*w)