2323var isPositiveInteger = require ( '@stdlib/assert/is-positive-integer' ) ;
2424var hasOwnProp = require ( '@stdlib/assert/has-own-property' ) ;
2525var roundn = require ( '@stdlib/math/base/special/roundn' ) ;
26+ var repeat = require ( '@stdlib/string/repeat' ) ;
27+ var max = require ( '@stdlib/math/base/special/max' ) ;
2628var isBoolean = require ( '@stdlib/assert/is-boolean' ) ;
2729
2830
31+ // FUNCTIONS //
32+
33+ /**
34+ * Returns n spaces.
35+ *
36+ * @private
37+ * @param {integer } n - number of spaces
38+ * @returns {string } n spaces
39+ */
40+ function spaces ( n ) {
41+ if ( n <= 0 ) {
42+ return '' ;
43+ }
44+ return repeat ( ' ' , n ) ;
45+ }
46+
47+
2948// MAIN //
3049
3150/**
@@ -49,6 +68,13 @@ function prettyPrint( results ) {
4968 */
5069 function print ( opts ) {
5170 var decision ;
71+ var treatMSS ;
72+ var treatSS ;
73+ var errMSS ;
74+ var extra1 ;
75+ var extra2 ;
76+ var errSS ;
77+ var ndgts ;
5278 var dgts ;
5379 var str ;
5480
@@ -68,7 +94,7 @@ function prettyPrint( results ) {
6894 decision = opts . decision ;
6995 }
7096 }
71- dgts = - dgts ;
97+ ndgts = - dgts ;
7298
7399 str = '' ;
74100 str += results . method ;
@@ -80,52 +106,61 @@ function prettyPrint( results ) {
80106 str += 'Alternate Hypothesis: At Least one Mean not Equal' ;
81107 str += '\n\n' ;
82108
109+ treatSS = roundn ( results . treatment . ss , ndgts ) . toString ( ) ;
110+ errSS = roundn ( results . error . ss , ndgts ) . toString ( ) ;
111+ treatMSS = roundn ( results . treatment . mss , ndgts ) . toString ( ) ;
112+ errMSS = roundn ( results . error . mss , ndgts ) . toString ( ) ;
113+
114+ extra1 = max ( max ( treatSS . length , errSS . length ) , 2 ) ;
115+ extra2 = max ( max ( treatMSS . length , errMSS . length ) , 3 ) ;
116+
83117 // Formatted table
84- str += '\t\t ' ;
118+ str += ' ' ;
85119 str += 'df' ;
86- str += '\t' ;
87- str += 'Sum Squares ' ;
88- str += '\t' ;
89- str += 'Mean Sum Sq. ' ;
90- str += '\t' ;
120+ str += spaces ( 3 ) ;
121+ str += 'SS ' ;
122+ str += spaces ( 2 + extra1 ) ;
123+ str += 'MSS ' ;
124+ str += spaces ( extra2 ) ;
91125 str += 'F Score' ;
92- str += '\t' ;
126+ str += spaces ( dgts - 1 ) ;
93127 str += 'P Value' ;
94128 str += '\n' ;
95129
96130 // Now start adding in values
97131 str += 'Treatment' ;
98- str += '\t' ;
132+ str += spaces ( 5 ) ;
99133 str += results . treatment . df ;
100- str += '\t' ;
101- str += roundn ( results . treatment . ss , dgts ) ;
102- str += '\t\t' ;
103- str += roundn ( results . treatment . mss , dgts ) ;
104- str += '\t\t' ;
105- str += roundn ( results . statistic , dgts ) ;
106- str += '\t' ;
107- str += roundn ( results . pValue , dgts ) ;
134+ str += spaces ( 4 ) ;
135+
136+ str += treatSS ;
137+ str += spaces ( 4 + extra1 - treatSS . length ) ;
138+ str += treatMSS ;
139+ str += spaces ( 3 + extra2 - treatMSS . length ) ;
140+ str += roundn ( results . statistic , ndgts ) ;
141+ str += spaces ( dgts ) ;
142+ str += roundn ( results . pValue , ndgts ) ;
108143 str += '\n' ;
109144
110145 // Next line
111146 str += 'Errors' ;
112- str += '\t\t ' ;
147+ str += ' ' ;
113148 str += results . error . df ;
114- str += '\t' ;
115- str += roundn ( results . error . ss , dgts ) ;
116- str += '\t\t' ;
117- str += roundn ( results . error . mss , dgts ) ;
149+ str += spaces ( dgts ) ;
150+ str += errSS ;
151+ str += spaces ( 4 + extra1 - errSS . length ) ;
152+ str += errMSS ;
118153
119154 if ( decision ) {
120155 str += '\n\n' ;
121156 if ( results . rejected ) {
122157 str += 'Reject Null: ' ;
123- str += roundn ( results . pValue , dgts ) ;
158+ str += roundn ( results . pValue , ndgts ) ;
124159 str += ' <= ' ;
125160 str += results . alpha ;
126161 } else {
127162 str += 'Fail to Reject Null: ' ;
128- str += roundn ( results . pValue , dgts ) ;
163+ str += roundn ( results . pValue , ndgts ) ;
129164 str += ' >= ' ;
130165 str += results . alpha ;
131166 }
0 commit comments