




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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年度老年人社区活动协助劳务协议
- 二零二五年度公共停车场地下车位转让及管理服务协议
- 2025年度生态农业空场地租赁管理书
- 2025年茶艺师常识与技巧试题及答案
- 妇幼保健员考试的健康知识试题及答案
- 酒店电气安装工程施工方案方案
- 人教鄂教版三年级下册科学全册教案
- 中西方服饰差异
- 陕西省历年中考语文真题及答案解析,2013-2022年陕西省十年中考语文试题汇总
- 埃美柯阀门检验报告汇总-391黄铜调节阀
- RBA0商业道德风险评价管理程序
- 2023国家汉办(HSK)汉语水平考试三级考试真题
- 脑动脉供血不足护理查房精品ppt
- 危险化学品安全知识培训--易燃液体篇
- 《Android手机软件开发》说课课件
- 新版病案首页
评论
0/150
提交评论