1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package ubic.basecode.math.linearmodels;
20
21 import org.apache.commons.lang3.StringUtils;
22
23 import java.io.Serializable;
24
25
26
27
28
29
30
31 public class AnovaEffect implements Serializable {
32
33 private static final long serialVersionUID = 1L;
34
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 }
48 this.effectName = effectName;
49 this.pValue = pValue;
50 this.fStat = fStat;
51 this.dof = dof;
52 this.ssQ = ssQ;
53 this.meanSq = ssQ / dof;
54 this.isInteraction = isInteraction;
55 this.isResiduals = isResiduals;
56 }
57
58
59
60
61 public double getDof() {
62 return dof;
63 }
64
65
66
67
68 public String getEffectName() {
69 return effectName;
70 }
71
72
73
74
75 public double getFStat() {
76 return fStat;
77 }
78
79
80
81
82 public double getMeanSq() {
83 return meanSq;
84 }
85
86
87
88
89 public double getPValue() {
90 return pValue;
91 }
92
93
94
95
96 public double getSsQ() {
97 return ssQ;
98 }
99
100
101
102
103 public boolean isInteraction() {
104 return isInteraction;
105 }
106
107 public boolean isResiduals() {
108 return isResiduals;
109 }
110
111 @Override
112 public String toString() {
113 StringBuilder buf = new StringBuilder();
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" );
120 buf.append( String.format( "%.3g", getPValue() ) );
121 }
122 return buf.toString();
123 }
124 }