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.io.Serializable;
027import java.util.Comparator;
028
029/**
030 *
031 * @author Scooter Willis <willishf at gmail dot com>
032 */
033public class MeanModelComparator implements Comparator<CoxVariables>, Serializable {
034        private static final long serialVersionUID = 1;
035
036        String variable = "";
037
038        /**
039         *
040         * @param variable
041         */
042        public MeanModelComparator(String variable) {
043          this.variable = variable;
044        }
045
046        @Override
047        public int compare(CoxVariables coxVariables1, CoxVariables coxVariables2) {
048                CoxInfo ci1LTMean = coxVariables1.getCoxInfo("<MEAN");
049                CoxInfo ci1GTMean = coxVariables1.getCoxInfo(">MEAN");
050
051                if(ci1LTMean == null || ci1GTMean == null)
052                        return 0;
053
054                double c1LTpvalue = ci1LTMean.getCoefficient(variable).getPvalue();
055                double c1GTpvalue = ci1GTMean.getCoefficient(variable).getPvalue();
056
057                double c1ratio = Math.min(c1LTpvalue, c1GTpvalue) / Math.max(c1LTpvalue, c1GTpvalue);
058
059                CoxInfo ci2LTMean = coxVariables2.getCoxInfo("<MEAN");
060                CoxInfo ci2GTMean = coxVariables2.getCoxInfo(">MEAN");
061
062                double c2LTpvalue = ci2LTMean.getCoefficient(variable).getPvalue();
063                double c2GTpvalue = ci2GTMean.getCoefficient(variable).getPvalue();
064
065           double c2ratio = Math.min(c2LTpvalue, c2GTpvalue) / Math.max(c2LTpvalue, c2GTpvalue);
066
067                if (c1ratio > c2ratio) {
068                        return 1;
069                } else if (c1ratio < c2ratio) {
070                        return -1;
071                } else {
072                        return 0;
073                }
074                //ascending order
075                // return coxVariables1.compareTo(coxVariables2);
076        }
077}