This function adds (or modifies) a "MISSING" flag to a dataset to simulate a missing completely at random behaviour.
Usage
createMCAR(
data,
prop = 0,
rule,
seed = .deriveFromMasterSeed(),
flagName = getEctdColName("Missing")
)
Arguments
- data
(Required) Data frame to which to add missingness
- prop
(Optional) proportion of missingness between 0 and 1. The default is "0" (so no missingness is generated)
- rule
(Optional) Only observations matching the rule can be flagged as missing. Be default, all observations are available to be missing
- seed
(Optional) Random seed to use. Based on the current random seed by default
- flagName
(Optional) name of the missing flag ("MISSING" by default)
Details
The missing data is either added to the dataset or modified if it already exist. In the latter case, the function only overwrites data that is not already missing.
See also
createDropout
for drop out missingness.
parseRangeCode
to handle the rule
argument.
Author
Mike K Smith mstoolkit@googlemail.com
Examples
myData <- data.frame(
SUBJ = rep(1:3, each = 3),
TIME = rep(0:2, 3) )
createMCAR( myData, prop = 0.1, rule = "TIME > 0")
#> SUBJ TIME MISSING
#> 1 1 0 0
#> 2 1 1 0
#> 3 1 2 0
#> 4 2 0 0
#> 5 2 1 0
#> 6 2 2 0
#> 7 3 0 0
#> 8 3 1 0
#> 9 3 2 0
if (FALSE) {
## more examples in the unit tests
file.show( system.file( "Runit", "runit.data.missing.R" , package = "MSToolkit") )
}