版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 有色金属行业A股央企ESG系列报告之十四:有色金属行业央企ESG评价结果分析充分履行环境责任
- 2025年清徐辅警招聘真题及答案
- 2025年兴业银行天津分行校园招聘备考题库完整答案详解
- 2025年广东省水利电力勘测设计研究院有限公司招聘备考题库及答案详解一套
- 2025年南昌农商银行中层管理岗位人员招聘5人备考题库及参考答案详解一套
- 2025山西朔州市公安局招聘留置看护岗位辅警260人笔试重点试题及答案解析
- 工业机器人精度五年提升:2025年传感器技术报告
- 《CBT 3656-1994船用空气减压阀》专题研究报告
- 2025内蒙古农商银行管理人员及专业人才招聘70人备考笔试题库及答案解析
- 2025山东济宁检察机关招聘聘用制书记员31人备考核心试题附答案解析
- 自由职业教练合同协议
- 放弃经济补偿协议书
- 运动控制系统安装与调试(第2版)习题及答案汇 甄久军 项目1-5
- 部编版九年级语文上册教科书(课本全册)课后习题参考答案
- 二零二五年度个人住房贷款展期协议书3篇
- 通信工程建设标准强制性条文汇编(2023版)-定额质监中心
- 大数据与会计专业实习报告个人小结
- 人工智能原理与方法智慧树知到期末考试答案章节答案2024年哈尔滨工程大学
- DB34-T 4704-2024 托幼机构消毒技术规范
- GB/T 10599-2023多绳摩擦式提升机
- 高速铁路线路轨道设备检查-静态检查
评论
0/150
提交评论