联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-23:00
  • 微信:codinghelp

您当前位置:首页 >> Algorithm 算法作业Algorithm 算法作业

日期:2018-04-21 09:54

Assignment 2, Computer Exercise Results

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document.

You must submit to Moodle two files

1.this R Markdown file expanded with Rcode chunks and your answers and comments to questions.

2.a pdf version of this knitted R Markdown file which will be named A2Rcode.pdf

Question a) Set up AR(2) parameters.

SID=3141593 ## replace by your own SID

set.seed(SID)

plot(c(-2,0,2),c(-1,1,-1), type="n",xlim=c(-2,2), ylim=c(-1,1),

    xlab="phi1", ylab="phi2")

abline(h=0)

abline(c(1,1),lty=2)

abline(c(1,-1),lty=2)

abline(h=-1, lty=2)

lines(seq(-2,2,0.01),-seq(-2,2,0.01)^2/4,col="green")


phi1=sample(c(-1,1),1)*runif(1,0,2)

if(phi1<0) phi2 = runif(1,-1,phi1+1) else phi2=runif(1,-1,1-phi1)

phi1=0.9*phi1 ## shrinks away from boundary.

phi2=0.9*phi2

points(phi1,phi2,col="red", pch=4)

INSERT EXTRA CODE CHUNKS HERE TO ANSWER THESE QUESTIONS AND ANSWER THEM BELOW:*

i.In at most 8 lines explain what the above code does.

ii.Determine if the parameter values produce a stationary solution by finding the roots of the appropriate polynomial.

iii.Are the roots: equal, real pair, or complex pair?

In particular refer to lectures in week 3 concerning section 3.2.2 of the notes on possible space of parameter values for an AR(2) as part of your explanations.

Question b) Simulate and AR(2) process and fit an AR to it.

n=200

X=2+arima.sim(model=list(ar=c(phi1,phi2)),n=n)

arfit=ar.yw(X,constant=TRUE)

ANSWER THE FOLLOWING QUESTIONS HERE:

i.Briefly summarize what the code simulates and fits.

ii.Summarise the order of the fitted model and ALL estimated parameter values and their standard errors and comment on the statistical significance of the parameters.

Question c) Residual diagnostics.

Perform the following diagnostics on the residuals in the above fitted autoregression. In particular use par(mfrow=c(2,2)) to arrange a 2 by 2 grid for plots in order left to right for each row: normal probability plot, histogram, autocorrelations, partial autocorrelations. Perform the Box-Ljung test these residuals for serial dependence using a total of 10 lags for the test and report your results here and summarise the key conclusions – in particular is there any evidence that the residuals are not Gaussian white noise. INSERT EXTRA CODE CHUNKS HERE TO ANSWER part c).

Question d)

Again on a 2 by 2 plotting grid display the ACF and PACF of the time series X generated above, the theoretival ACF for the true autoregressive model and the theoretical ACF using the fitted model parameters. Report your results here and discuss your graphs pointing out similarities and differences if any. INSERT EXTRA CODE CHUNKS HERE TO ANSWER part d).

e) Prediction

Produce a plot displaying the original series X along with predictions 20 steps into the future from the end of the series with 95% prediction limits. Properly annotate and title your graph and display here. Make brief comments on the forecast and the forecast intervals INSERT EXTRA CODE CHUNKS HERE TO ANSWER part e).

f) Correct and incorrect confidence intervals for true mean of X.

Using the sample mean of X calculate an approximate 95% confidence interval for the true mean mu assuming the series is a sequence of independent random variables (incorrect). Also do this using the formula (1.3) in section 1.4.1 of the notes (correct). For this latter, use the fitted autoregressive model, compute the theoretical autocorrelations corresponding to the fitted model for lags 1 through n, use these in formula (1.3) then estimate the variance of the process by var(X). Code hints:

acfarfit=ARMAacf(ar=arfit$ar,lag.max=n)

Var.mean.correct=var(X)*(1+2*sum((1-(1:n)/n)*acfarfit[-1]))/n

Var.mean.incorrect=var(X)/n

Report your results and answer these questions:

i.Briefly explain the difference between the two variance estimates and how the above code produces the required value for formula (1.3).

ii.Compare your results and make a brief comment comparing the two intervals.

iii.Is there any evidence to suggest that the true mean is not equal to the value 2?

INSERT EXTRA CODE CHUNKS HERE TO ANSWER part f).


相关文章

【上一篇】:R软件代写代做代写
【下一篇】:R软件代写代做代写

版权所有:留学生编程辅导网 2020 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp