[R] Time series example in Koop
Mike Marchywka
marchywka at hotmail.com
Tue Apr 5 16:01:56 CEST 2011
> Date: Tue, 5 Apr 2011 07:35:04 -0500
> From: ravi.kulk at gmail.com
> To: r-help at r-project.org
> Subject: [R] Time series example in Koop
>
> I am trying to reproduce the output of a time series example in Koop's book
> "Analysis of Financial Data". Koop does the example in Excel and I used the
> ts function followed by the lm function.
> I am unable to get the exact coefficients that Koop gives - my coefficients
> are slightly different.
> After loading the data file and attaching the frame, my code reads:
>
> > y = ts(m.cap)
> > x = ts(oil.price)
> > d = ts.union(y,x,x1=lag(x,-1),x2=lag(x,-2),x3=lag(x,-3),x4=lag(x,-4))
> > mod1 = lm(y~x+x1+x2+x3+x4, data=d)
> > summary(mod1)
>
> Koop gives an intercept of 92001.51, while the code above gives 91173.32.
> The other coefficients are also slightly off.
The differences here seem to be of order 1 percent. You could suspect
a number of things, including the published data file being published
to less precision than that used in the book numbers(also look at number
of points and see if any were added or dropped etc ). However, you may want
to judge these based on what they do to your error which they
presumably are both supposed to minimize but the calculation of which could
be subject to various roundoff errors etc. Unless minimization is done
analytically, it is of course subject to limitations of convergence or iteration
count. Plotting both fits over the data and looking at residuals may help too.
Depending on what you are really trying to do, you may want to change
your error calculation etc.
Details of numerical results often depend on details of implementation.
This is why stats packages that are not open
source have limitations in applicability. With "real models" of course
things get even more confusing.
( take a look at credit rating agencies results for example LOL).
>
> This is the example in Table 8.3 of Koop. I also attach a plain text version
> of the tab separated file "badnews.txt".
> http://r.789695.n4.nabble.com/file/n3427897/badnews.txt badnews.txt
>
> Any light on why I do not get Koop's coefficients is most welcome...
>
> Ravi
More information about the R-help
mailing list