Create an observed data set that includes missing data

genObs(dtName, dtMiss, idvars)

Arguments

dtName

Name of complete data set

dtMiss

Name of missing data matrix

idvars

Index variables that cannot be missing

Value

A data table that represents observed data, including missing data

See also

Examples

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 #> 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
#> id x1 x2 x3 u m #> 1: 1 1 0 0 1 0 #> 2: 2 0 0 0 1 0 #> 3: 3 0 0 0 1 0 #> 4: 4 1 0 0 1 0 #> 5: 5 0 1 0 1 0 #> --- #> 996: 996 0 1 0 1 0 #> 997: 997 0 1 1 1 0 #> 998: 998 1 0 0 1 0 #> 999: 999 0 0 0 1 0 #> 1000: 1000 0 1 0 1 0
# Generate observed data from actual data and missing data matrix dtObs <- genObs(dtAct, missMat, idvars = "id") dtObs
#> id m u x1 x2 x3 #> 1: 1 1 NA NA 21.2886294 18.900350 #> 2: 2 1 NA 22.641531 20.9883677 23.041397 #> 3: 3 1 NA 39.298018 40.4673572 41.135329 #> 4: 4 1 NA NA 19.6008298 19.188551 #> 5: 5 1 NA 41.304851 NA 39.279532 #> --- #> 996: 996 1 NA 20.956998 NA 19.156316 #> 997: 997 1 NA 39.511118 NA NA #> 998: 998 0 NA NA -0.2668746 1.483042 #> 999: 999 1 NA 40.595105 42.1371482 40.038236 #> 1000: 1000 0 NA 2.429684 NA 0.716800