s-news
[Top] [All Lists]

Re: Roll nlme

To: "'Chen,Sichong'" <sichong.chen@postgrad.manchester.ac.uk>, <s-news@lists.biostat.wustl.edu>
Subject: Re: Roll nlme
From: "Dimitrios Chalvatzis" <dimitrios.stats@btopenworld.com>
Date: Thu, 6 Apr 2006 20:36:08 +0100
In-reply-to: <20060406155353.EA23D1006459@mailgate.biostat.wustl.edu>
Thread-index: AcZZkki2UM5h0ItmSpyDlIi7QcWnuAAHbCRg

Chen,

 

Firstly to use the ‘roll’ you will need to align your matrices in the form of a dataframe or a time series.

In effect your two 5000x60 matrices need to form a frame of 300000x2.

Assuming you perform this simple data manipulation and your observations are saved as matrix A you have:

 

#### Some random data ####

A<-matrix(rnorm(600000),ncol=2)

 

 

#### This is the function call ####

 

glm.func<-function(data){

   a<-glm(data[,1]~data[,2])

   glm.coef<-summary(a)$coef

   return(list(glm.coef=glm.coef))

}

 

Results<-roll(glm.func,data="">

 

#### These are the results ####

 

> names(Results)

[1] "glm.coef"  "call"      "positions"

> Results$glm.coef[1:3,]

            [,1]        [,2]      [,3]      [,4]        [,5]      [,6]

 60  0.364897629  0.17356008 0.1352286 0.1229694  2.69837604  1.411409

120 -0.019862930 -0.18667690 0.1323861 0.1263117 -0.15003788 -1.477906

180  0.006771196  0.04408364 0.1379626 0.1365119  0.04907994  0.322929

 

On each row the first two values refer to the glm coefficients, the middle two values are your std.errors, and the last two your t-values.

The overall backtest took 7.05 min to run on a 2.4GHz, 1GB Ram, WinXP.

 

I hope this helps,

 

Dimitrios

 

 

 


From: s-news-owner@lists.biostat.wustl.edu [mailto:s-news-owner@lists.biostat.wustl.edu] On Behalf Of Chen,Sichong
Sent: 06 April 2006 16:54
To: s-news@lists.biostat.wustl.edu
Subject: Re: [S] Roll nlme

 

Dear All

This roll question reminds of previous problem. I have two matrix A (5000*60) and B (5000*60). What I need to do is to run the regression between the rows of A and B. out = A[1,]~B[1,]…, A[2,]~B[2,]…. A[5000,]~B[5000,]. Previously I used a loop to do 5,000 times of regression which cost about one hour. Since FinMetrics has the function like roll, do you know whether it has a function to solve this kind of problem faster?

Another question bothered me for a long time is that the function like GARCH, glm etc, the outputs don’t have t-stats, they only reports coefficients. I have to use function summary and find the t-stats. It works if I use loop to save my results of t-stats but it does not works if I use roll because only the coefficients are save.

Many thanks,

Best,

Sichong Chen
SPlus 7.0 & FinMetrics 2.0 User
Windows XP

<Prev in Thread] Current Thread [Next in Thread>