returns the sample variance of a set of numbers after discarding the nulls in this set.

@param expr argument
@return var_samp(expr)
15494
public static <T extends Number> WindowOver<T> varSamp(Expression<T> expr) {
        return new WindowOver<T>(expr.getType(), SQLOps.VARSAMP, expr);
    }
1067855
def variance(sample = false)
      a = numerify
      avg = a.average
      sum = a.inject(0) { |sum, value| sum + (value - avg) ** 2}
      (1 / (a.length.to_f - (sample ? 1 : 0)) * sum)
    end
1293903
@Override
  public final List<Node<String>> getSampleDataRow(
    final Map<String, Object> pReqVars) throws Exception {
    String lang = (String) pReqVars.get("lang");
    List<Node<String>> result = new ArrayList<Node<String>>();
    Integer idx = 1;
    Node<String> nodeGoods = new Node<String>();
    result.add(nodeGoods);
    nodeGoods.setItsName(getSrvI18n().getMsg("goods", lang));
    nodeGoods.setItsNodes(new ArrayList<Node<String>>());
    Node<String> nodeGoodsName = new Node<String>();
    nodeGoods.getItsNodes().add(nodeGoodsName);
    nodeGoodsName.setItsName(getSrvI18n().getMsg("itsName", lang));
    nodeGoodsName.setItsValue(idx.toString() + ";itsName");
    Node<String> nodeGoodsId = new Node<String>();
    nodeGoods.getItsNodes().add(nodeGoodsId);
    nodeGoodsId.setItsName(getSrvI18n().getMsg("itsId", lang));
    nodeGoodsId.setItsValue(idx.toString() + ";itsId");
    Node<String> nodeGoodsItsCategory = new Node<String>();
    nodeGoods.getItsNodes().add(nodeGoodsItsCategory);
    nodeGoodsItsCategory.setItsName(getSrvI18n().getMsg("itsCategory", lang));
    nodeGoodsItsCategory.setItsNodes(new ArrayList<Node<String>>());
    Node<String> nodeGoodsItsCategoryName = new Node<String>();
    nodeGoodsItsCategory.getItsNodes().add(nodeGoodsItsCategoryName);
    nodeGoodsItsCategoryName.setItsName(getSrvI18n().getMsg("itsName", lang));
    nodeGoodsItsCategoryName
      .setItsValue(idx.toString() + ";itsCategory,itsName");
    Node<String> nodeGoodsItsCategoryId = new Node<String>();
    nodeGoodsItsCategory.getItsNodes().add(nodeGoodsItsCategoryId);
    nodeGoodsItsCategoryId.setItsName(getSrvI18n().getMsg("itsId", lang));
    nodeGoodsItsCategoryId.setItsValue(idx.toString() + ";itsCategory,itsId");
    Node<String> nodeGoodsDefUnitOfMeasure = new Node<String>();
    nodeGoods.getItsNodes().add(nodeGoodsDefUnitOfMeasure);
    nodeGoodsDefUnitOfMeasure.setItsName(getSrvI18n()
      .getMsg("defUnitOfMeasure", lang));
    nodeGoodsDefUnitOfMeasure.setItsNodes(new ArrayList<Node<String>>());
    Node<String> nodeGoodsDefUnitOfMeasureName = new Node<String>();
    nodeGoodsDefUnitOfMeasure.getItsNodes().add(nodeGoodsDefUnitOfMeasureName);
    nodeGoodsDefUnitOfMeasureName
      .setItsName(getSrvI18n().getMsg("itsName", lang));
    nodeGoodsDefUnitOfMeasureName
      .setItsValue(idx.toString() + ";defUnitOfMeasure,itsName");
    Node<String> nodeGoodsDefUnitOfMeasureId = new Node<String>();
    nodeGoodsDefUnitOfMeasure.getItsNodes().add(nodeGoodsDefUnitOfMeasureId);
    nodeGoodsDefUnitOfMeasureId.setItsName(getSrvI18n().getMsg("itsId", lang));
    nodeGoodsDefUnitOfMeasureId
      .setItsValue(idx.toString() + ";defUnitOfMeasure,itsId");
    idx++;
    Node<String> nodePrice = new Node<String>();
    result.add(nodePrice);
    nodePrice.setItsName(getSrvI18n().getMsg("itsPrice", lang));
    nodePrice.setItsValue(idx.toString());
    idx++;
    Node<String> nodeCost = new Node<String>();
    result.add(nodeCost);
    nodeCost.setItsName(getSrvI18n().getMsg("itsCost", lang));
    nodeCost.setItsValue(idx.toString());
    idx++;
    Node<String> nodeQuantity = new Node<String>();
    result.add(nodeQuantity);
    nodeQuantity.setItsName(getSrvI18n().getMsg("itsQuantity", lang));
    nodeQuantity.setItsValue(idx.toString());
    idx++;
    Node<String> nodeIsAvailable = new Node<String>();
    result.add(nodeIsAvailable);
    nodeIsAvailable.setItsName(getSrvI18n().getMsg("isAvailable", lang));
    nodeIsAvailable.setItsValue(idx.toString());
    idx++;
    Node<String> nodeWarehouseSite = new Node<String>();
    result.add(nodeWarehouseSite);
    nodeWarehouseSite.setItsName(getSrvI18n().getMsg("WarehouseSite", lang));
    nodeWarehouseSite.setItsNodes(new ArrayList<Node<String>>());
    Node<String> nodeWarehouseSiteName = new Node<String>();
    nodeWarehouseSite.getItsNodes().add(nodeWarehouseSiteName);
    nodeWarehouseSiteName.setItsName(getSrvI18n().getMsg("itsName", lang));
    nodeWarehouseSiteName.setItsValue(idx.toString() + ";itsName");
    Node<String> nodeWarehouseSiteId = new Node<String>();
    nodeWarehouseSite.getItsNodes().add(nodeWarehouseSiteId);
    nodeWarehouseSiteId.setItsName(getSrvI18n().getMsg("itsId", lang));
    nodeWarehouseSiteId.setItsValue(idx.toString() + ";itsId");
    Node<String> nodeWarehouseSiteWarehouse = new Node<String>();
    nodeWarehouseSite.getItsNodes().add(nodeWarehouseSiteWarehouse);
    nodeWarehouseSiteWarehouse
      .setItsName(getSrvI18n().getMsg("warehouse", lang));
    nodeWarehouseSiteWarehouse.setItsNodes(new ArrayList<Node<String>>());
    Node<String> nodeWarehouseSiteWarehouseName = new Node<String>();
    nodeWarehouseSiteWarehouse.getItsNodes()
      .add(nodeWarehouseSiteWarehouseName);
    nodeWarehouseSiteWarehouseName
      .setItsName(getSrvI18n().getMsg("itsName", lang));
    nodeWarehouseSiteWarehouseName
      .setItsValue(idx.toString() + ";warehouse,itsName");
    Node<String> nodeWarehouseSiteWarehouseId = new Node<String>();
    nodeWarehouseSiteWarehouse.getItsNodes().add(nodeWarehouseSiteWarehouseId);
    nodeWarehouseSiteWarehouseId.setItsName(getSrvI18n().getMsg("itsId", lang));
    nodeWarehouseSiteWarehouseId
      .setItsValue(idx.toString() + ";warehouse,itsId");
    Set<String> ndFlIdNm = new HashSet<String>();
    ndFlIdNm.add("itsId");
    ndFlIdNm.add("itsName");
    pReqVars.put("InvItemTaxCategoryneededFields", ndFlIdNm);
    pReqVars.put("TaxneededFields", ndFlIdNm);
    List<InvItemTaxCategoryLine> allTaxCatsLns = getSrvOrm()
      .retrieveList(pReqVars, InvItemTaxCategoryLine.class);
    pReqVars.remove("InvItemTaxCategoryneededFields");
    pReqVars.remove("TaxneededFields");
    List<Tax> usedTaxes = new ArrayList<Tax>();
    List<InvItemTaxCategory> usedTaxCats = new ArrayList<InvItemTaxCategory>();
    for (InvItemTaxCategoryLine tcl : allTaxCatsLns) {
      boolean txListed = false;
      for (Tax tx : usedTaxes) {
        if (tx.getItsId().equals(tcl.getTax().getItsId())) {
          txListed = true;
          break;
        }
      }
      if (!txListed) {
        usedTaxes.add(tcl.getTax());
      }
      int tci = -1;
      for (InvItemTaxCategory tc : usedTaxCats) {
        if (tc.getItsId().equals(tcl.getItsOwner().getItsId())) {
          tci = usedTaxCats.indexOf(tc);
          break;
        }
      }
      if (tci == -1) {
        usedTaxCats.add(tcl.getItsOwner());
        tcl.getItsOwner().setTaxes(new ArrayList<InvItemTaxCategoryLine>());
        tcl.getItsOwner().getTaxes().add(tcl);
      } else {
        usedTaxCats.get(tci).getTaxes().add(tcl);
      }
    }
    boolean isOnlyTax = true;
    for (InvItemTaxCategory txc : usedTaxCats) {
      if (txc.getTaxes().size() > 1) {
        isOnlyTax = false;
        break;
      }
    }
    if (isOnlyTax) {
      idx++;
      addTaxWr(result, idx.toString(),
        getSrvI18n().getMsg("OnlyTax", lang), lang);
    } else {
      idx++;
      addTaxCatWr(result, idx.toString(),
        getSrvI18n().getMsg("taxCategory", lang), lang);
      Collections.sort(usedTaxes, new CmprHasIdLong<Tax>());
      for (Tax tx : usedTaxes) {
        idx++;
        addTaxWr(result, idx.toString(), tx.getItsName(), lang);
      }
      Collections.sort(usedTaxCats, new CmprHasIdLong<InvItemTaxCategory>());
      for (InvItemTaxCategory txc : usedTaxCats) {
        idx++;
        addTaxCatWr(result, idx.toString(), txc.getItsName(), lang);
      }
    }
    return result;
  }
999471
public static double[] multinomialGaussianSample(double[] mean, double[][] covariance) {
        MultivariateNormalDistribution gaussian = new 
            MultivariateNormalDistribution(mean, covariance);
        gaussian.reseedRandomGenerator(RandomGenerator.getThreadLocalRandom().nextLong());
        return gaussian.sample();
    }
597166
public double[] getInterleavedSamples() {
        double[] samples = new double[(int) getSampleCount()];
        try {
            getInterleavedSamples(0, getSampleCount(), samples);
        } catch (IllegalArgumentException | IOException e) {
            e.printStackTrace();
        }

        return samples;
    }
588028
public final double sampleCount()
  {
    long count = _count.get();
    long lastCount = _lastCount.getAndSet(count);

    return count - lastCount;
  }
428881
public static function stdev(array $values, $sample = false)
    {
        $variance = self::variance($values, $sample);

        return \sqrt($variance);
    }
296435
public static WindowOver<Double> covarSamp(Expression<? extends Number> expr1, Expression<? extends Number> expr2) {
        return new WindowOver<Double>(Double.class, SQLOps.COVARSAMP, expr1, expr2);
    }
632621
public static int[] getIndexesOfFreeVariable(Expression2 expression, String variableName) {
    List<Integer> indexes = Lists.newArrayList();
    ScopeSet scopes = getScopes(expression);
    for (int i = 0; i < expression.size(); i++) {
      Scope scope = scopes.getScope(i);
      String varName = getFreeVariable(expression, i, scope);
      if (varName != null && varName.equals(variableName)) {
        indexes.add(i);
      }
    }
    return Ints.toArray(indexes);
  }
1206380
public NumberExpression<Double> avg() {
        if (avg == null) {
            avg = Expressions.numberOperation(Double.class, Ops.AggOps.AVG_AGG, mixin);
        }
        return avg;
    }
941282
public static <T extends Number> WindowOver<T> stddev(Expression<T> expr) {
        return new WindowOver<T>(expr.getType(), SQLOps.STDDEV, expr);
    }
153746
@Override
	public double getVariance() {
		if(isDeterministic()) {
			return 0.0;
		}
		if(size() == 0) {
			return Double.NaN;
		}

		double sum			= 0.0;
		double sumOfSquared = 0.0;
		double errorOfSum			= 0.0;
		double errorOfSumSquared	= 0.0;
		for(int i=0; i<realizations.length; i++) {
			double value	= realizations[i] - errorOfSum;
			double newSum	= sum + value;
			errorOfSum		= (newSum - sum) - value;
			sum				= newSum;

			double valueSquared		= realizations[i] * realizations[i] - errorOfSumSquared;
			double newSumOfSquared	= sumOfSquared + valueSquared;
			errorOfSumSquared		= (newSumOfSquared-sumOfSquared) - valueSquared;
			sumOfSquared			= newSumOfSquared;
		}
		return (sumOfSquared/realizations.length - sum/realizations.length*sum/realizations.length);
	}
1108778
function anovafscore() {
    var args = slice.call(arguments),
    expVar, sample, sampMean, sampSampMean, tmpargs, unexpVar, i, j;
    if (args.length === 1) {
      tmpargs = new Array(args[0].length);
      for (i = 0; i < args[0].length; i++) {
        tmpargs[i] = args[0][i];
      }
      args = tmpargs;
    }
    // 2 sample case
    if (args.length === 2) {
      return jStat.variance(args[0]) / jStat.variance(args[1]);
    }
    // Builds sample array
    sample = new Array();
    for (i = 0; i < args.length; i++) {
      sample = sample.concat(args[i]);
    }
    sampMean = jStat.mean(sample);
    // Computes the explained variance
    expVar = 0;
    for (i = 0; i < args.length; i++) {
      expVar = expVar + args[i].length * Math.pow(jStat.mean(args[i]) - sampMean, 2);
    }
    expVar /= (args.length - 1);
    // Computes unexplained variance
    unexpVar = 0;
    for (i = 0; i < args.length; i++) {
      sampSampMean = jStat.mean(args[i]);
      for (j = 0; j < args[i].length; j++) {
        unexpVar += Math.pow(args[i][j] - sampSampMean, 2);
      }
    }
    unexpVar /= (sample.length - args.length);
    return expVar / unexpVar;
  }
152237
public Double getSampleValue(String name, String[] labelNames, String[] labelValues) {
    for (Collector.MetricFamilySamples metricFamilySamples : Collections.list(metricFamilySamples())) {
      for (Collector.MetricFamilySamples.Sample sample : metricFamilySamples.samples) {
        if (sample.name.equals(name)
                && Arrays.equals(sample.labelNames.toArray(), labelNames)
                && Arrays.equals(sample.labelValues.toArray(), labelValues)) {
          return sample.value;
        }
      }
    }
    return null;
  }
311760
public static /*@pure@*/ double variance(double[] vector) {
  
    double sum = 0, sumSquared = 0;

    if (vector.length <= 1) {
      return 0;
    }
    for (int i = 0; i < vector.length; i++) {
      sum += vector[i];
      sumSquared += (vector[i] * vector[i]);
    }
    double result = (sumSquared - (sum * sum / (double) vector.length)) / 
      (double) (vector.length - 1);

    // We don't like negative variance
    if (result < 0) {
      return 0;
    } else {
      return result;
    }
  }
1088884
public final double sampleCount()
  {
    synchronized (_lock) {
      long count = _count.get();
      long lastCount = _lastCount;
      _lastCount = count;

      return count - lastCount;
    }
  }
991471
public synchronized double variance()
    {
        long n = 0;
        double mean = 0;
        double s = 0.0;

        for (double x : m_times.m_values)
        {
            n++;
            double delta = x - mean;
            mean += delta / n;
            s += delta * (x - mean);
        }

        return (s / n);
    }