Skip to contents

Transform a complete case dataset according to the MAR mechanism.The MAR mechanism assumes that the probability of missingness in a variable depends on the observed data but not on the missing data itself. This function introduces missing values in selected features of a dataset, with the missing values determined by the values of the causative (target) feature.

Usage

mar.transform(input, target, features, na_rate)

Arguments

input

data to transform using MAR mechanism

target

variable to be used as causative feature

features

variables to which NA values are introduced using a causative feature

na_rate

proportion of missing values to be added to data

Value

a matrix or data frame containing NAs

Examples

set.seed(123)
data <- gen.mcar(100,rho = c(.15,.25,.12,.45,.34,.54),sigma = c(1,2,1,2),n_vars = 4, na_prob = 0)

mar_data <-mar.transform(data,"V1",c("V2","V3"), na_rate = .25)
#> Warning: One or more features are at risk of being entirely NA.
summary(mar_data)
#>        V1                 V2                 V3                 V4          
#>  Min.   :-2.30917   Min.   :-3.81356   Min.   :-1.72154   Min.   :-4.58910  
#>  1st Qu.:-0.49385   1st Qu.:-1.29734   1st Qu.:-0.44964   1st Qu.:-1.23381  
#>  Median : 0.06176   Median :-0.04843   Median : 0.03793   Median : 0.09614  
#>  Mean   : 0.09041   Mean   :-0.07917   Mean   : 0.19091   Mean   : 0.06959  
#>  3rd Qu.: 0.69182   3rd Qu.: 1.07806   3rd Qu.: 0.61703   3rd Qu.: 1.48147  
#>  Max.   : 2.18733   Max.   : 4.38669   Max.   : 2.39781   Max.   : 4.32329  
#>                     NA's   :38         NA's   :38