Re: [R] Time series example in Koop

2011-04-05 Thread Mike Marchywka





> Date: Tue, 5 Apr 2011 07:35:04 -0500
> From: ravi.k...@gmail.com
> To: r-help@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

  
__
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.


Re: [R] Time series example in Koop

2011-04-05 Thread Gabor Grothendieck
On Tue, Apr 5, 2011 at 8:35 AM, Ravi Kulkarni  wrote:
> 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.
>
> 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...
>

It looks like he erroneously left out the first point.

> URL <- "http://r.789695.n4.nabble.com/file/n3427897/badnews.txt";
> BAD <- read.table(URL, header = TRUE)
> library(dyn)
> dyn$lm(m.cap ~ lag(oil.price, -(0:4)), as.zoo(BAD))

Call:
lm(formula = dyn(m.cap ~ lag(oil.price, -(0:4))), data = as.zoo(BAD))

Coefficients:
(Intercept)  lag(oil.price, -(0:4))1  lag(oil.price, -(0:4))2
   91173.32  -131.99  -449.86
lag(oil.price, -(0:4))3  lag(oil.price, -(0:4))4  lag(oil.price, -(0:4))5
-422.52  -187.10   -27.77

>
> # without first point
> dyn$lm(m.cap ~ lag(oil.price, -(0:4)), tail(as.zoo(BAD), -1))

Call:
lm(formula = dyn(m.cap ~ lag(oil.price, -(0:4))), data = tail(as.zoo(BAD),
-1))

Coefficients:
(Intercept)  lag(oil.price, -(0:4))1  lag(oil.price, -(0:4))2
92001.5   -145.0   -462.1
lag(oil.price, -(0:4))3  lag(oil.price, -(0:4))4  lag(oil.price, -(0:4))5
 -424.5   -199.5-36.9

>


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

__
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.


[R] Time series example in Koop

2011-04-05 Thread Ravi Kulkarni
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.

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

--
View this message in context: 
http://r.789695.n4.nabble.com/Time-series-example-in-Koop-tp3427897p3427897.html
Sent from the R help mailing list archive at Nabble.com.

__
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.