Solved

Linear Regression Slope

Posted on 2006-11-30
6
1,924 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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
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 84

Accepted Solution

by:
ozo earned 500 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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL query and VBA 5 46
sql, case when & top 1 14 30
Need return values from a stored procedure 8 23
Microsoft CRM 4.0 26 21
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

820 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