001/*
002 *                    BioJava development code
003 *
004 * This code may be freely distributed and modified under the
005 * terms of the GNU Lesser General Public Licence.  This should
006 * be distributed with the code.  If you do not have a copy,
007 * see:
008 *
009 *      http://www.gnu.org/copyleft/lesser.html
010 *
011 * Copyright for this code is held jointly by the individual
012 * authors.  These should be listed in @author doc comments.
013 *
014 * For more information on the BioJava project and its aims,
015 * or to join the biojava-l mailing list, visit the home page
016 * at:
017 *
018 *      http://www.biojava.org/
019 *
020 */
021package org.biojava.nbio.survival.cox.comparators;
022
023import org.biojava.nbio.survival.cox.CoxInfo;
024import org.biojava.nbio.survival.cox.CoxVariables;
025
026import java.util.Comparator;
027
028/**
029 *
030 * @author Scooter Willis <willishf at gmail dot com>
031 */
032public class MeanModelComparator implements Comparator<CoxVariables> {
033
034        String variable = "";
035
036        /**
037         *
038         * @param variable
039         */
040        public MeanModelComparator(String variable) {
041          this.variable = variable;
042        }
043
044        @Override
045        public int compare(CoxVariables coxVariables1, CoxVariables coxVariables2) {
046                CoxInfo ci1LTMean = coxVariables1.getCoxInfo("<MEAN");
047                CoxInfo ci1GTMean = coxVariables1.getCoxInfo(">MEAN");
048
049                if(ci1LTMean == null || ci1GTMean == null)
050                        return 0;
051
052                double c1LTpvalue = ci1LTMean.getCoefficient(variable).getPvalue();
053                double c1GTpvalue = ci1GTMean.getCoefficient(variable).getPvalue();
054
055                double c1ratio = Math.min(c1LTpvalue, c1GTpvalue) / Math.max(c1LTpvalue, c1GTpvalue);
056
057                CoxInfo ci2LTMean = coxVariables2.getCoxInfo("<MEAN");
058                CoxInfo ci2GTMean = coxVariables2.getCoxInfo(">MEAN");
059
060                double c2LTpvalue = ci2LTMean.getCoefficient(variable).getPvalue();
061                double c2GTpvalue = ci2GTMean.getCoefficient(variable).getPvalue();
062
063           double c2ratio = Math.min(c2LTpvalue, c2GTpvalue) / Math.max(c2LTpvalue, c2GTpvalue);
064
065                if (c1ratio > c2ratio) {
066                        return 1;
067                } else if (c1ratio < c2ratio) {
068                        return -1;
069                } else {
070                        return 0;
071                }
072                //ascending order
073                // return coxVariables1.compareTo(coxVariables2);
074        }
075}