Wrong correlation coefficient
Wrong correlation coefficient
We use TeeChartPro V7 in Borland c++ builder.
On a graph, we display the correlation function, which is a polynom
of degree 1 (f(x)=ax + b
The graph is correct.
The coefficient for degree 1 is correct.
The coefficient for degree 0 is INCORRECT.
We use AnswerMethod to get the coefficients.
On a graph, we display the correlation function, which is a polynom
of degree 1 (f(x)=ax + b
The graph is correct.
The coefficient for degree 1 is correct.
The coefficient for degree 0 is INCORRECT.
We use AnswerMethod to get the coefficients.

 Site Admin
 Posts: 14730
 Joined: Mon Jun 09, 2003 4:00 am
 Location: Banyoles, Catalonia
 Contact:
Hi provis,
Could you please send us a simple example project we can run "asis" to reproduce the problem here? You can either post your files at news://www.steema.net/steema.public.attachments newsgroup or at our upload page.
Thanks in advance.
Could you please send us a simple example project we can run "asis" to reproduce the problem here? You can either post your files at news://www.steema.net/steema.public.attachments newsgroup or at our upload page.
Thanks in advance.
Best Regards,
Narcís Calvet / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com 
Instructions  How to post in this forum 

 Site Admin
 Posts: 14730
 Joined: Mon Jun 09, 2003 4:00 am
 Location: Banyoles, Catalonia
 Contact:
Hi provis,
Are you using TCustomTeeFunction for that?
Are you using TCustomTeeFunction for that?
Best Regards,
Narcís Calvet / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com 
Instructions  How to post in this forum 
Hi Narcis,
sorry for the late reply.
To get the coefficient factors, we use the TCurveFittingFunction
and AnswerVector.
I have made another simple test case, which unfortunately I cannot ship because it uses some internal classes.
Here is the description of my test, which you should be able to reproduce easily.
I have 2 series.
Serie 1 contains values 1,2,3,4,5,6
Serie 2 contains values 2000,20,30,40,50,60
We plot serie 2 against serie 1.
We draw the correlation polynom of degree 1.
The drawing is correct (polynom is Y=274.29X+1326.7).
But when we ask for correlatrion factors using AnswerVector,
coefficient of degree 1 is correct, but coefficient of degree 0 is not.
It returns 1032 instead of 1326.
If I use a polynom of degree 2, only coefficient of degree 2 is correct.
Back to the polynom of degree 1, if I use function GetCurveYValue
with parameter X=0, I get 1326.7, which proves that the polynom
is drawn correctly.
It looks there is only a problem with AnswerVector.
Thanks for your help
sorry for the late reply.
To get the coefficient factors, we use the TCurveFittingFunction
and AnswerVector.
I have made another simple test case, which unfortunately I cannot ship because it uses some internal classes.
Here is the description of my test, which you should be able to reproduce easily.
I have 2 series.
Serie 1 contains values 1,2,3,4,5,6
Serie 2 contains values 2000,20,30,40,50,60
We plot serie 2 against serie 1.
We draw the correlation polynom of degree 1.
The drawing is correct (polynom is Y=274.29X+1326.7).
But when we ask for correlatrion factors using AnswerVector,
coefficient of degree 1 is correct, but coefficient of degree 0 is not.
It returns 1032 instead of 1326.
If I use a polynom of degree 2, only coefficient of degree 2 is correct.
Back to the polynom of degree 1, if I use function GetCurveYValue
with parameter X=0, I get 1326.7, which proves that the polynom
is drawn correctly.
It looks there is only a problem with AnswerVector.
Thanks for your help
Hi.
I think the problem is the AnswerVector allways returns the coefficients of normalized equation.
Normalizing values prior to fitting avoids fp overflows when large x or y values are used. In short, fitting is performed on x=xxmin and y=yymin values. If you take this into the account, AnswerVector will return correct polynomial coefficients.
I think the problem is the AnswerVector allways returns the coefficients of normalized equation.
Normalizing values prior to fitting avoids fp overflows when large x or y values are used. In short, fitting is performed on x=xxmin and y=yymin values. If you take this into the account, AnswerVector will return correct polynomial coefficients.
Marjan Slatinek,
http://www.steema.com
http://www.steema.com
Normalized (in this case) means *all* that minimum x value is subtracted from all x values and minimum y value is subtracted from all y values. Then the actual fitting is performed on these normalized values. The actual fitting is therefore not done on:5886443 wrote:What do you mean by normalized equation ?
What should I do to get the correct coefficient ?
Code: Select all
y=a(n)*x^n + a(n1)*x^(n1) +... + a0
Code: Select all
yymin = b(n)*(xxmin)^n + b(n1)*(xxmin)^(n1) + ... + b0
Floating point overflows  this happens if the numbers in fitting algorithm get too big.5886443 wrote:What is fp overflow ?
See my explanation above.5886443 wrote: How come the coefficient for the highest degree is correct and not the others ?
Marjan Slatinek,
http://www.steema.com
http://www.steema.com
thanks a lot, this is clear now;
If I understand you correctly, to get the expected factors,
I need to modify my series (add xmin to all x, add ymin to all y),
before using AnswerVector ?
Or is there another method/property I could use to get directly
the coefficients used to draw the polynom (the polynom
is not drawn using normalized equation)
thanks
If I understand you correctly, to get the expected factors,
I need to modify my series (add xmin to all x, add ymin to all y),
before using AnswerVector ?
Or is there another method/property I could use to get directly
the coefficients used to draw the polynom (the polynom
is not drawn using normalized equation)
thanks
Hi.
Not quite. Simply adding xmin and ymax won't do the trick. For example, "normalized" 1st degree equation is:
By expanding this to:
you get the usuall a(1) and a(0) coefficients which define equation
a(1) and a(0) are the coefficients you're after. For higher order polynomial you can use the same approach (although the formulas for a(i) will be a bit longer).
Not quite. Simply adding xmin and ymax won't do the trick. For example, "normalized" 1st degree equation is:
Code: Select all
yymin = b(1)*(xxmin)+b(0)
Code: Select all
y = b(1)*x  b(1)*xmin+b(0)+ymin
Code: Select all
y=a(1)*x+a(0)
...
a(1) = b(1)
a(0) = b(1)*xmin+b(0)+ymin
Marjan Slatinek,
http://www.steema.com
http://www.steema.com
I've been trying to expand your equations to 5th order but I am getting completely incorrect results. Could you please provide the formula to obtain coefficients a(2), a(3) and a(4). Thank you in advance.Marjan wrote:Hi.
Not quite. Simply adding xmin and ymax won't do the trick. For example, "normalized" 1st degree equation is:By expanding this to:Code: Select all
yymin = b(1)*(xxmin)+b(0)
you get the usuall a(1) and a(0) coefficients which define equationCode: Select all
y = b(1)*x  b(1)*xmin+b(0)+ymin
a(1) and a(0) are the coefficients you're after. For higher order polynomial you can use the same approach (although the formulas for a(i) will be a bit longer).Code: Select all
y=a(1)*x+a(0) ... a(1) = b(1) a(0) = b(1)*xmin+b(0)+ymin

 Site Admin
 Posts: 14730
 Joined: Mon Jun 09, 2003 4:00 am
 Location: Banyoles, Catalonia
 Contact:
Hi MikeC,
The equation is different for each polynomial degree. You cannot apply 1st degree polynomial equation to 5th degree polynomial.
You shoud write out the 5th polynomial equation and use the same principle to extract coefficients a(0) to a(4). It's not complicated, but the equations are quite long. We suggest you to use Mathematica to extract a(0)..a(4) from system of equations.
The equation is different for each polynomial degree. You cannot apply 1st degree polynomial equation to 5th degree polynomial.
You shoud write out the 5th polynomial equation and use the same principle to extract coefficients a(0) to a(4). It's not complicated, but the equations are quite long. We suggest you to use Mathematica to extract a(0)..a(4) from system of equations.
Best Regards,
Narcís Calvet / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com 
Instructions  How to post in this forum 
Re: Wrong correlation coefficient
And for whatever it is worth here are the conversions for second and third order polynominals.
Code: Select all
'y = a(2)*x^2 + a(1)*x + a(0)
'yymin = b(2)*(xxmin)^2 + b(1)*(xxmin) + b(0)
a(2) = b(2)
a(1) = b(1)  2*b(2)*xmin
a(0) = b(2)*Math.Pow(xmin,2)  b(1)*xmin + b(0) + ymin
Code: Select all
'y = a(3)*x^3 + a(2)*x^2 + a(1)* x + a(0)
'yymin = b(3)*(xxmin)^3 + b(2)*(xxmin)^2 + b(1)*(xxmin) + b(0)
a(3) = b(3)
a(2) = b(2)  3*b(3)*xmin
a(1) = 3*b(3)*Math.Pow(xmin, 2)  2*b(2)*xmin + b(1)
a(0) = b(3)*Math.Pow(xmin, 3) + b(2)*Math.Pow(xmin, 2)  b(1)*xmin + b(0) + ymin
Re: Wrong correlation coefficient
I use teechartnet2010.
I need to use the polynomial coefficient with a polynomial degree 6.
I understand that your coefficient is for normalised value.
I draw a series point1.
I Apply polyfitting function on this curve. every things is OK.
I change polynomial coefficient by :
double[] tab_temp_poly = new double[polyFitting1.PolyDegree];
xmin = points1.MinXValue;
ymin = points1.MinYValue;
tab_temp_poly[5] = polyFitting1.Coefficient(5);
tab_temp_poly[4] = polyFitting1.Coefficient(4)  5 * polyFitting1.Coefficient(5) * xmin;
tab_temp_poly[3] = polyFitting1.Coefficient(3) + 10 * polyFitting1.Coefficient(5) * Math.Pow(xmin, 2)
 4 * polyFitting1.Coefficient(4) * xmin;
tab_temp_poly[2] = polyFitting1.Coefficient(2)  10 * polyFitting1.Coefficient(5) * Math.Pow(xmin, 3)
+ 4 * polyFitting1.Coefficient(4) * Math.Pow(xmin, 2)  3 * polyFitting1.Coefficient(3) * xmin;
tab_temp_poly[1] = polyFitting1.Coefficient(1) + 5 * polyFitting1.Coefficient(5) * Math.Pow(xmin,4)
 4 * polyFitting1.Coefficient(4) * Math.Pow(xmin,3) + 3 * polyFitting1.Coefficient(3) * Math.Pow(xmin,2)
 2 * polyFitting1.Coefficient(2) * xmin;
tab_temp_poly[0] = polyFitting1.Coefficient(0)
 polyFitting1.Coefficient(5) * Math.Pow(xmin, 5)
+ polyFitting1.Coefficient(4) * Math.Pow(xmin, 4)
 polyFitting1.Coefficient(3) * Math.Pow(xmin, 3)
+ polyFitting1.Coefficient(2) * Math.Pow(xmin, 2)
 polyFitting1.Coefficient(1) * xmin
+ ymin;
I draw the curve with this coefficient and I get bad result.
what do you think of this?
can you help me?
thanks
thierry
I need to use the polynomial coefficient with a polynomial degree 6.
I understand that your coefficient is for normalised value.
I draw a series point1.
I Apply polyfitting function on this curve. every things is OK.
I change polynomial coefficient by :
double[] tab_temp_poly = new double[polyFitting1.PolyDegree];
xmin = points1.MinXValue;
ymin = points1.MinYValue;
tab_temp_poly[5] = polyFitting1.Coefficient(5);
tab_temp_poly[4] = polyFitting1.Coefficient(4)  5 * polyFitting1.Coefficient(5) * xmin;
tab_temp_poly[3] = polyFitting1.Coefficient(3) + 10 * polyFitting1.Coefficient(5) * Math.Pow(xmin, 2)
 4 * polyFitting1.Coefficient(4) * xmin;
tab_temp_poly[2] = polyFitting1.Coefficient(2)  10 * polyFitting1.Coefficient(5) * Math.Pow(xmin, 3)
+ 4 * polyFitting1.Coefficient(4) * Math.Pow(xmin, 2)  3 * polyFitting1.Coefficient(3) * xmin;
tab_temp_poly[1] = polyFitting1.Coefficient(1) + 5 * polyFitting1.Coefficient(5) * Math.Pow(xmin,4)
 4 * polyFitting1.Coefficient(4) * Math.Pow(xmin,3) + 3 * polyFitting1.Coefficient(3) * Math.Pow(xmin,2)
 2 * polyFitting1.Coefficient(2) * xmin;
tab_temp_poly[0] = polyFitting1.Coefficient(0)
 polyFitting1.Coefficient(5) * Math.Pow(xmin, 5)
+ polyFitting1.Coefficient(4) * Math.Pow(xmin, 4)
 polyFitting1.Coefficient(3) * Math.Pow(xmin, 3)
+ polyFitting1.Coefficient(2) * Math.Pow(xmin, 2)
 polyFitting1.Coefficient(1) * xmin
+ ymin;
I draw the curve with this coefficient and I get bad result.
what do you think of this?
can you help me?
thanks
thierry
Re: Wrong correlation coefficient
sorry it's mathematical error
now I do
double[] tab_temp_poly = new double[polyFitting1.PolyDegree];
tab_temp_poly[5] = polyFitting1.Coefficient(5);
tab_temp_poly[4] = polyFitting1.Coefficient(4)  5 * polyFitting1.Coefficient(5) * xmin;
tab_temp_poly[3] = polyFitting1.Coefficient(3) + 10 * polyFitting1.Coefficient(5) * Math.Pow(xmin, 2)
 4 * polyFitting1.Coefficient(4) * xmin;
tab_temp_poly[2] = polyFitting1.Coefficient(2)  10 * polyFitting1.Coefficient(5) * Math.Pow(xmin, 3)
+ 6 * polyFitting1.Coefficient(4) * Math.Pow(xmin, 2)  3 * polyFitting1.Coefficient(3) * xmin;
tab_temp_poly[1] = polyFitting1.Coefficient(1) + 5 * polyFitting1.Coefficient(5) * Math.Pow(xmin,4)
 4 * polyFitting1.Coefficient(4) * Math.Pow(xmin,3) + 3 * polyFitting1.Coefficient(3) * Math.Pow(xmin,2)
 2 * polyFitting1.Coefficient(2) * xmin;
tab_temp_poly[0] = polyFitting1.Coefficient(0)
 polyFitting1.Coefficient(5) * Math.Pow(xmin, 5)
+ polyFitting1.Coefficient(4) * Math.Pow(xmin, 4)
 polyFitting1.Coefficient(3) * Math.Pow(xmin, 3)
+ polyFitting1.Coefficient(2) * Math.Pow(xmin, 2)
 polyFitting1.Coefficient(1) * xmin
+ ymin;
every things are ok.
now I do
double[] tab_temp_poly = new double[polyFitting1.PolyDegree];
tab_temp_poly[5] = polyFitting1.Coefficient(5);
tab_temp_poly[4] = polyFitting1.Coefficient(4)  5 * polyFitting1.Coefficient(5) * xmin;
tab_temp_poly[3] = polyFitting1.Coefficient(3) + 10 * polyFitting1.Coefficient(5) * Math.Pow(xmin, 2)
 4 * polyFitting1.Coefficient(4) * xmin;
tab_temp_poly[2] = polyFitting1.Coefficient(2)  10 * polyFitting1.Coefficient(5) * Math.Pow(xmin, 3)
+ 6 * polyFitting1.Coefficient(4) * Math.Pow(xmin, 2)  3 * polyFitting1.Coefficient(3) * xmin;
tab_temp_poly[1] = polyFitting1.Coefficient(1) + 5 * polyFitting1.Coefficient(5) * Math.Pow(xmin,4)
 4 * polyFitting1.Coefficient(4) * Math.Pow(xmin,3) + 3 * polyFitting1.Coefficient(3) * Math.Pow(xmin,2)
 2 * polyFitting1.Coefficient(2) * xmin;
tab_temp_poly[0] = polyFitting1.Coefficient(0)
 polyFitting1.Coefficient(5) * Math.Pow(xmin, 5)
+ polyFitting1.Coefficient(4) * Math.Pow(xmin, 4)
 polyFitting1.Coefficient(3) * Math.Pow(xmin, 3)
+ polyFitting1.Coefficient(2) * Math.Pow(xmin, 2)
 polyFitting1.Coefficient(1) * xmin
+ ymin;
every things are ok.