title: Calculating Standard Deviation, Variance in Java
body: <p>Building Test Cases for many different aggregate functions. </p>
  
  <p>Trying to manually create formulas to calculate standard deviation, variance.</p>
  
  <p>So far,</p>
  
  <p>I have these equations, but I am a little bit off on my calculations</p>
  
  <pre><code>//Calculate Standard Deviation
  double Sum1 = 0;
  double Sum2 = 0;
  long count = 0;
  
  
  
  public Object compute()
  {
  if (count &gt; 0)
        return Math.sqrt(count*Sum2 - Math.pow(Sum1. 2))/ count;
  else
      return null;
  }
  
  //Calculate Variance
  double sum = 0;
  double count = 0;
  
  public Object compute()
  {
  if(count&gt;0)
      return (Math.pow(sum-(sum/count),1))/count;
  else
      return null;
  </code></pre>
  
  <p>Where I am getting stuck the most is I know when trying to calculate the variance I can calculate the mean by going:</p>
  
  <pre><code>Math.pow(sum, 1)/count;
  </code></pre>
  
  <p>Im having trouble with the next part which is trying to calculate the deviance of all these numbers. </p>
  
  <p>I have it setup where I am retrieving all the numbers in such a way to make these calculations work. Just don't have the equations right. Would be perfect if I could do it in a single equation instead of doing it separately. If anyone could help, would be greatly appreciated. 
  Thank you</p>