Message-ID: <BANLkTimwL9PNp1DfZW2ikjP=eVhkHFofrA@mail.gmail.com>
Date: 2011-04-18T12:08:10Z
From: Gabor Grothendieck
Subject: plot and lines with time series data
In-Reply-To: <f6f38f41-829a-400a-8940-973c379de964@a21g2000prj.googlegroups.com>
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