




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
R在水文时间序列分析的应用自回归滑动平均模型AutoregressiveModels-AR(p)ar{stats}FitAutoregressiveModelstoTimeSeriesDescriptionFitanautoregressivetimeseriesmodeltothedata,bydefaultselectingthecomplexitybyAIC.Usagear(x,aic=TRUE,order.max=NULL,method=c("yule-walker","burg","ols","mle","yw"),na.action,series,...)ArgumentsxAunivariateormultivariatetimeseries.aicLogicalflag.IfTRUEthentheAkaikeInformationCriterionisusedtochoosetheorderoftheautoregressivemodel.IfFALSE,themodeloforderorder.maxisfitted.order.maxMaximumorder(ororder)ofmodeltofit.DefaultstothesmallerofN-1and10*log10(N)whereNisthenumberofobservationsexceptformethod="mle"whereitistheminimumofthisquantityand12.methodCharacterstringgivingthemethodusedtofitthemodel.Mustbeoneofthestringsinthedefaultargument(thefirstfewcharactersaresufficient).Defaultsto"yule-walker".na.actionfunctiontobecalledtohandlemissingvalues.seriesnamesfortheseries.Defaultstodeparse(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)$p.value,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=ar.ols(x,order=2,demean=FALSE,intercept=FALSE)regr结果:Call:ar.ols(x=x,order.max=2,demean=FALSE,intercept=FALSE)Coefficients:121.1319-0.1319Orderselected2sigma^2estimatedas0.5281预测1973值>1.1319*x[98]-0.1319*x[97][1]579.9692参考书目:IntroductoryTimeSerieswithR,AnalysisofTimeSeriesDataUsingR,TimeSeriesAnalysisandItsApplications--withRexamples,TimeSeriesAnalysisandItsApplications--withRexamples参考网站:http://zoonek2.free.fr/UNIX/48_R/15.html#2MA(MovingAveragemodels)Hereisasimplewayofbuildingatimeseriesfromawhitenoise:justperformaMovingAverage(MA)ofthisnoise.n<-200x<-rnorm(n)y<-(x[2:n]+x[2:n-1])/2op<-par(mfrow=c(3,1),mar=c(2,4,2,2)+.1)plot(ts(x),xlab="",ylab="whitenoise")plot(ts(y),xlab="",ylab="MA(1)")acf(y,main="")par(op)n<-200x<-rnorm(n)y<-(x[1:(n-3)]+x[2:(n-2)]+x[3:(n-1)]+x[4:n])/4op<-par(mfrow=c(3,1),mar=c(2,4,2,2)+.1)plot(ts(x),xlab="",ylab="whitenoise")plot(ts(y),xlab="",ylab="MA(3)")acf(y,main="")par(op)Youcanalsocomputethemovingaveragewithdifferentcoefficients.n<-200x<-rnorm(n)y<-x[2:n]-x[1:(n-1)]op<-par(mfrow=c(3,1),mar=c(2,4,2,2)+.1)plot(ts(x),xlab="",ylab="whitenoise")plot(ts(y),xlab="",ylab="momentum(1)")acf(y,main="")par(op)n<-200x<-rnorm(n)y<-x[3:n]-2*x[2:(n-1)]+x[1:(n-2)]op<-par(mfrow=c(3,1),mar=c(2,4,2,2)+.1)plot(ts(x),xlab="",ylab="whitenoise")plot(ts(y),xlab="",ylab="Momentum(2)")acf(y,main="")par(op)Insteadofcomputingthemovingaveragebyhand,youcanusethe"filter"function.n<-200x<-rnorm(n)y<-filter(x,c(1,-2,1))op<-par(mfrow=c(3,1),mar=c(2,4,2,2)+.1)plot(ts(x),xlab="",ylab="Whitenoise")plot(ts(y),xlab="",ylab="Momentum(2)")acf(y,na.action=na.pass,main="")par(op)TODO:the"side=1"argument.AR(Auto-Regressivemodels)Anothermeansofbuildingatimeseriesistocomputeeachtermbyaddingnoisetotheprecedingterm:thisiscalledarandomwalk.Forinstance,n<-200x<-rep(0,n)for(iin2:n){x[i]<-x[i-1]+rnorm(1)}Thiscanbewritten,moresimply,withthe"cumsum"function.n<-200x<-rnorm(n)y<-cumsum(x)op<-par(mfrow=c(3,1),mar=c(2,4,2,2)+.1)plot(ts(x),xlab="",ylab="")plot(ts(y),xlab="",ylab="AR(1)")acf(y,main="")par(op)Moregenerally,onecanconsiderX(n+1)=aX(n)+noise.Thisiscalledanauto-regressivemodel,orAR(1),becauseonecanestimatethecoefficientsbyperformingaregressionofxagainstlag(x,1).n<-200a<-.7x<-rep(0,n)for(iin2:n){x[i]<-a*x[i-1]+rnorm(1)}y<-x[-1]x<-x[-n]r<-lm(y~x-1)plot(y~x)abline(r,col='red')abline(0,.7,lty=2)Moregenerally,anAR(q)processisaprocessinwhicheachtermisalinearcombinationoftheqprecedingtermsandawhitenoise(withfixedcoefficients).n<-200x<-rep(0,n)for(iin4:n){x[i]<-.3*x[i-1]-.7*x[i-2]+.5*x[i-3]+rnorm(1)}op<-par(mfrow=c(3,1),mar=c(2,4,2,2)+.1)plot(ts(x),xlab="",ylab="AR(3)")acf(x,main="",xlab="")pacf(x,main="",xlab="")par(op)Youcanalsosimulatethosemodelswiththe"arima.sim"function.n<-200x<-arima.sim(list(ar=c(.3,-.7,.5)),n)op<-par(mfrow=c(3,1),mar=c(2,4,2,2)+.1)plot(ts(x),xlab="",ylab="AR(3)")acf(x,xlab="",main="")pacf(x,xlab="",main="")par(op)PACFThepartialAutoCorrelationFunction(PACF)providesanestimationofthecoefficientsofanAR(infinity)model:wehavealreadyseenitonthepreviousexamples.Itcanbeeasilycomputedfromtheautocorrelationfunctionwiththe"Yule-Walker"equations.Yule-WalkerEquationsTocomputetheauto-correlationfunctionofanAR(p)processwhosecoefficientsareknown,(1-a1B-a2B^2-...-apB^p)Y=Zwejusthavetocomputethefirstautocorrelationsr1,r2,...,rp,andthenusetheYule-Walkerequations:r(j)=a1r(j-1)+a2r(j-2)+...+apr(j-p).YoucanalsousethemintheotherdirectiontocomputethecoefficientsofanARprocessfromitsautocorrelations.DescriptionFitanARMAmodeltoaunivariatetimeseriesbyconditionalleastsquares.Forexactmaximumlikelihoodestimationsee
arima0.Usagearma(x,order=c(1,1),lag=NULL,coef=NULL,ercept=TRUE,series=NULL,qr.tol=1e-07,...)Argumentsxanumericvectorortimeseries.orderatwodimensionalintegervectorgivingtheordersofthemodeltofit.
order[1]
correspondstotheARpartand
order[2]
totheMApart.lagalistwithcomponents
ar
and
ma.Eachcomponentisanintegervector,specifyingtheARandMAlagsthatareincludedinthemodel.Ifboth,
order
andlag,aregiven,onlythespecificationfrom
lag
isused.coefIfgiventhisnumericvectorisusedastheinitialestimateoftheARMAcoefficients.ThepreliminaryestimatorsuggestedinHannanandRissanen(1982)isusedforthedefaulterceptShouldthemodelcontainanintercept?seriesnamefortheseries.Defaultsto
deparse(substitute(x)).qr.tolthe
tol
argumentfor
HYPERLINK"/Rdoc/li
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 医用设备捐赠管理办法
- 供暖供水考核管理办法
- 新质生产力对电商创新生态系统的影响及发展策略
- 小学描写人物作文写作指导
- 绿色教育校本课程开发与实施
- 施工方案:道路与地坪拆除工程
- 智能预测系统在化纤生产中的应用-洞察及研究
- 培训机构聘用管理办法
- 探索和完善科研过程中的容错机制以促进创新活力的策略研究
- 供暖企业热源管理办法
- 2025年天津市中考语文试卷(含标准答案)
- 保险品质管理制度
- 2025年辽宁高考地理试卷真题答案详解讲评课件(黑龙江吉林内蒙古适用)
- 全国中小学教师职业道德知识竞赛80题及答案
- 2023CSCO食管癌诊疗指南
- 2024年四川省资中县事业单位公开招聘教师岗笔试题带答案
- 成人女性压力性尿失禁护理干预护理团标解读
- 某律师事务所内部规章管理制度大全
- GB 29743.2-2025机动车冷却液第2部分:电动汽车冷却液
- 急性右心衰的治疗与护理
- 制约理论(TOC)驱动制造业突破性增长
评论
0/150
提交评论