Hi:

Usually, if you get no response from the list, it's because either
    (a)  your question is vague or ill-defined;
    (b)  you supplied no reproducible example to illustrate what you tried,
          what was the error and what you expected to get (per the
          instructions in the Posting Guide);
    (c) both (a) and (b)
    (d) no one on the list knows.

That said...

On Thu, Dec 9, 2010 at 6:46 PM, Jiakang Lu <jl9jb@virginia.edu> wrote:

> Does anyone have similar experience before? I'd appreciate any
> suggestion/advice from the community.
>
> On Wed, Dec 8, 2010 at 4:05 PM, Jiakang Lu <jl9jb@virginia.edu> wrote:
>
> > Dear all,
> >
> > I'm new to R and time series analysis. I'd appreciate if you could shed
> > light on my problem.
> >
> > Here is what I have been trying to do:
> > 1. I fit the model ARIMA(1,0,0) with the training dataset xdata[1:100]
> > fitit = arima(xdata, order=c(1,0,0)
>

(a) What is xdata?  (Part of 'reproducible' includes example data)
(b) You don't have a closing right paren in your line of code.

> >
> > 2. I have some current observations in the buffer. Say that
> > buf = xdata_new[1:20]
>

Fine. (BTW, statisticians don't use the word 'buffer' for the availability
of new data. Is this supposed to be a test set?) Did you update the model to
include this new information? If not, what is its intended purpose?

> >
> > 3. I'm trying to forecast the xdata_new[21] based on the history
> > fore=predict(fitit,buf,n.ahead=1)
>

Which history? The first 100 points in the training set, or the 120
available from the training and test sets?
Your code would make sense if the model were fit to the 120 points available
through the combination of xdata and xdata_new, but it's not obvious what
you're doing. If you look carefully at the help page of predict.Arima(),
you'll find that n.ahead is its second positional argument, not the third.

> >
> > However, the results of fore$pred give me 20 predicted values from 101 to
> > 120. I'm really confused why this happens. Could you give me some
> > suggestions? It'd be great if there is a similar example.
>

It's not clear what you want. Do you want the 21st step ahead forecast for
the unknown 121st observation based on the AR(1) model from observations
1:100, or the first step ahead forecast from a revised model based on the
first 120 observations? In the first case, the answer is predict(fitit,
n.ahead = 21), selecting out the 21st component of its pred component; in
the second case, it would be predict(refitit, n.ahead = 1).

Here's a reproducible example:

# Generate an AR(1) series:
x <- arima.sim(list(order = c(1,0,0), ar = 0.7), n = 100)
# Generate a test set (this one is nothing like x)
xtest <- ts(rnorm(20))

# Fit an AR(1) model to x:
m <- arima(x, order = c(1, 0, 0))

# Predict 21 steps ahead based on this model:
p1 <- predict(m, n.ahead = 21)

# Fit an AR(1) model to the combination of x and xtest:
# Shouldn't be the same since the test data is white noise
m2 <- arima(c(x, xtest), order = c(1, 0, 0))

p2 <- predict(m2, n.ahead = 1)

# Get the 21st step ahead forecast based on model m
p1$pred[21]
# Get the 1st step ahead forecast based on model m2
as.vector(p2$pred)

Not close, but that's to be expected.

HTH,
Dennis

>
> > Thank you very much.
> >
> > Best,
> > Jiakang
> >
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

	[[alternative HTML version deleted]]

