文档介绍:R在水文时间序列分析的应用自回归滑动平均模型AutoregressiveModels-AR(p)ar{stats}FitAutoregressiveModelstoTimeSeriesDescriptionFitanautoregressivetimeseriesmodeltothedata,(x,aic=TRUE,=NULL,method=c("yule-walker","burg","ols","mle","yw"),,series,...),(ororder)-1and10*log10(N)whereNisthenumberofobservationsexceptformethod="mle"(thefirstfewcharactersaresufficient).Defaultsto"yule-walker".(substitute(x)).在概率论中,一个时间序列是一串随机变量。在统计学中,这样一些变量都会受时间影响:比如每天在变的股票价格,每月一测的空气温度,每分钟病人的心率等等数据:北美五大湖之一的LakeHuron的1875-1972年每年的水位值这个时间序列大致的图像:plot(LakeHuron,ylab="",main="LevelofLakeHuron")AR(1)模型:x<-LakeHuronop<-par(mfrow=c(2,1))y<-filter(x,.8,method="recursive")plot(y,main="AR(1)",ylab="")acf(y,main=paste("p=",signif(dwtest(y~1)$,3)))par(op)ACF和PCF图op<-par(mfrow=c(3,1),mar=c(2,4,1,2)+.1)acf(x,xlab="")pacf(x,xlab="")spectrum(x,xlab="",main="")par(op)AR(p)模型使用Yule-walker法得出估计的参数值y<-ar(x,aic=TRUE,method="yule-walker")regr=(x,order=2,demean=FALSE,intercept=FALSE)regr结果:Call:(x=x,=2,demean=FALSE,intercept=FALSE)Coefficients:-^>*x[98]-*x[97][1]:IntroductoryTimeSerieswithR,AnalysisofTimeSeriesDataUsingR,TimeSeriesAnalysisandItsApplications--withRexamples,TimeSeriesAnalysisandItsApplications--withRexamples参考网站:#2MA(MovingAveragemodels)Hereisasimplewayofbuildingatimeseriesfromawhitenoise:justperformaMovingAverage(MA)<-200x<-rnorm(n)y<-(x[2:n]+x[2:n-1])/2op<-par(mfr