Skip to contents

This function inserts NA's to the provided metabolomic matrix according to the MNAR (Missing Not At Random) mechanism.

Usage

insert_MNAR(dat, ratio = 0.1, 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

LOD missing data is simulated by sampling possible limit of detection (LOD) for each metabolite and truncates the observations below this values. Thus, each metabolite has different truncation threshold. However, all the removed data corresponds to the provided fraction.

Examples

set.seed(1)
m <- as.data.frame(matrix(rnorm(200), 10, 20))
insert_MNAR(m, ratio = 0.1)
#>            V1          V2          V3          V4         V5         V6
#> 1  -0.6264538  1.51178117  0.91897737  1.35867955 -0.1645236  0.3981059
#> 2   0.1836433  0.38984324  0.78213630 -0.10278773 -0.2533617 -0.6120264
#> 3          NA -0.62124058  0.07456498  0.38767161  0.6969634  0.3411197
#> 4   1.5952808 -2.21469989          NA -0.05380504  0.5566632         NA
#> 5   0.3295078  1.12493092  0.61982575          NA         NA  1.4330237
#> 6  -0.8204684 -0.04493361 -0.05612874          NA         NA  1.9803999
#> 7   0.4874291 -0.01619026 -0.15579551 -0.39428995  0.3645820 -0.3672215
#> 8   0.7383247  0.94383621          NA -0.05931340  0.7685329         NA
#> 9   0.5757814  0.82122120 -0.47815006  1.10002537 -0.1123462  0.5697196
#> 10 -0.3053884  0.59390132  0.41794156  0.76317575  0.8811077 -0.1350546
#>             V7           V8         V9        V10         V11        V12
#> 1   2.40161776  0.475509529 -0.5686687 -0.5425200 -0.62036668 -0.6357365
#> 2  -0.03924000 -0.709946431 -0.1351786  1.2078678  0.04211587 -0.4616447
#> 3   0.68973936  0.610726353  1.1780870  1.1604026          NA  1.4322822
#> 4   0.02800216 -0.934097632 -1.5235668  0.7002136  0.15802877         NA
#> 5  -0.74327321           NA  0.5939462  1.5868335          NA -0.2073807
#> 6   0.18879230  0.291446236  0.3329504  0.5584864  1.76728727 -0.3928079
#> 7  -1.80495863 -0.443291873  1.0630998         NA  0.71670748 -0.3199929
#> 8   1.46555486  0.001105352 -0.3041839 -0.5732654  0.91017423 -0.2791133
#> 9   0.15325334  0.074341324  0.3700188         NA  0.38418536  0.4941883
#> 10  2.17261167 -0.589520946  0.2670988 -0.4734006  1.68217608 -0.1773305
#>            V13         V14         V15         V16        V17         V18
#> 1  -0.50595746  0.06016044          NA  0.45018710  0.4251004  2.30797840
#> 2   1.34303883 -0.58889449  1.17658331 -0.01855983 -0.2386471  0.10580237
#> 3  -0.21457941  0.53149619 -1.66497244 -0.31806837  1.0584830  0.45699881
#> 4  -0.17955653 -1.51839408 -0.46353040 -0.92936215  0.8864227 -0.07715294
#> 5  -0.10019074  0.30655786 -1.11592011 -1.48746031 -0.6192430 -0.33400084
#> 6   0.71266631          NA -0.75081900 -1.07519230  2.2061025 -0.03472603
#> 7  -0.07356440 -0.30097613  2.08716655  1.00002880 -0.2550270  0.78763961
#> 8  -0.03763417 -0.52827990  0.01739562 -0.62126669 -1.4244947  2.07524501
#> 9           NA -0.65209478 -1.28630053 -1.38442685 -0.1443996  1.02739244
#> 10 -0.32427027 -0.05689678 -1.64060553  1.86929062  0.2075383  1.20790840
#>           V19        V20
#> 1  -1.2313234 -0.1771040
#> 2   0.9838956  0.4020118
#> 3   0.2199248 -0.7317482
#> 4          NA  0.8303732
#> 5   0.5210227         NA
#> 6  -0.1587546 -1.0479844
#> 7   1.4645873  1.4411577
#> 8  -0.7660820 -1.0158475
#> 9  -0.4302118  0.4119747
#> 10 -0.9261095 -0.3810761