The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Origin C
 Returning all parameters from linear fitting
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

greadey

UK
Posts

Posted - 03/01/2005 :  08:16:38 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Greetings all,

I've been looking at performing a linear regression using code and have found the easiest implementation is by using the fitpoly_range approach.

While I am able to retrieve the fitted parameteres (gradient and intercept) I need to access the correlation coefficient, the errors in the estimation of the fit would also be beneficial.

Are these numbers available to Origin C?

Thanks all,

greadey

easwar

USA
1965 Posts

Posted - 03/01/2005 :  2:58:38 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi greadey,

Those functions (fitpoly, fitpoly_range etc) were written just to get quick estimates on polynomial coefficients - they are used in initialization code for nonlinear fitting mainly.

You would be better off using the LabTalk stat object directly from your Origin C code (these functions in fact use the stat object anyway).

Sample code pasted below:

Easwar
OriginLab

void test()
{
// fit to x,y data in cols 1, 2 of active wks
Worksheet wks = Project.ActiveLayer();
Curve crv( wks, 0, 1);
if( !crv ) return;

// Point to LabTalk stat object
using stat = LabTalk.Stat;
// Reset object
stat.reset();
// Set data name
stat.Data$ = crv.GetName();
// Set chi-sq scaling to 1 - need to do this if no error bars associated with data
// If error bars, then set to 0
stat.ChiSqrErr = 1;
// Set order - poly of order 3 for example
stat.pr.order = 3;
// Perform the operation
stat.pr();
// Print results
printf("Coeff[0], Err[0] = %f, %f\n", stat.pr.a, stat.pr.ase);
for(int ii=1; ii < 4; ii++)
printf("Coeff[%d], Err[%d] = %f, %f\n", ii, ii, stat.pr.b$(ii), stat.pr.bse$(ii));
printf("R-Sqr = %f\n", stat.adrsq);
// See the documentation on Stat object under LabTalk language reference file for more info
}


Go to Top of Page

greadey

UK
Posts

Posted - 03/02/2005 :  03:37:43 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks Easwar,

You pointed me in the right direction. I tried to usethe Labtalk LR object but couldn't get it to work, now I'll have a go with this.

greadey
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000