forum.alglib.net

ALGLIB forum
It is currently Wed Nov 27, 2024 1:06 am

All times are UTC


Forum rules


1. This forum can be used for discussion of both ALGLIB-related and general numerical analysis questions
2. This forum is English-only - postings in other languages will be removed.



Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: How to calculate regression errors
PostPosted: Tue Feb 26, 2013 9:12 am 
Offline

Joined: Tue Feb 26, 2013 9:00 am
Posts: 6
Apologies in advance as maths isn't my strong point, so please go easy with your replies!

I'm using the "lsfitlinearw" method (least squares linear fit with weighting) to calculate the slope and intercept for a series of X,Y points. I've now been asked to "calculate the standard error and relative standard error of the slope and intercept". How would I go about doing this? I've noticed the lsfitlinearw method returns a series of "fitting report" error values and wondered if any of these would be relevant?

The alglib documentation describes the error values as follows:-
- "RMS error on the X,Y"
- "Average error on the X,Y"
- "Average relative error on the non-zero Y"
- "Maximum error"

Thanks in advance
Andrew


Top
 Profile  
 
 Post subject: Re: How to calculate regression errors
PostPosted: Tue Feb 26, 2013 12:39 pm 
Offline
Site Admin

Joined: Fri May 07, 2010 7:06 am
Posts: 927
You can use Rep.ErrPar - it stores vector of standard errors in parameters.


Top
 Profile  
 
 Post subject: Re: How to calculate regression errors
PostPosted: Tue Feb 26, 2013 1:38 pm 
Offline

Joined: Tue Feb 26, 2013 9:00 am
Posts: 6
The "rep" output parameter contains properties like avgerror, avgrelerror, etc, but there isn't one called ErrPar. I'm using the C# alglib library if that makes a difference.


Top
 Profile  
 
 Post subject: Re: How to calculate regression errors
PostPosted: Tue Feb 26, 2013 1:46 pm 
Offline

Joined: Tue Feb 26, 2013 9:00 am
Posts: 6
Apologies, I've just downloaded the latest version and can see it now.

So the ErrPar structure - is the first value the intercept standard error, and the second the slope std error?

Thanks again


Top
 Profile  
 
 Post subject: Re: How to calculate regression errors
PostPosted: Tue Feb 26, 2013 2:45 pm 
Offline
Site Admin

Joined: Fri May 07, 2010 7:06 am
Posts: 927
It depends on how you generate your data :) First element of ErrPar corresponds to the first column of the FMatrix, second one corresponds to the second column. Which column is used for intercept is defined by you.


Top
 Profile  
 
 Post subject: Re: How to calculate regression errors
PostPosted: Tue Feb 26, 2013 3:23 pm 
Offline

Joined: Tue Feb 26, 2013 9:00 am
Posts: 6
Ah, yes I see it now. I had written my own code to calculate the slope and intercept standard errors, but it was giving different results to those in rep.errpar. My code is using n-2 degrees of freedom, but changing it to n-1 d.f. gives the same results as alglib.

I confess to not really understanding "degrees of freedom". I based my original code on this article: http://www.chem.utoronto.ca/coursenotes/analsci/StatsTutorial/ErrRegr.html.
Is there a reason why this (and many other articles) generally seem to use n-2 d.f., while alglib uses n-1?


Top
 Profile  
 
 Post subject: Re: How to calculate regression errors
PostPosted: Tue Feb 26, 2013 6:14 pm 
Offline
Site Admin

Joined: Fri May 07, 2010 7:06 am
Posts: 927
I've added this question to issues tracker and will investigate it later. Maybe it is minor error in the regression estimation code... maybe it is just another formula with some hidden meaning...

I recall that unbiased formula for variance uses degrees of freedom which are different from that of same formula for standard deviation. Maybe it is the reason...


Top
 Profile  
 
 Post subject: Re: How to calculate regression errors
PostPosted: Wed Feb 27, 2013 8:10 am 
Offline

Joined: Tue Feb 26, 2013 9:00 am
Posts: 6
Thanks for your help on this.

Andrew


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group