List of usage examples for org.apache.commons.math3.stat.regression SimpleRegression getInterceptStdErr
public double getInterceptStdErr()
From source file:nl.systemsgenetics.cellTypeSpecificAlleleSpecificExpression.CTSlinearRegression.java
public CTSlinearRegression(ArrayList<IndividualSnpData> all_individuals) { //basic information, get the zero instance. snpName = all_individuals.get(0).getSnpName(); chromosome = all_individuals.get(0).getChromosome(); position = all_individuals.get(0).getPosition(); //isolate heterozygotes ArrayList<IndividualSnpData> het_individuals = UtilityMethods .isolateValidHeterozygotesFromIndividualSnpData(all_individuals); numberOfHets = het_individuals.size(); hetSampleNames = new ArrayList<String>(); asRef = new ArrayList<Integer>(); asAlt = new ArrayList<Integer>(); asNo = new ArrayList<Integer>(); cellProp = new ArrayList<Double>(); int total_overlap = 0; //Get the basic data without doing any tests. for (IndividualSnpData temp_het : het_individuals) { //Do nothing if there is no data in het_individuals hetSampleNames.add(temp_het.getSampleName()); asRef.add(temp_het.getRefNum()); asAlt.add(temp_het.getAltNum()); asNo.add(temp_het.getNoNum());/* w w w . java2s . co m*/ cellProp.add(temp_het.getCellTypeProp()); //this is used to check if we will continue with calculations. //BASED on the minHets and MinReads total_overlap += temp_het.getRefNum() + temp_het.getAltNum(); } //Check if we do a test. if ((total_overlap >= GlobalVariables.minReads) && (numberOfHets >= GlobalVariables.minHets) && (numberOfHets >= 3)) { ASScatterPlot plotThis = null; if (!GlobalVariables.plotDir.equals("")) { plotThis = new ASScatterPlot(400); } SimpleRegression thisRegression = new SimpleRegression(); for (int i = 0; i < asRef.size(); i++) { Double asRatio; //do this check, otherwise the denominator will be zero. if (asRef.get(i) != 0) { asRatio = ((double) asRef.get(i)) / ((double) (asRef.get(i) + asAlt.get(i))); } else { asRatio = 0.0; } Double phenoRatio = cellProp.get(i); thisRegression.addData(phenoRatio, asRatio); if (!GlobalVariables.plotDir.equals("")) { plotThis.plot(asRatio, phenoRatio); } } if (!GlobalVariables.plotDir.equals("")) { plotThis.draw(GlobalVariables.plotDir + "/" + snpName + "_ASratio_Pheno_Plot.png"); } slope = thisRegression.getSlope(); intercept = thisRegression.getIntercept(); Rsquared = thisRegression.getRSquare(); stdErrorIntercept = thisRegression.getInterceptStdErr(); stdErrorSlope = thisRegression.getSlopeStdErr(); pValue = thisRegression.getSignificance(); if (GlobalVariables.verbosity >= 10) { System.out.println("\n--- Starting cell type specific linear regression ---"); System.out.println("\tSlope: " + Double.toString(slope)); System.out.println("\tStdError of Slope: " + Double.toString(stdErrorSlope) + "\n"); System.out.println("\tIntercept: " + Double.toString(intercept)); System.out.println("\tStdError of Intercept: " + Double.toString(stdErrorIntercept) + "\n"); System.out.println("\tP value: " + Double.toString(pValue)); System.out.println("--------------------------------------------------------------"); } testPerformed = true; } }
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 va 2 s . 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"); }/*w ww.j av a 2 s .co m*/ 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); }
From source file:sim.module.broker.bo.BrokerAgent.java
/** * Forecast future deficit using linear regression forecast. * /*w ww. j av a 2 s. c om*/ * Forecast: Using the last 3 years data (36 months): * 1. Use linear regression to estimate linear trend line. * 2. Calculate seasonal index (monthly residual from trend line) * 3. Use trend line to produce linear forecast * 4. Add seasonal (monthly) effects to forecast demand for each future month, t: forecast(t). * * @param - recent historical demand over the last 36 months (inclusive of *this* month) * @return demand forecast list for the next [learning period = 36] months */ public List<Double> getForecastDemandUsingLinearRegression(List<Double> historicDemand) { List<Double> forecastDemand = new ArrayList<Double>(); List<Double> trendLine = new ArrayList<Double>(); List<Double> residuals = new ArrayList<Double>(); List<Double> monthlyResiduals = new ArrayList<Double>(); if (historicDemand.size() != learningPeriod) { logger.warn("*** Historic data list is incorrect size. Returning zero forecast list. *** Size = " + historicDemand.size() + ", Size should be = " + learningPeriod + ", historicData: " + historicDemand); for (int i = 0; i < learningPeriod; i++) { forecastDemand.add(0.0); } return forecastDemand; } else { //convert List into 2d array double[][] historicDataArray = new double[historicDemand.size()][2]; int index = 0; for (double h : historicDemand) { historicDataArray[index][0] = index; historicDataArray[index][1] = h; index++; } logger.debug("Historic array: " + Arrays.deepToString(historicDataArray)); // now do the regression... SimpleRegression regression = new SimpleRegression(); regression.addData(historicDataArray); logger.debug("Regression: m=" + regression.getSlope() + ", c=" + regression.getIntercept() + ", cStdErr=" + regression.getInterceptStdErr()); // now get the trend line & residuals for (int i = 0; i < historicDemand.size(); i++) { trendLine.add((i * regression.getSlope()) + regression.getIntercept()); residuals.add(historicDemand.get(i) - trendLine.get(i)); } logger.debug("Trend line = " + trendLine); logger.debug("Residuals = " + residuals); // get mean residuals per month for (int i = 0; i < 12; i++) { logger.debug("We are assuming that learning period is 36 months. Make this generic code!!!"); //TODO use %12 and iterate through to make this generic monthlyResiduals.add((residuals.get(i) + residuals.get(i + 12) + residuals.get(i + 24)) / 3); } logger.debug("mean monthly residuals: " + monthlyResiduals); // now forecast using monthly residuals and trend line // first set forecast using trendline for (double t : trendLine) { forecastDemand.add(t); } // forecast using trend line plus monthly adjustment for (int i = 0; i < 12; i++) { //TODO: Make this code generic not fixed to 36 months forecastDemand.set(i, trendLine.get(i) + monthlyResiduals.get(i)); forecastDemand.set(i + 12, trendLine.get(i + 12) + monthlyResiduals.get(i)); forecastDemand.set(i + 24, trendLine.get(i + 24) + monthlyResiduals.get(i)); } // finally, multiply normalised demand by number of agents for (int i = 0; i < forecastDemand.size(); i++) { forecastDemand.set(i, Math.floor(forecastDemand.get(i) * BrokerModuleRunner.getInstance().getNumEachAgent())); } logger.debug("final forecast with seasonal adjustment: " + forecastDemand); logger.debug("RForecastDemand: " + forecastDemand); logger.debug("Previous demand: " + historicDemand); return forecastDemand; } }
From source file:uk.ac.diamond.scisoft.ncd.core.data.plots.GuinierPlotData.java
private Amount<Dimensionless> getI0(SimpleRegression regression) { Amount<Dimensionless> I0 = Amount.valueOf(regression.getIntercept(), regression.getInterceptStdErr(), Dimensionless.UNIT);//from ww w. ja va2s . c om return I0.copy(); }
From source file:uk.ac.diamond.scisoft.ncd.core.data.plots.PorodPlotData.java
public Amount<Dimensionless> getC4(SimpleRegression regression) { Amount<Dimensionless> c4 = Amount.valueOf(regression.getIntercept(), regression.getInterceptStdErr(), Dimensionless.UNIT);/*from ww w.j a v a 2 s. c o m*/ return c4.copy(); }