R在水文时间序列分析的应用Word格式文档下载.docx

上传人:b****5 文档编号:17255470 上传时间:2022-11-29 格式:DOCX 页数:14 大小:78.53KB
下载 相关 举报
R在水文时间序列分析的应用Word格式文档下载.docx_第1页
第1页 / 共14页
R在水文时间序列分析的应用Word格式文档下载.docx_第2页
第2页 / 共14页
R在水文时间序列分析的应用Word格式文档下载.docx_第3页
第3页 / 共14页
R在水文时间序列分析的应用Word格式文档下载.docx_第4页
第4页 / 共14页
R在水文时间序列分析的应用Word格式文档下载.docx_第5页
第5页 / 共14页
点击查看更多>>
下载资源
资源描述

R在水文时间序列分析的应用Word格式文档下载.docx

《R在水文时间序列分析的应用Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《R在水文时间序列分析的应用Word格式文档下载.docx(14页珍藏版)》请在冰豆网上搜索。

R在水文时间序列分析的应用Word格式文档下载.docx

whereitistheminimumofthisquantityand12.

method

Characterstringgivingthemethodusedtofitthemodel.Mustbeoneofthestringsinthedefaultargument(thefirstfewcharactersaresufficient).Defaultsto"

.

na.action

functiontobecalledtohandlemissingvalues.

series

namesfortheseries.Defaultstodeparse(substitute(x)).

在概率论中,一个时间序列是一串随机变量。

在统计学中,这样一些变量都会受时间影响:

比如每天在变的股票价格,每月一测的空气温度,每分钟病人的心率等等

数据:

北美五大湖之一的LakeHuron的1875-1972年每年的水位值这个时间序列大致的图像:

plot(LakeHuron,

ylab="

"

main="

LevelofLakeHuron"

AR

(1)模型:

x<

-LakeHuron

op<

-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图

-par(mfrow=c(3,1),

mar=c(2,4,1,2)+.1)

acf(x,xlab="

pacf(x,xlab="

spectrum(x,xlab="

main="

AR(p)模型使用Yule-walker法得出估计的参数值

y<

-ar(x,aic=TRUE,method="

regr=ar.ols(x,order=2,demean=FALSE,intercept=FALSE)

regr

结果:

Call:

ar.ols(x=x,order.max=2,demean=FALSE,intercept=FALSE)

Coefficients:

12

1.1319-0.1319

Orderselected2sigma^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#2

MA(MovingAveragemodels)

Hereisasimplewayofbuildingatimeseriesfromawhitenoise:

justperformaMovingAverage(MA)ofthisnoise.

n<

-200

x<

-rnorm(n)

-(x[2:

n]+x[2:

n-1])/2

-par(mfrow=c(3,1),mar=c(2,4,2,2)+.1)

plot(ts(x),xlab="

whitenoise"

plot(ts(y),xlab="

MA

(1)"

acf(y,main="

-(x[1:

(n-3)]+x[2:

(n-2)]+x[3:

(n-1)]+x[4:

n])/4

MA(3)"

Youcanalsocomputethemovingaveragewithdifferentcoefficients.

-x[2:

n]-x[1:

(n-1)]

momentum

(1)"

-x[3:

n]-2*x[2:

(n-1)]+x[1:

(n-2)]

Momentum

(2)"

Insteadofcomputingthemovingaveragebyhand,youcanusethe"

filter"

function.

-filter(x,c(1,-2,1))

Whitenoise"

acf(y,na.action=na.pass,main="

TODO:

the"

side=1"

argument.

AR(Auto-Regressivemodels)

Anothermeansofbuildingatimeseriesistocomputeeachtermbyaddingnoisetotheprecedingterm:

thisiscalledarandomwalk.

Forinstance,

-200

-rep(0,n)

for(iin2:

n){

x[i]<

-x[i-1]+rnorm

(1)

}

Thiscanbewritten,moresimply,withthe"

cumsum"

-cumsum(x)

Moregenerally,onecanconsider

X(n+1)=aX(n)+noise.

Thisiscalledanauto-regressivemodel,orAR

(1),becauseonecanestimatethecoefficientsbyperformingaregressionofxagainstlag(x,1).

a<

-.7

-a*x[i-1]+rnorm

(1)

-x[-1]

-x[-n]

r<

-lm(y~x-1)

plot(y~x)

abline(r,col='

red'

abline(0,.7,lty=2)

Moregenerally,anAR(q)processisaprocessinwhicheachtermisalinearcombinationoftheqprecedingtermsandawhitenoise(withfixedcoefficients).

for(iin4:

-.3*x[i-1]-.7*x[i-2]+.5*x[i-3]+rnorm

(1)

AR(3)"

acf(x,main="

xlab="

pacf(x,main="

Youcanalsosimulatethosemodelswiththe"

arima.sim"

-arima.sim(list(ar=c(.3,-.7,.5)),n)

acf(x,xlab="

main="

pacf(x,xlab="

PACF

ThepartialAutoCorrelationFunction(PACF)providesanestimationofthecoefficientsofanAR(infinity)model:

wehavealreadyseenitonthepreviousexamples.Itcanbeeasilycomputedfromtheautocorrelationfunctionwiththe"

Yule-Walker"

equations.

Yule-WalkerEquations

Tocomputetheauto-correlationfunctionofanAR(p)processwhosecoefficientsareknown,

(1-a1B-a2B^2-...-apB^p)Y=Z

wejusthavetocomputethefirstautocorrelationsr1,r2,...,rp,andthenusetheYule-Walkerequations:

r(j)=a1r(j-1)+a2r(j-2)+...+apr(j-p).

YoucanalsousethemintheotherdirectiontocomputethecoefficientsofanARprocessfromitsautocorrelations.

FitanARMAmodeltoaunivariatetimeseriesbyconditionalleastsquares.Forexactmaximumlikelihoodestimationsee 

arima0.

arma(x,order=c(1,1),lag=NULL,coef=NULL,

include.intercept=TRUE,series=NULL,qr.tol=1e-07,...)

anumericvectorortimeseries.

order

atwodimensionalintegervectorgivingtheordersofthemodeltofit. 

order[1] 

correspondstotheARpartand 

order[2] 

totheMApart.

lag

alistwithcomponents 

ar 

and 

ma.Eachcomponentisanintegervector,specifyingtheARandMAlagsthatareincludedinthemodel.Ifboth, 

order 

andlag,aregiven,onlythespecificationfrom 

lag 

isused.

coef

IfgiventhisnumericvectorisusedastheinitialestimateoftheARMAcoefficients.ThepreliminaryestimatorsuggestedinHannanandRissanen(1982)isusedforthedefaultinitialization.

include.intercept

Shouldthemodelcontainanintercept?

namefortheseries.Defaultsto 

deparse(substitute(x)).

qr.tol

the 

tol 

argumentfor 

qr 

whencomputingtheasymptoticstandarderrorsof 

coef.

Examples

data(tcm)

-diff(tcm10y)

summary(r.arma<

-arma(r,order=c(1,0)))

-arma(r,order=c(2,0)))

-arma(r,order=c(0,1)))

-arma(r,order=c(0,2)))

-arma(r,order=c(1,1)))

plot(r.arma)

data(nino)

s<

-nino3.4

summary(s.arma<

-arma(s,order=c(20,0)))

summary(s.arma

<

-arma(s,lag=list(ar=c(1,3,7,10,12,13,16,17,19),ma=NULL)))

acf(residuals(s.arma),na.action=na.remove)

pacf(residuals(s.arma),na.action=na.remove)

-arma(s,lag=list(ar=c(1,3,7,10,12,13,16,17,19),ma=12)))

-arma(s,lag=list(ar=c(1,3,7,10,12,13,16,17),ma=12)))

plot(s.arma)

(本资料素材和资料部分来自网络,仅供参考。

请预览后才下载,期待您的好评与关注!

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高等教育 > 管理学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1