1 #ifndef _TableOfReal_extensions_h_
2 #define _TableOfReal_extensions_h_
3 /* TableOfReal_extensions.h
4  *
5  * Copyright (C) 1993-2021 David Weenink
6  *
7  * This code is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or (at
10  * your option) any later version.
11  *
12  * This code is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this work. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #include "Categories.h"
22 #include "Collection.h"
23 #include "Graphics_extensions.h"
24 #include "Matrix_extensions.h"
25 #include "PatternList.h"
26 #include "Strings_.h"
27 #include "TableOfReal.h"
28 
29 void TableOfReal_to_PatternList_and_Categories(TableOfReal me, integer fromrow, integer torow, integer fromcol, integer tocol, autoPatternList *out_p, autoCategories *out_c);
30 
31 autoTableOfReal TableOfReal_transpose (TableOfReal me);
32 
33 autoStrings TableOfReal_extractRowLabels (TableOfReal me);
34 
35 autoStrings TableOfReal_extractColumnLabels (TableOfReal me);
36 
37 void TableOfReal_Categories_setRowLabels (TableOfReal me, Categories thee);
38 // !!! Set rowlabels from categories because we need a Table-object with string-columns.
39 
40 autoTableOfReal TableOfReal_sortOnlyByRowLabels (TableOfReal me);
41 
42 autoINTVEC TableOfReal_getSortedIndexFromRowLabels (TableOfReal me);
43 
44 autoTableOfReal TableOfReal_sortRowsByIndex (TableOfReal me, constINTVEC index, bool reverse);
45 // thy data [reverse ? i : index [i]] [j] = my data [reverse ? index [i] : i]
46 
47 autoTableOfReal TableOfReal_createIrisDataset ();
48 
49 autoTableOfReal TableOfReal_create_pols1973 (bool include_levels);
50 
51 autoTableOfReal TableOfReal_create_vanNierop1973 (bool include_levels);
52 
53 autoTableOfReal TableOfReal_create_weenink1983 (int option); /* M W C */
54 
55 /* The data for Fig. 2 in Sandwell (1987) */
56 autoTableOfReal TableOfReal_create_sandwell1987 ();
57 
58 void TableOfReal_getColumnExtrema (TableOfReal me, integer col, double *min, double *max);
59 
60 integer TableOfReal_getColumnIndexAtMaximumInRow (TableOfReal me, integer rowNumber);
61 
62 conststring32 TableOfReal_getColumnLabelAtMaximumInRow (TableOfReal me, integer rowNumber);
63 
64 void TableOfReal_drawRowsAsHistogram (TableOfReal me, Graphics g, constINTVECVU const& rowNumbers, integer colb, integer cole,
65 	double ymin, double ymax, double xoffsetFraction, double interbarFraction,
66 	double interbarsFraction, constVECVU const& greys, bool garnish
67 );
68 
69 void TableOfReal_drawScatterPlot (TableOfReal me, Graphics g, integer icx, integer icy, integer rowb,
70 	integer rowe, double xmin, double xmax, double ymin, double ymax,
71 	integer labelSize, bool useRowLabels, conststring32 label, bool garnish
72 );
73 
74 void TableOfReal_drawAsScalableSquares (TableOfReal me, Graphics g, integer rowmin, integer rowmax, integer colmin, integer colmax, kGraphicsMatrixOrigin origin, double cellSizeFactor, kGraphicsMatrixCellDrawingOrder fillOrder, bool garnish);
75 
76 void TableOfReal_drawScatterPlotMatrix (TableOfReal me, Graphics g, integer colb, integer cole, double fractionWhite);
77 
78 void TableOfReal_drawBoxPlots (TableOfReal me, Graphics g, integer rowmin, integer rowmax, integer colmin, integer colmax,
79 	double ymin, double ymax, bool garnish);
80 
81 void TableOfReal_drawVectors (TableOfReal me, Graphics g, integer colx1, integer coly1,
82 	integer colx2, integer coly2, double xmin, double xmax,
83 	double ymin, double ymax, int vectype, int labelsize, bool garnish);
84 
85 void TableOfReal_drawBiplot (TableOfReal me, Graphics g, double xmin, double xmax,
86 	double ymin, double ymax, double sv_splitfactor, int labelsize,
87 	bool garnish);
88 
89 void TableOfReal_drawColumnAsDistribution (TableOfReal me, Graphics g, integer column, double minimum, double maximum, integer nBins,
90 	double freqMin, double freqMax, bool cumulative, bool garnish);
91 
92 integer TableOfReal_getNumberOfLabelMatches (TableOfReal me, conststring32 search, bool columnLabels,
93 	bool use_regexp);
94 /*
95 	Find number of labels that match search description.
96 */
97 
98 void TableOfReal_copyLabels (TableOfReal me, TableOfReal thee, int rowOrigin, int columnOrigin);
99 /*
100 	rowOrigin ==  1 copy from row
101 	rowOrigin ==  0 do nothing
102 	rowOrigin == -1 copy from column
103 
104 	columnOrigin ==  1 copy from column
105 	columnOrigin ==  0 do nothing
106 	columnOrigin == -1 copy from row
107 */
108 
109 void TableOfReal_setLabelsFromCollectionItemNames (TableOfReal me, Collection thee, bool setRowLabels, bool setColumnLabels);
110 
111 void TableOfReal_setSequentialColumnLabels (TableOfReal me, integer from, integer to, conststring32 precursor, integer number, integer increment);
112 
113 void TableOfReal_setSequentialRowLabels (TableOfReal me, integer from, integer to, conststring32 precursor, integer number, integer increment);
114 
115 bool TableOfReal_hasRowLabels (TableOfReal me);
116 
117 bool TableOfReal_hasColumnLabels (TableOfReal me);
118 
119 void TableOfReal_changeRowLabels (TableOfReal me, conststring32 search, conststring32 replace,
120 	integer maximumNumberOfReplaces, integer *nmatches, integer *nstringmatches, bool use_regexp);
121 
122 void TableOfReal_changeColumnLabels (TableOfReal me, conststring32 search, conststring32 replace,
123 	integer maximumNumberOfReplaces, integer *nmatches, integer *nstringmatches, bool use_regexp);
124 /*
125 	Change all row/column labels. The 'search' and 'replace' string are
126 	interpreted as regular expressions when 'use_regexp' != 0.
127 	'maximumNumberOfReplaces' is the maximum number of replaces in EACH string
128 	in the array of strings (you can replace ALL occurrences by making this
129 	number <= 0)
130 	The totalnumber of matches found is returned in 'nmatches'.
131 	The number of strings with at least one match is returned in
132 	'nstringmatches'.
133 */
134 
135 void TableOfReal_centreColumns (TableOfReal me);
136 
137 void TableOfReal_centreColumns_byRowLabel (TableOfReal me);
138 /* PRECONDITION: Table should be sorted by row labels !! */
139 
140 double TableOfReal_getColumnQuantile (TableOfReal me, integer col, double quantile);
141 
142 double TableOfReal_getRowSumByLabel (TableOfReal me, conststring32 label);
143 
144 double TableOfReal_getRowSum (TableOfReal me, integer index);
145 
146 double TableOfReal_getColumnSumByLabel (TableOfReal me, conststring32 label);
147 
148 double TableOfReal_getColumnSum (TableOfReal me, integer index);
149 
150 double TableOfReal_getGrandSum (TableOfReal me);
151 
152 void TableOfReal_centreRows (TableOfReal me);
153 
154 void TableOfReal_doubleCentre (TableOfReal me);
155 
156 bool TableOfReal_isNonNegative (TableOfReal me);
157 
158 double TableOfReal_getTableNorm (TableOfReal me);
159 
160 void TableOfReal_normalizeTable (TableOfReal me, double norm);
161 
162 void TableOfReal_normalizeColumns (TableOfReal me, double norm);
163 
164 void TableOfReal_normalizeRows (TableOfReal me, double norm);
165 
166 void TableOfReal_standardizeColumns (TableOfReal me);
167 
168 void TableOfReal_standardizeRows (TableOfReal me);
169 
170 autoTableOfReal TableOfReal_rankColumns (TableOfReal me, integer fromColumn, integer toColumn);
171 
172 autoTableOfReal TableOfReal_meansByRowLabels (TableOfReal me, bool expand, bool useMedians);
173 /*
174 	stats == 0? averages : medians
175 	For a table with n rows and m different labels (m <= n):
176 	if (expand=1) { output has n rows, substitute each array by the average value for that row label}
177 	else output a table with m rows, the averages for the m labels.
178 */
179 
180 autoTableOfReal TableOfReal_bootstrap (TableOfReal me);
181 // Produce new table with the same number of entries, but randomly selected with replacement.
182 
183 autoTableOfReal TableOfReal_randomizeRows (TableOfReal me);
184 /* Produce new table with randomized rows */
185 
186 /* For the inheritors */
187 autoTableOfReal TableOfReal_to_TableOfReal (TableOfReal me);
188 
189 autoTableOfReal TableOfReal_choleskyDecomposition (TableOfReal me, bool upper, bool inverse);
190 
191 autoTableOfReal TableOfReal_appendColumns (TableOfReal me, TableOfReal thee);
192 
193 void TableOfReal_copyOneRowWithLabel (TableOfReal me, TableOfReal thee, integer myrow, integer thyrow);
194 
195 double TableOfReal_normalityTest_BHEP (TableOfReal me, double *h, double *out_tnb, double *out_lnmu, double *out_lnvar, bool *out_singularCovariance);
196 /*
197 	Henze & Wagner (1997), A new approach to the BHEP tests for multivariate normality, Journal of Multivariate Analysis 62, 1-23.
198 */
199 
200 double TableOfReal_testSphericityOfCovariance (TableOfReal me, integer numberOfPermutations, bool useCorrelation);
201 /*
202 	Sphericity test of covariance (correlation) matrix
203 	This test is a combinaation of two tests:
204 	1. H0: Sigma = sigma^2 I vs. H1: Sigma = diag (sigma[1]^2, sigma-2[^2, ... sigma[p]^2)
205 	2. H0: Sigma = diag (sigma[1]^2, sigma-2[^2, ... sigma[p]^2) vs. H1: Sigma != diag (sigma[1]^2, sigma-2[^2, ... sigma[p]^2)
206 	This is test 1 in:
207 	L. Wu, C. Weng, X. Wang, K. Wang & X. Liu (2018): Test of covariance and correlation matrices,
208 	arXiv: 1812.01172v1 [start.ME] 4 Dec 2018.
209 */
210 
211 double TableOfReal_testCovarianceEqualsIdentityMatrix (TableOfReal me, integer numberOfPermutations, bool useCorrelation);
212 /*
213 	Test if the covariance or correlation equals the identity matrix I.
214 	H0: Sigma = I vs H1: Sigma != I
215 	This is test2 in:
216 		L. Wu, C. Weng, X. Wang, K. Wang & X. Liu (2018): Test of covariance and correlation matrices,
217 		arXiv: 1812.01172v1 [start.ME] 4 Dec 2018.
218 */
219 
220 double TableOfReal_testCovarianceCompoundSymmetry (TableOfReal me, integer numberOfPermutations, bool useCorrelation);
221 /*
222 	H0: Sigma = sigma^2 (1-rho) * I + rho * J,
223 	where I is identity matrix and J is sqaure matrix of ones znd rho > 0 (intra-class correlation coefficient
224 	This is test3 in:
225 		L. Wu, C. Weng, X. Wang, K. Wang & X. Liu (2018): Test of covariance and correlation matrices,
226 		arXiv: 1812.01172v1 [start.ME] 4 Dec 2018.
227 
228 */
229 
230 double TableOfReal_testEqualityOfCovariances (TableOfReal me, TableOfReal thee, integer numberOfPermutations, bool useCorrelation);
231 /*
232 	Test the equality of two covariance or correlation matrices.
233 	H0: Sigma[1] = Sigma[2] vs H1: Sigma[1] != Sigma[2]
234 	This is test4 in:
235 		L. Wu, C. Weng, X. Wang, K. Wang & X. Liu (2018): Test of covariance and correlation matrices,
236 		arXiv: 1812.01172v1 [start.ME] 4 Dec 2018.
237 */
238 
239 autoTableOfReal TableOfReal_TableOfReal_crossCorrelations (TableOfReal me, TableOfReal thee, bool by_columns, bool center, bool normalize);
240 
241 
242 #pragma mark - class TableOfRealList
243 
244 autoTableOfReal TableOfRealList_sum (TableOfRealList me);
245 
246 bool TableOfRealList_haveIdenticalDimensions (TableOfRealList me);
247 
248 autoTableOfReal TableOfRealList_appendColumnsMany (TableOfRealList me);
249 
250 autoMatrix TableOfReal_to_Matrix_interpolateOnRectangularGrid (TableOfReal me, double xmin, double xmax, double nx, double ymin, double ymax, integer ny, int method);
251 
252 #endif /* _TableOfReal_extensions_h_ */
253