Solved

# Linear Regression Slope

Posted on 2006-11-30
1,927 Views
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
Question by:Navicerts
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 4

LVL 20

Expert Comment

ID: 18045854
Check if this one helps

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

LVL 7

Author Comment

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

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

LVL 7

Author Comment

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

ozo earned 500 total points
ID: 18046689
try
or
pow(Cast(DateDiff(dd, [Hatch Date], [Date]) As Float),2)
Cast(DateDiff(dd, [Hatch Date], [Date]) As Float)^2
0

LVL 7

Author Comment

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

Question has a verified solution.

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

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
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
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
###### Suggested Courses
Course of the Month7 days, 9 hours left to enroll