Example usage for org.apache.commons.math3.stat.regression SimpleRegression getSlopeConfidenceInterval

List of usage examples for org.apache.commons.math3.stat.regression SimpleRegression getSlopeConfidenceInterval

Introduction

In this page you can find the example usage for org.apache.commons.math3.stat.regression SimpleRegression getSlopeConfidenceInterval.

Prototype

public double getSlopeConfidenceInterval() throws OutOfRangeException 

Source Link

Document

Returns the half-width of a 95% confidence interval for the slope estimate.

Usage

From source file:org.apache.solr.client.solrj.io.eval.RegressionEvaluator.java

@Override
public Object doWork(Object first, Object second) throws IOException {
    if (null == first) {
        throw new IOException(String.format(Locale.ROOT,
                "Invalid expression %s - null found for the first value", toExpression(constructingFactory)));
    }//from w w  w.j a v  a2s .co  m
    if (null == second) {
        throw new IOException(String.format(Locale.ROOT,
                "Invalid expression %s - null found for the second value", toExpression(constructingFactory)));
    }
    if (!(first instanceof List<?>)) {
        throw new IOException(String.format(Locale.ROOT,
                "Invalid expression %s - found type %s for the first value, expecting a list of numbers",
                toExpression(constructingFactory), first.getClass().getSimpleName()));
    }
    if (!(second instanceof List<?>)) {
        throw new IOException(String.format(Locale.ROOT,
                "Invalid expression %s - found type %s for the second value, expecting a list of numbers",
                toExpression(constructingFactory), first.getClass().getSimpleName()));
    }

    List<?> l1 = (List<?>) first;
    List<?> l2 = (List<?>) second;

    if (l2.size() < l1.size()) {
        throw new IOException(String.format(Locale.ROOT,
                "Invalid expression %s - first list (%d) has more values than the second list (%d)",
                toExpression(constructingFactory), l1.size(), l2.size()));
    }

    SimpleRegression regression = new SimpleRegression();
    for (int idx = 0; idx < l1.size(); ++idx) {
        regression.addData(((BigDecimal) l1.get(idx)).doubleValue(), ((BigDecimal) l2.get(idx)).doubleValue());
    }

    Map<String, Number> map = new HashMap<>();
    map.put("slope", regression.getSlope());
    map.put("intercept", regression.getIntercept());
    map.put("R", regression.getR());
    map.put("N", regression.getN());
    map.put("RSquare", regression.getRSquare());
    map.put("regressionSumSquares", regression.getRegressionSumSquares());
    map.put("slopeConfidenceInterval", regression.getSlopeConfidenceInterval());
    map.put("interceptStdErr", regression.getInterceptStdErr());
    map.put("totalSumSquares", regression.getTotalSumSquares());
    map.put("significance", regression.getSignificance());
    map.put("meanSquareError", regression.getMeanSquareError());

    return new RegressionTuple(regression, map);
}

From source file:org.apache.solr.client.solrj.io.stream.RegressionEvaluator.java

public Tuple evaluate(Tuple tuple) throws IOException {

    if (subEvaluators.size() != 2) {
        throw new IOException("Regress expects 2 columns as parameters");
    }/*from ww  w .j a va 2  s .com*/

    StreamEvaluator colEval1 = subEvaluators.get(0);
    StreamEvaluator colEval2 = subEvaluators.get(1);

    List<Number> numbers1 = (List<Number>) colEval1.evaluate(tuple);
    List<Number> numbers2 = (List<Number>) colEval2.evaluate(tuple);
    double[] column1 = new double[numbers1.size()];
    double[] column2 = new double[numbers2.size()];

    for (int i = 0; i < numbers1.size(); i++) {
        column1[i] = numbers1.get(i).doubleValue();
    }

    for (int i = 0; i < numbers2.size(); i++) {
        column2[i] = numbers2.get(i).doubleValue();
    }

    SimpleRegression regression = new SimpleRegression();
    for (int i = 0; i < column1.length; i++) {
        regression.addData(column1[i], column2[i]);
    }

    Map map = new HashMap();
    map.put("slope", regression.getSlope());
    map.put("intercept", regression.getIntercept());
    map.put("R", regression.getR());
    map.put("N", regression.getN());
    map.put("regressionSumSquares", regression.getRegressionSumSquares());
    map.put("slopeConfidenceInterval", regression.getSlopeConfidenceInterval());
    map.put("interceptStdErr", regression.getInterceptStdErr());
    map.put("totalSumSquares", regression.getTotalSumSquares());
    map.put("significance", regression.getSignificance());
    map.put("meanSquareError", regression.getMeanSquareError());
    return new RegressionTuple(regression, map);
}