Re: [R] plot and lines with time series data

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Mon, 18 Apr 2011 08:08:10 -0400

On Mon, Apr 18, 2011 at 7:20 AM, Fred <jianyun.fred.wu_at_gmail.com> wrote:
> Dear all,
>
> I am doing some time series analysis with R now. The problem is, when
> I create a time series object using "ts" function, then after fitting
> the model, the predicted values cannot be plotted with "ts" object
> together using "lines". ie.
>
> ts.series<-ts(x,start, end)
> plot(ts.series)
> lines(predict(fit.model))
>
> This doesn't work.
>
> Does anyone know about how to make it work ?

Its hard to tell what did not work without a complete example but try replacing lm with dyn$lm. Using built in Nile:

library(dyn)
fit.model <- dyn$lm(Nile ~ time(Nile))
plot(Nile)
lines(predict(fit.model))

-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

______________________________________________
R-help_at_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.
Received on Mon 18 Apr 2011 - 12:10:28 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 18 Apr 2011 - 12:20:32 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive