help-gsl
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-gsl] linear regression


From: David Schaich
Subject: Re: [Help-gsl] linear regression
Date: Mon, 06 Nov 2006 11:57:19 -0500
User-agent: Thunderbird 1.5.0.7 (X11/20060909)

One thing that pops out at me is that all the c_i, cov_ij and sum_sq are just numbers, not arrays. So the commented-out line can be used, and you don't even have to assign values. You can just pass &c_0, &c_1, etc.

You should also set the strides to 1 instead of 6 -- if you check out the code fit/linear.c, you'll see lines like

for (i = 0; i < n; i++)
   {
     m_x += (x[i * xstride] - m_x) / (i + 1.0);
     m_y += (y[i * ystride] - m_y) / (i + 1.0);
   }

so by using 6 for xstride and ystride you'll fly out of your 6-element arrays pretty quickly.

Boris isn't really "linear", he's more of an indication of whether or not there were any problems.

Check out the examples in the manual if you haven't already:

http://www.gnu.org/software/gsl/manual/html_node/Fitting-Examples.html

-David

Huddwah wrote:
Hi,

I'm looking to do a simple linear regression. Unfortunately I'm a newb (with
regard to both c++ and GSL).

All I want is to return the coefficients of a series. I have tried to work
out how to use squares fitting functions described in the manual but I'm
pretty lost!

I know when you read this you will probably scratch your head and say it's
hopeless but any comment you have for me would be appreciated :)

   double x[6] = { 1, 2.3, 3.1, 4.8,  5.6, 6.3};
   double y[6] = { 2.6, 2.8, 3.1, 4.7, 5.1, 5.3};
   //double c_0 = 0.0, c_1 = 0.0, c_00 = 0.0, cov_01 = 0.0, cov_11 = 0.0,
sum_sq = 0.0;

   double c_1[6], c_0[6], c_01[6], c_00[6], cov_01[6], cov_11[6],
sum_sq[6];
   double * p = x;
   double * q = y;
   double * c0 = c_0;
   double * c01 = c_01;
   double * c00 = c_00;
   double * cov01 = cov_01;
   double * cov11 = cov_11;
   double * sumsq = sum_sq;


   int boris = gsl_fit_linear(x,6,y,6,6, c0, c01, c00, cov01, cov11,
sumsq);

   printf("linear: %.18e\n",boris);
   printf("c0: %.18e\n",c0);
   printf("c01: %.18e\n",c01);
   printf("c00: %.18e\n",c00);
   printf("cov01: %.18e\n",cov01);
   printf("cov11: %.18e\n",cov11);
   printf("sumsq: %.18e\n",sumsq);

// "boris" is just a random word I used because I have no idea what this
function is supposed to return.

I am asuming that c0 to cov11 are the coefficients and that pointers are
passed to the functions so that the function can update the values of these
variables.

The output is this:

linear: 5.283463952109629100e-308
c0: 5.283463954375817300e-308
c01: 5.283463954375769800e-308
c00: 5.283463954375722400e-308
cov01: 5.283463954375675000e-308
cov11: 5.283463954375627600e-308
sumsq: 5.283463954375580100e-308

ok, so now that I have given you a good laugh, any pointers would be
appreciated!! :)
_______________________________________________
Help-gsl mailing list
address@hidden
http://lists.gnu.org/mailman/listinfo/help-gsl




reply via email to

[Prev in Thread] Current Thread [Next in Thread]