Rescale all columns of a matrix

clamp(.data)

clamp_robust(.data)

clamp_sd(.data, sd = 1)

clamp_standardize(.data, sd = 1)

Arguments

.data

A numeric matrix

sd

the value of each columns standard deviation (default is 1)

Value

A matrix with the same dimension as .data where each column has been rescaled.

Details

These functions are used internally by the tour to rescale all columns of .data.

  • clamp() rescales so all values for each column lie in the unit interval

  • clamp_robust() rescales by first centering by the median and then scaling by the median absolute deviation.

  • clamp_sd() rescales all columns to have a fixed standard deviation.

  • clamp_standardize() rescales all columns to have zero mean and unit variance.

Examples

mv <- matrix(rnorm(30), ncol = 3)

clamp(mv)
#>            [,1]       [,2]       [,3]
#>  [1,] 0.2892677 0.33332484 0.58236096
#>  [2,] 0.7509271 0.63441203 0.55142709
#>  [3,] 0.0000000 1.00000000 0.06111789
#>  [4,] 0.6781686 0.05906821 0.66164043
#>  [5,] 0.8530656 0.60473942 1.00000000
#>  [6,] 1.0000000 0.00000000 0.41605241
#>  [7,] 0.1716402 0.34139169 0.16952910
#>  [8,] 0.6107464 0.46089430 0.44001509
#>  [9,] 0.6116181 0.61252178 0.20159657
#> [10,] 0.6008793 0.24158042 0.00000000

clamp_robust(mv)
#>               [,1]       [,2]        [,3]
#>  [1,] -1.137905487 -0.2204600  0.45253198
#>  [2,]  0.493970786  0.7582998  0.36182491
#>  [3,] -2.160410729  1.9467357 -1.07590332
#>  [4,]  0.236783619 -1.1120003  0.68500228
#>  [5,]  0.855010733  0.6618415  1.67717030
#>  [6,]  1.374395167 -1.3040164 -0.03513275
#>  [7,] -1.553695998 -0.1942367 -0.75801032
#>  [8,] -0.001540676  0.1942367  0.03513275
#>  [9,]  0.001540676  0.6871400 -0.66397924
#> [10,] -0.036418891 -0.5186984 -1.25511863

clamp_sd(mv)
#>               [,1]        [,2]        [,3]
#>  [1,] -1.252655193 -0.47084067  0.44710615
#>  [2,]  0.228438781  0.53485761  0.34663293
#>  [3,] -2.180682874  1.75600287 -1.24589114
#>  [4,] -0.004984775 -1.38691891  0.70460583
#>  [5,]  0.556119317  0.43574448  1.80359756
#>  [6,]  1.027513606 -1.58421990 -0.09306396
#>  [7,] -1.630027443 -0.44389560 -0.89377157
#>  [8,] -0.221288353 -0.04473026 -0.01523318
#>  [9,] -0.218491713  0.46173929 -0.78961644
#> [10,] -0.252943887 -0.77728749 -1.44440202

clamp_standardize(mv)
#>             [,1]       [,2]        [,3]
#>  [1,] -0.8577549 -0.3188858  0.56510974
#>  [2,]  0.6233390  0.6868125  0.46463652
#>  [3,] -1.7857826  1.9079577 -1.12788756
#>  [4,]  0.3899155 -1.2349640  0.82260941
#>  [5,]  0.9510196  0.5876993  1.92160115
#>  [6,]  1.4224139 -1.4322650  0.02493962
#>  [7,] -1.2351272 -0.2919407 -0.77576798
#>  [8,]  0.1736119  0.1072246  0.10277040
#>  [9,]  0.1764085  0.6136942 -0.67161286
#> [10,]  0.1419564 -0.6253326 -1.32639843