Skip to contents

This function inserts NA's to the provided matrix according to the MAR (Missing At Random) patterns.

Usage

insert_MAR(dat, ratio = 0, thresh = 0.2)

Arguments

dat

a matrix or data.frame of data to be filled with some NA's.

ratio

a number from 0 to 1 denoting the ratio of data to be exchanged into NA's

thresh

a value from 0 to 1: limit value indicating maximum ratio of missing observations in one column

Value

A matrix with NA values inserted.

Details

This function uses ampute. It firstly tries to ampute missing data by metabolites (columns) and if it fails, it switches to introduce missing values by samples (rows).

Examples

set.seed(1)
m <- as.data.frame(matrix(rnorm(10), 50, 5))
insert_MAR(m, ratio = 0.1)
#>            V1         V2         V3         V4         V5
#> 1  -0.6264538 -0.6264538 -0.6264538         NA -0.6264538
#> 2   0.1836433  0.1836433  0.1836433  0.1836433  0.1836433
#> 3  -0.8356286 -0.8356286         NA -0.8356286 -0.8356286
#> 4          NA         NA  1.5952808  1.5952808  1.5952808
#> 5   0.3295078  0.3295078  0.3295078  0.3295078  0.3295078
#> 6  -0.8204684 -0.8204684         NA -0.8204684 -0.8204684
#> 7   0.4874291  0.4874291  0.4874291  0.4874291  0.4874291
#> 8          NA  0.7383247  0.7383247  0.7383247  0.7383247
#> 9   0.5757814  0.5757814  0.5757814  0.5757814  0.5757814
#> 10 -0.3053884 -0.3053884 -0.3053884 -0.3053884 -0.3053884
#> 11 -0.6264538 -0.6264538 -0.6264538 -0.6264538 -0.6264538
#> 12  0.1836433  0.1836433  0.1836433  0.1836433  0.1836433
#> 13 -0.8356286 -0.8356286         NA -0.8356286 -0.8356286
#> 14         NA         NA  1.5952808  1.5952808  1.5952808
#> 15  0.3295078  0.3295078  0.3295078  0.3295078  0.3295078
#> 16 -0.8204684 -0.8204684 -0.8204684         NA -0.8204684
#> 17  0.4874291  0.4874291  0.4874291  0.4874291  0.4874291
#> 18         NA  0.7383247  0.7383247  0.7383247  0.7383247
#> 19  0.5757814  0.5757814  0.5757814  0.5757814  0.5757814
#> 20 -0.3053884 -0.3053884 -0.3053884 -0.3053884 -0.3053884
#> 21 -0.6264538 -0.6264538 -0.6264538 -0.6264538 -0.6264538
#> 22  0.1836433  0.1836433  0.1836433  0.1836433  0.1836433
#> 23 -0.8356286 -0.8356286         NA -0.8356286 -0.8356286
#> 24         NA         NA  1.5952808  1.5952808  1.5952808
#> 25  0.3295078  0.3295078  0.3295078  0.3295078  0.3295078
#> 26 -0.8204684 -0.8204684 -0.8204684         NA -0.8204684
#> 27  0.4874291  0.4874291  0.4874291  0.4874291  0.4874291
#> 28         NA  0.7383247  0.7383247  0.7383247  0.7383247
#> 29  0.5757814  0.5757814  0.5757814  0.5757814  0.5757814
#> 30 -0.3053884 -0.3053884 -0.3053884 -0.3053884 -0.3053884
#> 31 -0.6264538 -0.6264538 -0.6264538 -0.6264538 -0.6264538
#> 32  0.1836433  0.1836433  0.1836433  0.1836433  0.1836433
#> 33 -0.8356286 -0.8356286         NA -0.8356286 -0.8356286
#> 34         NA         NA  1.5952808  1.5952808  1.5952808
#> 35  0.3295078  0.3295078  0.3295078  0.3295078  0.3295078
#> 36 -0.8204684 -0.8204684 -0.8204684         NA -0.8204684
#> 37  0.4874291  0.4874291  0.4874291  0.4874291  0.4874291
#> 38         NA  0.7383247  0.7383247  0.7383247  0.7383247
#> 39  0.5757814  0.5757814  0.5757814  0.5757814  0.5757814
#> 40 -0.3053884 -0.3053884 -0.3053884 -0.3053884 -0.3053884
#> 41 -0.6264538 -0.6264538 -0.6264538 -0.6264538 -0.6264538
#> 42  0.1836433  0.1836433  0.1836433  0.1836433  0.1836433
#> 43 -0.8356286 -0.8356286         NA -0.8356286 -0.8356286
#> 44         NA  1.5952808  1.5952808  1.5952808  1.5952808
#> 45  0.3295078  0.3295078  0.3295078  0.3295078  0.3295078
#> 46 -0.8204684 -0.8204684 -0.8204684         NA -0.8204684
#> 47  0.4874291  0.4874291  0.4874291  0.4874291  0.4874291
#> 48         NA  0.7383247  0.7383247  0.7383247  0.7383247
#> 49  0.5757814  0.5757814  0.5757814  0.5757814  0.5757814
#> 50 -0.3053884 -0.3053884 -0.3053884 -0.3053884 -0.3053884