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