# forum.alglib.net

ALGLIB forum
 It is currently Thu Aug 11, 2022 9:03 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.

 Page 1 of 1 [ 8 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: How to calculate regression errorsPosted: Tue Feb 26, 2013 9:12 am

Joined: Tue Feb 26, 2013 9:00 am
Posts: 6

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"

Andrew

Top

 Post subject: Re: How to calculate regression errorsPosted: Tue Feb 26, 2013 12:39 pm

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

Top

 Post subject: Re: How to calculate regression errorsPosted: Tue Feb 26, 2013 1:38 pm

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

 Post subject: Re: How to calculate regression errorsPosted: Tue Feb 26, 2013 1:46 pm

Joined: Tue Feb 26, 2013 9:00 am
Posts: 6

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

Thanks again

Top

 Post subject: Re: How to calculate regression errorsPosted: Tue Feb 26, 2013 2:45 pm

Joined: Fri May 07, 2010 7:06 am
Posts: 878
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

 Post subject: Re: How to calculate regression errorsPosted: Tue Feb 26, 2013 3:23 pm

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

 Post subject: Re: How to calculate regression errorsPosted: Tue Feb 26, 2013 6:14 pm

Joined: Fri May 07, 2010 7:06 am
Posts: 878
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

 Post subject: Re: How to calculate regression errorsPosted: Wed Feb 27, 2013 8:10 am

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

Andrew

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 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 forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for: