Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Register Now and get your question answered!
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 Script Library
 Curve Fitting (Trend Analysis and Prediction)
 Reply to Topic
 Printer Friendly
Previous Page
Author Previous Topic Topic Next Topic
Page: of 2

Starting Member

3 Posts

Posted - 12/26/2013 :  23:21:29  Show Profile  Reply with Quote
Hi All,

Can someone help me to add one more fit curve for a 3rd degree Polynomial and help me to find the coefficients and R^2.

Example : y = ax^3+bx^2+cx+d
Please help me to find a,b,c,d and r.

I have a set of x and y points

Thank you all in advance.
Go to Top of Page

Patron Saint of Lost Yaks

30421 Posts

Posted - 12/28/2013 :  05:16:05  Show Profile  Visit SwePeso's Homepage  Reply with Quote
I'll soon have a SQLCLR for that too.

Go to Top of Page

Starting Member

3 Posts

Posted - 12/30/2013 :  00:59:12  Show Profile  Reply with Quote
Hi Peter Larsson,

Very sorry to ask you, but do you have any time lines for finishing this SQLCLR. I am looking for a project deliverable by end of this week. Can u give me a headsup on what logic you would write within SQLCLR, and the .NET classes from the library, so i could do some brainstorming on that.

Thank you in advance.

Edited by - mvsandeep on 12/30/2013 00:59:54
Go to Top of Page

Starting Member

1 Posts

Posted - 05/06/2015 :  16:10:20  Show Profile  Reply with Quote
I realize I'm a little late to the party here but found your code when I was looking for something pre-built instead of coding my own.

Really enjoy that you had done this already, saved me some work! I think there is a small issue with your coefficient of determination (r2) calculation though. I got a little bogged down by messy math when actually trying to work it out from squaring the standard equation for r so I just took the lazy way out and modified r2 to just square the calculation of r. It now calculates as I would expect. I'm sure you can go through the math to modify the original version to make it work, I just couldn't find it. Here is my equation:

@r2=power( (@n * @xy - @x * @y)/(sqrt( ( @n * @x2 - @x * @x) * ( @n * @y2 - @y * @y) )),2)
Go to Top of Page
Page: of 2 Previous Topic Topic Next Topic  
Previous Page
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000