R: Creates artificial missing at random missingness
makemar
R Documentation
Creates artificial missing at random missingness
Description
Introduces missingness into x1 and x2 into a data.frame of the format produced by simdata,
for use in the simulation study.
The probability of missingness depends on the logistic of the fully observed variables y and x3;
hence it is missing at random but not missing completely at random.
Usage
makemar(simdata, prop = 0.2)
Arguments
simdata
simulated dataset created by simdata.
prop
proportion of missing values to be introduced in x1 and x2.
Details
This function is used for simulation and testing.
Value
A data.frame with columns:
y
dependent variable, based on the model y = x1 + x2 + x3 + normal error
x1
partially observed continuous variable
x2
partially observed continuous or binary (factor) variable
x3
fully observed continuous variable
x4
variable not in the model to predict y, but associated with x1, x2 and x3;
used as an auxiliary variable in imputation
See Also
simdata
Examples
set.seed(1)
mydata <- simdata(n=100)
mymardata <- makemar(mydata, prop=0.1)
# Count the number of missing values
sapply(mymardata, function(x){sum(is.na(x))})
# y x1 x2 x3 x4
# 0 11 10 0 0
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(CALIBERrfimpute)
Loading required package: mice
Loading required package: Rcpp
mice 2.25 2015-11-09
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/CALIBERrfimpute/makemar.Rd_%03d_medium.png", width=480, height=480)
> ### Name: makemar
> ### Title: Creates artificial missing at random missingness
> ### Aliases: makemar
>
> ### ** Examples
>
> set.seed(1)
> mydata <- simdata(n=100)
> mymardata <- makemar(mydata, prop=0.1)
> # Count the number of missing values
> sapply(mymardata, function(x){sum(is.na(x))})
y x1 x2 x3 x4
0 11 10 0 0
> # y x1 x2 x3 x4
> # 0 11 10 0 0
>
>
>
>
>
> dev.off()
null device
1
>