Skip to content

Performing regression using R & C

4 messages · Manoj - Hachibushu Capital, Greg Tarpinian, Roger Bivand +1 more

#
Dear All,
	Is it possible to perform OLS using C code? I am trying to
optimize a n-period "moving window" OLS on a huge dataset hence was
wondering if such a thing is possible.

	Ideally the solution that I am looking for would involve a
C-code accepting two float arrays and returning back computed parameters
such as t-stat, coefficient etc. 

	I have glanced thru the FAQ's and tried to google this
information but wasn't able to find anything truly relevant, hence would
really appreciate your help on this one.


Thanks.

Manoj
#
I have found "Numerical Recipes in C" to be extremely
helpful in my statistical studies.  OLS is described
in detail in this book.

Best,

    Greg


--- Manoj - Hachibushu Capital <Wanzare at HCJP.com>
wrote:
#
On Thu, 18 Nov 2004, Greg Tarpinian wrote:

            
Maybe just read the R code: src/library/stats/R/lm.R contains function 
lm.fit(), which is a wrapper for the Fortran subroutine dqrls(), and is 
about as finely honed as you get. It won't give you the standard errors, 
but you get the coefficients and the qr object, from which the rest can be 
constructed. Using well-supported and maintained code does save time too!

But maybe there are moving window functions around that you can use
without having to "roll your own", searching on "moving window" at
http://finzi.psych.upenn.edu/search.html gave 85 hits, including the
following, which you may find fruitful:

http://finzi.psych.upenn.edu/R/Rhelp02a/archive/26904.html

Roger

  
    
#
It is probably not worth trying to call R to do OLS from C.  I would 
look at GSL:

http://www.gnu.org/software/gsl/manual/gsl-ref_toc.html

GSL has a simple but elegant C interface for doing OLS and weighted 
least squares.  It will give you the covariance matrix of the model 
parameters, from which you can derive t-stats.

Jim M