0

whats the easiest way to calculate the standard deviation of a query column webmatrix? any predefined method, etc?

if there isn't any easy way.. how can i utilize this code?

public static double StandardDeviation(List<double> valueList)
{
double M = 0.0;
double S = 0.0;
int k = 1;
foreach (double value in valueList)
{
    double tmpM = M;
    M += (value - tmpM) / k;
    S += (value - tmpM) * (value - M);
    k++;
    }
    return Math.Sqrt(S / (k-2));
}
mdehghani
  • 504
  • 1
  • 7
  • 23

1 Answers1

0

if you are getting your data from SQL Server, then letting the database do the calculations may work for you. Something like

SELECT STDEVP(valueList)
FROM yourTable

or more specifically to WebMatrix

@{
   var sd = db.QueryValue( "SELECT STDEVP(valueList) FROM yourTable");
}

<p>
SD is @sd
</p>

See this question for more SQL - STDEVP or STDEV and how to use it?

Community
  • 1
  • 1
Knox
  • 2,909
  • 11
  • 37
  • 65
  • dear knox.. STDEVP doesn't appear to be supported in webmatrix/sql Compact Edition.. anyway, I assume the best answer may be seen here: http://forums.asp.net/p/2033343/5854905.aspx?p=True&t=635584667300135174 – mdehghani Feb 02 '15 at 18:27