forum.alglib.net
http://forum.alglib.net/

How to calculate regression errors
http://forum.alglib.net/viewtopic.php?f=2&t=782
Page 1 of 1

Author:  andyste1 [ Tue Feb 26, 2013 9:12 am ]
Post subject:  How to calculate regression errors

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

Author:  Sergey.Bochkanov [ Tue Feb 26, 2013 12:39 pm ]
Post subject:  Re: How to calculate regression errors

You can use Rep.ErrPar - it stores vector of standard errors in parameters.

Author:  andyste1 [ Tue Feb 26, 2013 1:38 pm ]
Post subject:  Re: How to calculate regression errors

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.

Author:  andyste1 [ Tue Feb 26, 2013 1:46 pm ]
Post subject:  Re: How to calculate regression errors

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

Author:  Sergey.Bochkanov [ Tue Feb 26, 2013 2:45 pm ]
Post subject:  Re: How to calculate regression errors

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.

Author:  andyste1 [ Tue Feb 26, 2013 3:23 pm ]
Post subject:  Re: How to calculate regression errors

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?

Author:  Sergey.Bochkanov [ Tue Feb 26, 2013 6:14 pm ]
Post subject:  Re: How to calculate regression errors

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...

Author:  andyste1 [ Wed Feb 27, 2013 8:10 am ]
Post subject:  Re: How to calculate regression errors

Thanks for your help on this.

Andrew

Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/