So now suppose we model the time series with ARP model yt equals to phi 1 yt-1 + phi 2 yt-2 plus dot dot dot plus phi p yt minus p plus epsilon t. And our term epsilon t flows a normal distribution with mean zero and variance nu. So the question now is, how do we predict new values of yt? So prediction, And for t greater than capital T. So the first step ahead prediction is generated by yt + 1, this follows a normal distribution, Of phi 1 yt + dot dot plus phi p yt +1-p and nu. So this is from the AR model. And now, since we have already obtained samples, posterior samples of phi one, pgi p and nu, so suppose the Sth posterior sample Is denoted as phi1s, phi2s, dot dot dot phi ps and also nus the Sth posterior sample, Of this y capital T+1. We also denote it as y capital T+1 and a subscript s here. So this will be generated from a normal distribution with mean. Phi1s y capital T plus dot, dot, dot plus phi ps, y capital, T+1 minus p and nu s. Similarly for yt+2 the Sth, posterior sample. Of yt plus 2s. This is generated from a normal distribution with mean phi 1s y capital T+1 plus phi 2s y capital T plus dot dot dot plus phi ps, yt plus 2 minus p and nu s. Here, we notice this yt plus 1, this is not belonging to the original data set. So actually here we need to use the Sth posterior sample of it. So and it is generated here from the first step. So you see, the whole prediction process is also a sequentially updated process. We first make one step, we'll have prediction based on the value of the one step ahead prediction, we make the two step [INAUDIBLE] Prediction. In general, the sth sample of the H step ahead prediction can be obtained by sample from a normal distribution. So the Sth posterior sample Of yt plus hs this is obtained from a normal distribution with mean [INAUDIBLE] To p phi j syt plus h minus j s and nu s. And here this yt plus h minus js, this cannot be the sth sample if t plus h minus j is greater than capital T, because if this is greater than capital T, this means this y value is not contained in your original data set. So, you don't need to use the Sth sample which is obtained in your previous prediction steps and it will be the original data, F t plus h minus j is less than or equal to capital T. We illustrate this prediction procedure using the previous simulated data example. Remember, previously we sampled 200 observations from this AR2 model. To obtain up to h step prediction, we can use this function. The function has two inputs, h.step is a number of steps you need to predict an S denote the sth posterior sample. Let's see how this function works. Firstly, we take the sth posterior sample of AR coefficients and variance. Here phi.sample is a matrix of posterior samples of AR coefficients. And nu.sample is a posterior samples of variance parameter. Since it is an AR2 process, we initialize y with the last two observations of our time series y.sample. We defined a y.pred-reptor to store the predictions. Then it comes to the sequential update procedure. For the first step, the mean of the normal distribution is just sum of element wise product of these two vectors. This is just the phi [INAUDIBLE] S times yt plus phi 2s times yt minus 1 part. Then we sample the sth posterior sample of the one step ahead prediction from this normal distribution and record it on the first [INAUDIBLE] Of y.pred. Because this is a sequentially updated procedure We also need to update the y vector we use in the next loop. So here we're at the newly generated y to the left of the y.cur vector. Then y.cur becomes a stray element vector. The last element of y.cur is the second to last data, yt minus 2. It will not be needed in predicting yt plus 2. So here we remove it. Now we finish a loop. Finally, after we obtain the sth posterior samples of all each step you need, the function returns the predictions, the output will be a vector of last [INAUDIBLE] And the key slot of the output is sth posterior sample of the case that had prediction. For illustration purpose, they obtain three step-ahead predictions. We use the [INAUDIBLE] Function, to obtain 5,000 posterior samples, based on the 5,000 posterior samples of modal parameters we generated previously. This [INAUDIBLE] Supply function is equivalent to [INAUDIBLE] The output here will be a three by 5000 matrix. Its ig element is a [INAUDIBLE] Posterior sample of a step-ahead prediction. We plot the posterior distribution here using these lines of code. We can also get the posterior mean and a 95% credible interval for the predictions using this line of code. The result is shown here. The columns are the three steps-ahead prediction. The first and third row are boundaries for the credible interval and the second row is opposed to your mean