scale by mean of group mean for imbalanced data
scale_mgm(expr, label, pooled.sd = FALSE)
scaled matrix
$$z=\frac{x-\frac{\sum_k^{n_D}(\mu_k)}{n_D}}{s}$$
where \(\mu_k\) is the mean of x in \(k^{th}\) class, and \(n_D\) is
the number of classes, \(s\) is the standard deviation of x,
when pooled.sd
is set to be TRUE, \(s\) will be replaced with
\(s_{pooled}\), \(s_{pooled}=\sqrt{\frac{\sum_k^{n_D}{(n_k-1){s_k}^2}}{\sum_k^{n_D}{n_k}-k}}\)
scale_mgm(matrix(rnorm(100), 10), label = rep(letters[1:2], 5))
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] 1.3663405 -0.48931977 -1.85236500 -0.76886172 0.3519732 0.34014600
#> [2,] -1.4362591 0.10705079 -1.27230325 -0.10508879 0.1617974 -0.05551098
#> [3,] 1.8029909 -0.24758057 -0.72291766 -1.00474068 1.4289029 0.91628196
#> [4,] -0.3363015 -0.57255340 -1.16672747 1.64618577 -0.5550281 1.06857837
#> [5,] -0.7514267 1.38176894 0.59768145 0.01282032 -1.7143455 -0.06921118
#> [6,] -0.6186002 -1.08097161 0.88104355 0.37339532 1.5722245 -0.81134043
#> [7,] -0.1931922 0.20723301 -1.77164989 1.19180929 0.5108023 0.89790449
#> [8,] -1.6635465 0.07851664 0.36071611 -1.31759086 -0.5336866 0.02617118
#> [9,] -1.3586186 0.78454157 -0.07611186 0.42925552 0.6368621 0.66968423
#> [10,] -0.4562446 -0.89316913 -0.56846706 0.84605640 -0.8526870 0.51373285
#> [,7] [,8] [,9] [,10]
#> [1,] 0.16688339 1.26746795 -0.8709494 0.4886848
#> [2,] 0.85705454 -0.86281494 0.8604105 1.7456639
#> [3,] -0.71761698 -0.60983213 -0.5455922 -0.2998955
#> [4,] -0.48740329 0.67281640 0.9402539 -1.2098206
#> [5,] 0.06945184 0.12055556 -1.0773133 1.4300185
#> [6,] -1.40318651 -0.43420185 0.9704080 0.5512292
#> [7,] -0.56237404 -0.32236298 -1.1774943 1.2193243
#> [8,] 0.94103949 0.09706555 1.7662851 0.2450299
#> [9,] -0.48972522 -1.10859614 1.6517529 -1.1390445
#> [10,] -0.11652181 -1.27435578 0.9525378 1.8491183