1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package ubic.basecode.util.r;
20
21 import org.rosuda.REngine.REXP;
22 import org.rosuda.REngine.REXPMismatchException;
23 import org.rosuda.REngine.RList;
24 import ubic.basecode.math.linearmodels.OneWayAnovaResult;
25
26
27
28
29
30 class OneWayAnovaResultImpl extends AbstractAnovaResult implements OneWayAnovaResult {
31
32 private final String factorName;
33 private final double mainEffectDof;
34 private final double mainEffectFStat;
35 private final double mainEffectPValue;
36 private final double residualDof;
37 private final double residualFStat;
38 private final double residualPValue;
39
40
41
42
43 public OneWayAnovaResultImpl( String key ) {
44 super( key );
45 factorName = "null";
46 mainEffectDof = Double.NaN;
47 mainEffectFStat = Double.NaN;
48 mainEffectPValue = Double.NaN;
49 residualDof = Double.NaN;
50 residualFStat = Double.NaN;
51 residualPValue = Double.NaN;
52 }
53
54
55
56
57 public OneWayAnovaResultImpl( String key, REXP rAnovaTable ) throws REXPMismatchException {
58 super( key );
59 this.factorName = rAnovaTable.getAttribute( "row.names" ).asStrings()[0];
60 RList list = rAnovaTable.asList();
61 this.mainEffectDof = list.at( "Df" ).asDoubles()[0];
62 this.mainEffectPValue = list.at( "Pr(>F)" ).asDoubles()[0];
63 this.mainEffectFStat = list.at( "F value" ).asDoubles()[0];
64 this.residualDof = list.at( "Df" ).asDoubles()[1];
65 this.residualFStat = list.at( "F value" ).asDoubles()[1];
66 this.residualPValue = list.at( "Pr(>F)" ).asDoubles()[1];
67 }
68
69 @Override
70 public String getFactorName() {
71 return factorName;
72 }
73
74 @Override
75 public double getMainEffectDof() {
76 return mainEffectDof;
77 }
78
79 @Override
80 public double getMainEffectFStat() {
81 return mainEffectFStat;
82 }
83
84 @Override
85 public double getMainEffectPValue() {
86 return mainEffectPValue;
87 }
88
89 @Override
90 public boolean hasResiduals() {
91 return true;
92 }
93
94 @Override
95 public double getResidualsDof() {
96 return residualDof;
97 }
98
99 @Override
100 public double getResidualsFStat() {
101 return residualFStat;
102 }
103
104 @Override
105 public double getResidualsPValue() {
106 return residualPValue;
107 }
108
109 @Override
110 public String toString() {
111 return String.format( "Factor\tDf\tF\tP\n%s\t%.2f\t%.2f\t%.3g\nResidual\t%.2f\t%.2f\t%.3g", factorName,
112 mainEffectDof, mainEffectFStat, mainEffectPValue,
113 residualDof, residualFStat, residualPValue );
114 }
115 }