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;
022
023
024import java.text.DecimalFormat;
025
026/**
027 *
028 * @author Scooter Willis <willishf at gmail dot com>
029 */
030public class CoxCoefficient {
031
032        String name;
033        double coeff; //beta
034        double stdError; //se
035        double robustStdError; //nse
036        double z;
037        double hazardRatio; //exp(beta)
038        double hazardRatioLoCI;
039        double hazardRatioHiCI;
040        double pvalue;
041        double mean;
042        double standardDeviation;
043
044        /**
045         *
046         */
047        public CoxCoefficient() {
048        }
049
050        @Override
051        public String toString() {
052                return name + " " + coeff + " " + pvalue + " " + hazardRatio + " " + hazardRatioLoCI + " " + hazardRatioHiCI;
053        }
054
055        /**
056         *
057         * @return
058         */
059        public String getHRText() {
060                return fmt(hazardRatio, 2, 0) + " CI(" + fmt(hazardRatioLoCI, 2, 0) + "-" + fmt(hazardRatioHiCI, 2, 0) + ")";
061        }
062
063        /**
064         * @return the name
065         */
066        public String getName() {
067                return name;
068        }
069
070        /**
071         * @return the coeff
072         */
073        public double getCoeff() {
074                return coeff;
075        }
076
077        /**
078         * @return the stdError
079         */
080        public double getStdError() {
081                return stdError;
082        }
083
084        /**
085         * @return the robustStdError
086         */
087        public double getRobustStdError() {
088                return robustStdError;
089        }
090
091        /**
092         * @return the z
093         */
094        public double getZ() {
095                return z;
096        }
097
098        /**
099         * @return the hazardRatio
100         */
101        public double getHazardRatio() {
102                return hazardRatio;
103        }
104
105        /**
106         * @return the hazardRatioLoCI
107         */
108        public double getHazardRatioLoCI() {
109                return hazardRatioLoCI;
110        }
111
112        /**
113         * @return the hazardRatioHiCI
114         */
115        public double getHazardRatioHiCI() {
116                return hazardRatioHiCI;
117        }
118
119        /**
120         * @return the pvalue
121         */
122        public double getPvalue() {
123                return pvalue;
124        }
125
126        /**
127         * @return the mean
128         */
129        public double getMean() {
130                return mean;
131        }
132
133        /**
134         * @return the standardDeviation
135         */
136        public double getStandardDeviation() {
137                return standardDeviation;
138        }
139
140        /**
141         * @param name the name to set
142         */
143        public void setName(String name) {
144                this.name = name;
145        }
146
147        /**
148         * @param coeff the coeff to set
149         */
150        public void setCoeff(double coeff) {
151                this.coeff = coeff;
152        }
153
154        /**
155         * @param stdError the stdError to set
156         */
157        public void setStdError(double stdError) {
158                this.stdError = stdError;
159        }
160
161        /**
162         * @param robustStdError the robustStdError to set
163         */
164        public void setRobustStdError(double robustStdError) {
165                this.robustStdError = robustStdError;
166        }
167
168        /**
169         * @param z the z to set
170         */
171        public void setZ(double z) {
172                this.z = z;
173        }
174
175        /**
176         * @param hazardRatio the hazardRatio to set
177         */
178        public void setHazardRatio(double hazardRatio) {
179                this.hazardRatio = hazardRatio;
180        }
181
182        /**
183         * @param hazardRatioLoCI the hazardRatioLoCI to set
184         */
185        public void setHazardRatioLoCI(double hazardRatioLoCI) {
186                this.hazardRatioLoCI = hazardRatioLoCI;
187        }
188
189        /**
190         * @param hazardRatioHiCI the hazardRatioHiCI to set
191         */
192        public void setHazardRatioHiCI(double hazardRatioHiCI) {
193                this.hazardRatioHiCI = hazardRatioHiCI;
194        }
195
196        /**
197         * @param pvalue the pvalue to set
198         */
199        public void setPvalue(double pvalue) {
200                this.pvalue = pvalue;
201        }
202
203        /**
204         * @param mean the mean to set
205         */
206        public void setMean(double mean) {
207                this.mean = mean;
208        }
209
210        /**
211         * @param standardDeviation the standardDeviation to set
212         */
213        public void setStandardDeviation(double standardDeviation) {
214                this.standardDeviation = standardDeviation;
215        }
216
217                /**
218         *
219         * @param d
220         * @param precision
221         * @param pad
222         * @return
223         */
224        public static String fmt(Double d, int precision, int pad) {
225                String value = "";
226                DecimalFormat dfe = new DecimalFormat("0.00E0");
227                String dpad = "0.";
228                double p = 1.0;
229                for (int i = 0; i < (precision); i++) {
230                        dpad = dpad + "0";
231                        p = p / 10.0;
232                }
233                DecimalFormat df = new DecimalFormat(dpad);
234                if (Math.abs(d) >= p) {
235                        value = df.format(d);
236                } else {
237                        value = dfe.format(d);
238                }
239                int length = value.length();
240                int extra = pad - length;
241                if (extra > 0) {
242                        for (int i = 0; i < extra; i++) {
243                                value = " " + value;
244                        }
245                }
246                return value;
247        }
248}