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

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

Introduction

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

Prototype

public double getSlopeStdErr() 

Source Link

Document

Returns the <a href="http://www.xycoon.com/standerrorb(1).htm">standard error of the slope estimate</a>, usually denoted s(b1).

Usage

From source file:edu.ucsc.barrel.cdf_gen.ExtractTiming.java

public void fillModels() {
    int last_rec = 0, frame_i = 0, size_1Hz;
    long last_frame;
    SimpleRegression fit = null, new_fit = null;

    size_1Hz = data.getSize("1Hz");
    //create a model for each batch of time records
    for (int first_rec = 0; first_rec < time_rec_cnt; first_rec = last_rec) {
        //incriment the last_rec by the max, or however many recs are left
        last_rec += Math.min(MAX_RECS, (time_rec_cnt - first_rec));

        //try to generate a model
        new_fit = genModel(first_rec, last_rec);

        //Need to add better criteria than this for accepting a new model
        if (new_fit != null) {
            fit = new_fit;

            models[model_cnt] = new LinModel();
            models[model_cnt].setSlope(fit.getSlope());
            models[model_cnt].setIntercept(fit.getIntercept());
            models[model_cnt].setFirst(time_recs[first_rec].getFrame());
            models[model_cnt].setLast(time_recs[last_rec - 1].getFrame());
            model_cnt++;//from   w ww. j a va  2s .c o m

            System.out.println(
                    "Frames " + time_recs[first_rec].getFrame() + " - " + time_recs[last_rec - 1].getFrame());
            System.out.println("\tm = " + fit.getSlope() + ", b = " + fit.getIntercept() + " slope error = "
                    + fit.getSlopeStdErr() + " n = " + fit.getN());
        } else {
            System.out.println("Failed to get model using " + (last_rec - first_rec) + " records.");
        }
    }

    if (fit == null) {
        //no timing model was ever created. 
        //Use slope=1000 and intercept=0 to use frame number epoch.
        //this will clearly not give a good result for time, but will
        //allow the data to be plotted as a time series.
        //This will be a place to add a quality flag
        models[model_cnt] = new LinModel();
        models[model_cnt].setSlope(1000);
        models[model_cnt].setIntercept(0);
        models[model_cnt].setFirst(0);
        models[model_cnt].setLast(data.frame_1Hz[size_1Hz]);
        model_cnt = 1;
    }
}

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());/* ww  w .  ja v  a2 s.  c om*/
        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:uk.ac.diamond.scisoft.ncd.core.data.plots.GuinierPlotData.java

private Amount<Dimensionless> getRg(SimpleRegression regression) {
    Amount<Dimensionless> slope = Amount.valueOf(regression.getSlope(), regression.getSlopeStdErr(),
            Dimensionless.UNIT);//  w  ww .  j a v a  2s.  c o  m
    Amount<Dimensionless> Rg = slope.times(-3.0).sqrt().to(Dimensionless.UNIT);
    return Rg.copy();
}