1、时间序列基本概念,吴喜之,1,某些描述方法,2,3,#T2.1 n=200;t=1:n;alpha=0;beta=2;e=rnorm(n,0,10);x=alpha+beta*t+e;par(mfrow=c(2,2);plot(t,x,type=l);plot(t,beta*t,type=l);plot(t,e,type=l,ylim=c(0,400);par(mfrow=c(1,1),4,#T2.2 n=200;t=seq(0,6,len=n);e=rnorm(n); alpha=0;gamma=3;x= alpha+gamma*cos(t*5)+e;par(mfrow=c(2,2); pl
2、ot(t,x,type=l);plot(t,gamma*cos(t*5),type=l,ylim=c(-5,5);plot(t,e,type=l,ylim=c(-5,5);par(mfrow=c(1,1),5,#T2.3 n=200;t=seq(0,6,len=n);e=rnorm(n); alpha=0;beta=6;gamma=3;x= alpha+beta*t+gamma*cos(t*5)+e;par(mfrow=c(2,2);plot(t,x,type=l);plot(t,gamma*cos(t*5),type=l,ylim=c(-5,40);plot(t,beta*t,type=l,
3、ylim=c(-5,40);plot(t,e,type=l,ylim=c(-5,40);par(mfrow=c(1,1),6,#T2.4 n=200;t=seq(0,6,len=n);e=rnorm(n,0,2); alpha=0;beta=6;gamma=.2;x= (alpha+beta*t)*(gamma*cos(t*5)+e;par(mfrow=c(2,2);plot(t,x,type=l);plot(t,gamma*cos(t*5),type=l);plot(t,beta*t,type=l);plot(t,e,type=l);par(mfrow=c(1,1),7,#T2.5 n=20
4、0;t=seq(0,6,len=n);e=rnorm(n,0,2); alpha=0;beta=6;gamma=.2;x= (alpha+beta*t)*(gamma*cos(t*5)*e par(mfrow=c(2,2);plot(t,x,type=l);plot(t,gamma*cos(t*5),type=l);plot(t,beta*t,type=l);plot(t,e,type=l);par(mfrow=c(1,1),8,#Difference operation removing the trend #As T2.1 n=200;t=1:n;alpha=0;beta=2;e=rnor
5、m(n,0,10);x=alpha+beta*t+e; par(mfrow=c(2,1); plot(t,x,type=l);plot(t-1,diff(x),type=l,ylim=c(-300,300);par(mfrow=c(1,1),9,# Difference operation removing the seasonal effect. set.seed(10); n=24;t=1:n;alpha=0;beta=2;e=rnorm(n,0,10);x=alpha+beta*t+e;m=n*30 y=rep(x,30)+rnorm(m);t=1:m;par(mfrow=c(2,1);
6、plot(t,y,type=l);plot(t-(1:24),diff(y,24),type=l,ylim=c(-10,50);par(mfrow=c(1,1),10,# Difference operation removing both the trend and seasonal effect. set.seed(10);n=24;t=1:n;alpha=0;beta=2;e=rnorm(n,0,20);x=alpha+beta*t+e;m=n*30;gamma=.2;t=1:m;y=rep(x,30)+gamma*t1.35+rnorm(m);par(mfrow=c(1,2);plot
7、(t,y,type=l);plot(t-(1:25),diff(diff(y,1),24),type=l,ylim=c(-10,50);par(mfrow=c(1,1),11,#Correlation library(TeachingDemos) if(interactive() run.cor2.examp() x=-10:10;y=x2;plot(x,y);cor(x,y);a=lm(yx);abline(a)set.seed(0) x=arima.sim(n = 63, list(ar = c(0.8897, -0.4858), ma = c(-0.2279, 0.2488),sd =
8、sqrt(0.1796) par(mfrow=c(2,3) plot(x) a=acf(x) y=zlag(x,1);plot(as.vector(x-1),as.vector(y-1),main=substitute(r=that,list(that=a$acf1) y2=zlag(x,2);plot(as.vector(x-1),as.vector(y2-1),main=substitute(r=that,list(that=a$acf2) #y3=zlag(x,3);plot(as.vector(x-1),as.vector(y3-1),main=substitute(r=that,li
9、st(that=a$acf3) y10=zlag(x,10);plot(as.vector(x-1),as.vector(y10-1),main=substitute(r=that,list(that=a$acf10) y14=zlag(x,14);plot(as.vector(x-1),as.vector(y14-1),main=substitute(r=that,list(that=a$acf14) par(mfrow=c(1,1),12,13,x=scan(“c:/xzwu/tjbook3/data/tax.txt“) tax=ts(x/100000, frequency = 12, s
10、tart = c(1995, 1) ts.plot(tax,ylab=“Tax“,ylim=c(-1.2,11.6),main=“Monthly Tax in a Chinese City (in Billion RMB)“) a=stl(tax, “period“)#Seasonal Decomposition of Time Series by Loess #,a$time.series has 3 columns (seasonal, trend, remainder) par(mfrow=c(2,2) ts.plot(tax,ylab=“Tax“,ylim=c(-1.2,11.6),m
11、ain=“Monthly Tax in a Chinese City (in Billion RMB)“) plot(a$time.series,1,col=2,type=“l“,ylim=c(-1,12) plot(a$time.series,2,col=2,type=“l“,ylim=c(-1,12) plot(a$time.series,3,col=2,type=“l“,ylim=c(-1,12) par(mfrow=c(1,1)ts.plot(tax,ylab=“Tax“,ylim=c(-1.2,11.6),main=“Monthly Tax in a Chinese City (in
12、 Billion RMB)“) lines(a$time.series,1,col=2) lines(a$time.series,2,col=3) lines(a$time.series,3,col=4),14,15,ts.plot(tax,ylab=“Tax“,ylim=c(-1.2,11.6),main=“Monthly Tax in a Chinese City (in Billion RMB)“) lines(a$time.series,1,col=2);lines(a$time.series,2,col=3);lines(a$time.series,3,col=4),What about this time series? Passengers in Chinas Airports,16,What about this time series? Passengers in Chinas Airports,17,某些时间序列模型,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,