# ma.scale2: Standardization of a Matrix In miceadds: Some Additional Multiple Imputation Functions, Especially for 'mice'

## Description

This function performs a z-standardization for a numeric matrix. Note that in a case of a zero standard deviation all matrix entries are divided by a small number such that no `NaN`s occur.

## Usage

 `1` ```ma.scale2(x, missings=FALSE) ```

## Arguments

 `x` A numeric matrix in which missing values are permitted `missings` A logical indicating whether missings occur (or could occur) in the dataset

A matrix

## Author(s)

Alexander Robitzsch

`base::scale`
 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51``` ```############################################################################# # EXAMPLE 1: z-standardization data.internet ############################################################################# data(data.internet) dat <- data.internet # z-standardize all variables in this dataset zdat <- miceadds::ma.scale2( dat , missings=TRUE ) ## Not run: ############################################################################# # SIMULATED EXAMPLE 2: Speed comparison for many cases and many variables ############################################################################# set.seed(9786) # 3000 cases, 200 variables N <- 3000 p <- 200 # simulate some data x <- matrix( stats::rnorm( N*p ) , N , p ) x <- round( x , 2 ) # compare computation times for 10 replications B <- 10 s1 <- Sys.time() # scale in R for (bb in 1:B){ res <- scale(x) } ; s2 <- Sys.time() ; d1 <- s2-s1 s1 <- Sys.time() # scale in miceadds for (bb in 1:B){ res1 <- miceadds::ma.scale2(x) } ; s2 <- Sys.time() ; d2 <- s2-s1 # scale in miceadds with missing handling s1 <- Sys.time() for (bb in 1:B){ res1 <- miceadds::ma.scale2(x,missings=TRUE) } ; s2 <- Sys.time() ; d3 <- s2-s1 d1 # scale in R d2 # scale in miceadds (no missing handling) d3 # scale in miceadds (with missing handling) ## > d1 # scale in R ## Time difference of 1.622431 secs ## > d2 # scale in miceadds (no missing handling) ## Time difference of 0.156003 secs ## > d3 # scale in miceadds (with missing handling) ## Time difference of 0.2028039 secs ## End(Not run) ```