Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Linear Regression Slope

Posted on 2006-11-30
6
Medium Priority
?
1,930 Views
Last Modified: 2012-06-22
Hello,

I am transferring an Access query to SQL Server.  One of the fields requires me to find the linear regression slope.  In Access, i used LinRegSlope() to find this.  Is there any way to do this in SQL Server?

Thanks!

-Navicerts
0
Comment
Question by:Navicerts
  • 4
6 Comments
 
LVL 20

Expert Comment

by:Sirees
ID: 18045854
Check if this one helps

http://support.microsoft.com/kb/307276
0
 
LVL 7

Author Comment

by:Navicerts
ID: 18045926
That looks like information for MS Access, as i mentioned above, or am i missing something?  Is this SQL Server stuff?  If so, I am not having luck using this function.

Thanks
0
 
LVL 7

Author Comment

by:Navicerts
ID: 18045943
I have three pertanant columns... ID, Weight, and Date.  I want the regression slope to be a function of weight gain over time.
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 7

Author Comment

by:Navicerts
ID: 18045984
When i try to get the answer manually (no idea if im doing this correct) I get an error message....
Server: Msg 403, Level 16, State 1, Line 3
Invalid operator for data type. Operator equals boolean XOR, type equals float.

--SLOPE = ( COUNT(*)*SUM(x*y) -SUM(x)*SUM(y) ) / (COUNT(*)*SUM(x^2)-SUM(x)^2)
SELECT
      (COUNT(*)*SUM(Cast(DateDiff(dd, [Hatch Date], [Date]) As Float)*Weight) -SUM(Cast(DateDiff(dd, [Hatch Date], [Date]) As Float))*SUM(Weight) ) / (COUNT(*)*SUM(Cast(DateDiff(dd, [Hatch Date], [Date]) As Float)^2)-SUM(Cast(DateDiff(dd, [Hatch Date], [Date]) As Float))^2)
FROM
      WingbandFlock As wf
INNER JOIN
      Weight As w
ON
      wf.[Bird ID] = w.[Bird ID]
0
 
LVL 85

Accepted Solution

by:
ozo earned 2000 total points
ID: 18046689
try
x*x instead of x^2
or
pow(Cast(DateDiff(dd, [Hatch Date], [Date]) As Float),2)
instead of
Cast(DateDiff(dd, [Hatch Date], [Date]) As Float)^2
0
 
LVL 7

Author Comment

by:Navicerts
ID: 18047087
I realized it was gain vs feed eaten as opposed to gain over time, but it was the ^ that had me all confused.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

876 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question