Example usage for org.apache.commons.math.stat.regression SimpleRegression getR

List of usage examples for org.apache.commons.math.stat.regression SimpleRegression getR

Introduction

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

Prototype

public double getR() 

Source Link

Document

Returns <a href="http://mathworld.wolfram.com/CorrelationCoefficient.html"> Pearson's product moment correlation coefficient</a>, usually denoted r.

Usage

From source file:net.sf.mzmine.modules.peaklistmethods.identification.metamsecorrelate.MetaMSEcorrelateTask.java

/**
 * correlates the height profile of one row to another
 * NO escape routine/*from  w  w w. ja  va  2s  .  c o  m*/
 * @param raw
 * @param row
 * @param g
 * @return Pearson r of height correlation
 */
public static double corrRowToRowIProfile(final RawDataFile raw[], PeakListRow row, PeakListRow g) {
    SimpleRegression reg = new SimpleRegression();
    // go through all raw files 
    for (int r = 0; r < raw.length; r++) {
        Feature f1 = row.getPeak(raw[r]);
        Feature f2 = g.getPeak(raw[r]);
        // I profile correlation
        // TODO: low value imputation?
        double I1 = f1 != null ? f1.getHeight() : 0;
        double I2 = f2 != null ? f2.getHeight() : 0;
        reg.addData(I1, I2);
    }
    // TODO weighting of intensity corr
    double corrIprofile = reg.getR();
    return corrIprofile;
}

From source file:net.sf.mzmine.modules.peaklistmethods.identification.metamsecorrelate.MetaMSEcorrelateTask.java

/**
 * correlates one row to another/*from w  w  w. j  a va  2  s.c o  m*/
 * peak shape correlation (Pearson) (if negative or zero direct escape)
 *       otherwise avg(corr)>= minCorrPeakShape
 * intensity profile correlation (Pearson) >= minCorrIProfile
 *       TODO: maybe impute low values instead of 0 for not detected!
 * @param row
 * @param g
 * @return average correlation over both factors ranging from minR to 1 (or 0 if minimum correlation was not met)
 * @throws Exception 
 */
private double corrRowToRow(final PeakList peakList, final RawDataFile raw[], PeakListRow row, PeakListRow row2)
        throws Exception {
    double corr = 0;
    SimpleRegression reg = new SimpleRegression();
    // count
    int c = 0;
    // go through all raw files 
    for (int r = 0; r < raw.length; r++) {
        Feature f1 = row.getPeak(raw[r]);
        Feature f2 = row2.getPeak(raw[r]);
        if (f1 != null && f2 != null) {
            // peak shape correlation
            FeatureShapeCorrelationData cFS = corrFeatureShape(f1, f2, true);
            if (cFS != null) {
                double tmpcorr = cFS.getR();
                // escape if peak shapes are showing a negative correlation
                if (tmpcorr <= 0)
                    return tmpcorr;
                corr += tmpcorr;
                c++;
            } else {
                // correlation was not possible
                // maybe due to a small peak in this raw file
                // escape if features would be high enough for a correlation
                // this means the features are not intercepting
                if (countDPHigherThanNoise(f1) >= minCorrelatedDataPoints
                        && countDPHigherThanNoise(f2) >= minCorrelatedDataPoints)
                    return 0;
            }
        }
        // I profile correlation
        // TODO: low value imputation?
        double I1 = f1 != null ? f1.getHeight() : 0;
        double I2 = f2 != null ? f2.getHeight() : 0;
        reg.addData(I1, I2);
    }
    // First search for isotopes TODO later fill in isotopes from raw
    int absCharge = AlignedIsotopeGrouperTask.find13CIsotope(peakList, row, row2, maxCharge, mzTolerance);
    boolean isIsotope = absCharge != -1;
    // TODO search for adducts and add correlation: IProfile doesnt have to be the same for adducts
    boolean isAdduct = false;
    if (!isIsotope)
        findAdducts(peakList, row, row2, row.getRowCharge(), row2.getRowCharge());
    double adductBonus = (isIsotope || isAdduct) && useAdductBonusR ? adductBonusR : 0;
    // TODO weighting of intensity corr and feature shape corr
    // there was no correlation possible due to small peaks
    if (c == 0) {
        // 
        return isAdduct || isIsotope ? 1 : 0;
    } else {
        corr = (corr / c);
        double corrIprofile = reg.getR();
        if (corr + adductBonus < minShapeCorrR)
            return 0;
        else if (corrIprofile < minIntensityProfileR)
            return 0;
        else
            return (corr + corrIprofile) / 2;
    }
}