Transform a complete case dataset according to the MCAR mechanism.The MCAR
mechanism assumes that the probability of missingness is the same for all cases,
and therefore,the missing data are not related to the observed data. transform.mcar
uses the binomial distribution to generate NA an index of possible NA values that will
replace a percentage of data points in the input.
Examples
set.seed(123)
data <- data.frame(x1 = stats::rnorm(100),x2 = stats::rnorm(100),y = stats::rnorm(100))
mcar_data <- mcar.transform(data,na_prob = .25)
#> Warning: One or more columns are at risk of being entirely NA.
summary(mcar_data)
#> x1 x2 y
#> Min. :-2.3092 Min. :-2.05325 Min. :-1.75653
#> 1st Qu.:-0.5234 1st Qu.:-0.80506 1st Qu.:-0.57397
#> Median : 0.1239 Median :-0.06344 Median : 0.02098
#> Mean : 0.1477 Mean :-0.06648 Mean : 0.09745
#> 3rd Qu.: 0.8580 3rd Qu.: 0.53030 3rd Qu.: 0.63075
#> Max. : 2.1873 Max. : 3.24104 Max. : 2.29308
#> NA's :29 NA's :24 NA's :19