Generate missing data
genMiss(
dtName,
missDefs,
idvars,
repeated = FALSE,
periodvar = "period",
envir = parent.frame()
)
Missing data matrix indexed by idvars (and period if relevant)
def1 <- defData(varname = "m", dist = "binary", formula = .5)
def1 <- defData(def1, "u", dist = "binary", formula = .5)
def1 <- defData(def1, "x1", dist = "normal", formula = "20*m + 20*u", variance = 2)
def1 <- defData(def1, "x2", dist = "normal", formula = "20*m + 20*u", variance = 2)
def1 <- defData(def1, "x3", dist = "normal", formula = "20*m + 20*u", variance = 2)
dtAct <- genData(1000, def1)
defM <- defMiss(varname = "x1", formula = .15, logit.link = FALSE)
defM <- defMiss(defM, varname = "x2", formula = ".05 + m * 0.25", logit.link = FALSE)
defM <- defMiss(defM, varname = "x3", formula = ".05 + u * 0.25", logit.link = FALSE)
defM <- defMiss(defM, varname = "u", formula = 1, logit.link = FALSE) # not observed
defM
#> varname formula logit.link baseline monotonic
#> <char> <char> <lgcl> <lgcl> <lgcl>
#> 1: x1 0.15 FALSE FALSE FALSE
#> 2: x2 .05 + m * 0.25 FALSE FALSE FALSE
#> 3: x3 .05 + u * 0.25 FALSE FALSE FALSE
#> 4: u 1 FALSE FALSE FALSE
# Generate missing data matrix
missMat <- genMiss(dtAct, defM, idvars = "id")
missMat
#> Key: <id>
#> id x1 x2 x3 u m
#> <int> <int> <int> <int> <int> <num>
#> 1: 1 0 0 0 1 0
#> 2: 2 0 0 0 1 0
#> 3: 3 1 0 0 1 0
#> 4: 4 0 0 0 1 0
#> 5: 5 0 0 0 1 0
#> ---
#> 996: 996 0 0 1 1 0
#> 997: 997 0 0 0 1 0
#> 998: 998 0 0 0 1 0
#> 999: 999 0 0 0 1 0
#> 1000: 1000 0 0 1 1 0
# Generate observed data from actual data and missing data matrix
dtObs <- genObs(dtAct, missMat, idvars = "id")
dtObs
#> Key: <id>
#> id m u x1 x2 x3
#> <int> <int> <int> <num> <num> <num>
#> 1: 1 0 NA -2.250859 0.9351444 0.4240502
#> 2: 2 0 NA 1.254368 1.1885831 0.8909210
#> 3: 3 1 NA NA 19.7829796 20.1291439
#> 4: 4 0 NA -1.678498 -1.2700800 -1.0723500
#> 5: 5 0 NA -1.981356 1.1946704 1.1647107
#> ---
#> 996: 996 1 NA 39.605641 40.0627717 NA
#> 997: 997 0 NA -1.350135 1.1546430 -0.2701091
#> 998: 998 0 NA 17.800273 21.5847249 18.0452866
#> 999: 999 1 NA 19.993959 19.7405706 19.6181556
#> 1000: 1000 1 NA 41.717430 37.5900058 NA