Link to home
Start Free TrialLog in
Avatar of Navicerts
NavicertsFlag for United States of America

asked on

Slope

Hello,

I am trying to find the linear regression of weight gain over time via MS SQL Server.  I found a function for slope and im trying to apply it.  I am looking for a conformation on this equation and if im applying it correctly.

Slope = ( COUNT(*)*SUM(x*y) -SUM(x)*SUM(y) ) / (COUNT(*)*SUM(x^2)-SUM(x)^2)

The site i found it said x is date and y is weight.  I figured (correct me if im wrong) that x would be the age of the bird in days so i came up with the following query....

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]

In concept, am i correct?  I am still running into an SQL error i have not solved, if you know that you can post the answer in my related question for more points :)

https://www.experts-exchange.com/questions/22077814/Linear-Regression-Slope.html?anchorAnswerId=18045854#a18045854

Thanks!

-Navicerts
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Navicerts

ASKER

Well shoot, that explains some things.  Working now!  Sorry i *thought* it was a math question, but you answered an SQL Server question :)  I graphed it and the answer checks out too.

Thanks again!


SELECT
      (Count(*)*SUM(Cast([Feed Consumed] As float)*([Weight Gain]*453.6)) -SUM(Cast([Feed Consumed] As float))*SUM(([Weight Gain]*453.6)) ) / (Count(*)*SUM(power(Cast([Feed Consumed] As float),2))-power(SUM(Cast([Feed Consumed] As float)), 2))
FROM
      WingbandFlock As wf
INNER JOIN
      [Feed Consumed] As fc
ON
      wf.[Bird ID] = fc.[Bird ID]
INNER JOIN
      [Keepers Report] As kr
ON
      wf.[Bird ID] = kr.[Bird ID]