11/*
22 * The baseCode project
3- *
3+ *
44 * Copyright (c) 2010 University of British Columbia
5- *
5+ *
66 * Licensed under the Apache License, Version 2.0 (the "License");
77 * you may not use this file except in compliance with the License.
88 * You may obtain a copy of the License at
1616 * limitations under the License.
1717 *
1818 */
19+ package ubic .basecode .math .linearmodels ;
1920
20- package ubic . basecode . util . r . type ;
21+ import org . apache . commons . lang3 . StringUtils ;
2122
2223import java .io .Serializable ;
2324
24- import org .apache .commons .lang3 .StringUtils ;
25-
2625/**
2726 * Represents one row of an ANOVA table
28- *
27+ *
2928 * @author paul
30- *
29+ *
3130 */
3231public class AnovaEffect implements Serializable {
3332
3433 private static final long serialVersionUID = 1L ;
3534
36- private Double degreesOfFreedom = null ;
37-
38- private String effectName = null ;
39-
40- private Double fStatistic = Double .NaN ;
41-
42- private boolean isInteraction = false ;
43-
44- private Double meanSq = Double .NaN ;
45-
46- private Double pValue = Double .NaN ;
47-
48- private Double ssQ = Double .NaN ;
49-
50- /**
51- * @param effectName
52- * @param pValue
53- * @param fStatistic
54- * @param degreesOfFreedom
55- * @param ssQ
56- * @param isInteraction
57- */
58- public AnovaEffect ( String effectName , Double pValue , Double fStatistic , Double degreesOfFreedom , Double ssQ ,
59- boolean isInteraction ) {
60- super ();
35+ private final double dof ;
36+ private final String effectName ;
37+ private final double fStat ;
38+ private final boolean isInteraction ;
39+ private final boolean isResiduals ;
40+ private final double meanSq ;
41+ private final double pValue ;
42+ private final double ssQ ;
43+
44+ public AnovaEffect ( String effectName , double pValue , double fStat , double dof , double ssQ , boolean isInteraction , boolean isResiduals ) {
45+ if ( isResiduals && isInteraction ) {
46+ throw new IllegalArgumentException ( "An ANOVA effect cannot be both a residual and an interaction." );
47+ }
6148 this .effectName = effectName ;
6249 this .pValue = pValue ;
63- this .fStatistic = fStatistic ;
64- this .degreesOfFreedom = degreesOfFreedom ;
50+ this .fStat = fStat ;
51+ this .dof = dof ;
6552 this .ssQ = ssQ ;
66- this .meanSq = ssQ / degreesOfFreedom ;
53+ this .meanSq = ssQ / dof ;
6754 this .isInteraction = isInteraction ;
55+ this .isResiduals = isResiduals ;
6856 }
6957
7058 /**
7159 * @return the degreesOfFreedom
7260 */
73- public Double getDegreesOfFreedom () {
74- return degreesOfFreedom ;
61+ public double getDof () {
62+ return dof ;
7563 }
7664
7765 /**
@@ -84,28 +72,28 @@ public String getEffectName() {
8472 /**
8573 * @return the fStatistic
8674 */
87- public Double getFStatistic () {
88- return fStatistic ;
75+ public double getFStat () {
76+ return fStat ;
8977 }
9078
9179 /**
9280 * @return the meanSq
9381 */
94- public Double getMeanSq () {
82+ public double getMeanSq () {
9583 return meanSq ;
9684 }
9785
9886 /**
9987 * @return the pValue
10088 */
101- public Double getPValue () {
89+ public double getPValue () {
10290 return pValue ;
10391 }
10492
10593 /**
10694 * @return the ssQ
10795 */
108- public Double getSsQ () {
96+ public double getSsQ () {
10997 return ssQ ;
11098 }
11199
@@ -116,19 +104,21 @@ public boolean isInteraction() {
116104 return isInteraction ;
117105 }
118106
107+ public boolean isResiduals () {
108+ return isResiduals ;
109+ }
110+
119111 @ Override
120112 public String toString () {
121113 StringBuilder buf = new StringBuilder ();
122- buf .append ( StringUtils .rightPad ( StringUtils .abbreviate ( getEffectName (), 10 ), 10 ) + "\t " );
123- buf .append ( String .format ( "%.2f" , getDegreesOfFreedom () ) + "\t " );
124- buf .append ( String .format ( "%.4f" , getSsQ () ) + "\t " );
125- buf .append ( String .format ( "%.4f" , getMeanSq () ) + "\t " );
126-
127- if ( fStatistic != null ) {
128- buf .append ( StringUtils .rightPad ( String .format ( "%.3f" , getFStatistic () ), 6 ) + "\t " );
114+ buf .append ( StringUtils .rightPad ( StringUtils .abbreviate ( getEffectName (), 10 ), 10 ) ).append ( "\t " );
115+ buf .append ( String .format ( "%.2f" , getDof () ) ).append ( "\t " );
116+ buf .append ( String .format ( "%.4f" , getSsQ () ) ).append ( "\t " );
117+ buf .append ( String .format ( "%.4f" , getMeanSq () ) ).append ( "\t " );
118+ if ( !Double .isNaN ( fStat ) ) {
119+ buf .append ( StringUtils .rightPad ( String .format ( "%.3f" , getFStat () ), 6 ) ).append ( "\t " );
129120 buf .append ( String .format ( "%.3g" , getPValue () ) );
130121 }
131122 return buf .toString ();
132123 }
133-
134124}
0 commit comments