[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
## [Help-gsl] linear regression

**From**: |
Huddwah |

**Subject**: |
[Help-gsl] linear regression |

**Date**: |
Mon, 6 Nov 2006 07:59:23 -0800 |

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] linear regression**,
*Huddwah* **<=**