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.80299093 -0.24758057 -0.72291766 -1.00474068 1.4289029 0.91628196
#> [2,] -0.33630149 -0.57255340 -1.16672747 1.64618577 -0.5550281 1.06857837
#> [3,] -0.75142665 1.38176894 0.59768145 0.01282032 -1.7143455 -0.06921118
#> [4,] -0.61860022 -1.08097161 0.88104355 0.37339532 1.5722245 -0.81134043
#> [5,] -0.19319224 0.20723301 -1.77164989 1.19180929 0.5108023 0.89790449
#> [6,] -1.66354653 0.07851664 0.36071611 -1.31759086 -0.5336866 0.02617118
#> [7,] -1.35861864 0.78454157 -0.07611186 0.42925552 0.6368621 0.66968423
#> [8,] -0.45624456 -0.89316913 -0.56846706 0.84605640 -0.8526870 0.51373285
#> [9,] -0.29494374 -1.80083887 -0.60378225 0.63451847 0.6214517 0.43003084
#> [10,] 0.03778445 -1.48489673 -0.19639831 0.09821971 -0.1416689 0.86572026
#> [,7] [,8] [,9] [,10]
#> [1,] -0.71761698 -0.60983213 -0.5455922 -0.2998955
#> [2,] -0.48740329 0.67281640 0.9402539 -1.2098206
#> [3,] 0.06945184 0.12055556 -1.0773133 1.4300185
#> [4,] -1.40318651 -0.43420185 0.9704080 0.5512292
#> [5,] -0.56237404 -0.32236298 -1.1774943 1.2193243
#> [6,] 0.94103949 0.09706555 1.7662851 0.2450299
#> [7,] -0.48972522 -1.10859614 1.6517529 -1.1390445
#> [8,] -0.11652181 -1.27435578 0.9525378 1.8491183
#> [9,] 1.64595889 -0.71656891 0.7855577 -0.7013839
#> [10,] -1.03285894 0.86942493 1.8466640 -0.8619904