Add single row to definitions table for missing data

defMiss(
  dtDefs = NULL,
  varname,
  formula,
  logit.link = FALSE,
  baseline = FALSE,
  monotonic = FALSE
)

Arguments

dtDefs

Definition data.table to be modified

varname

Name of variable with missingness

formula

Formula to describe pattern of missingness

Indicator set to TRUE when the probability of missingness is based on a logit model.

baseline

Indicator is set to TRUE if the variable is a baseline measure and should be missing throughout an entire observation period. This is applicable to repeated measures/longitudinal data.

monotonic

Indicator set to TRUE if missingness at time t is followed by missingness at all follow-up times > t.

Value

A data.table named dtName that is an updated data definitions table

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
#>     <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(dtName = dtAct, missDefs = defM, idvars = "id")
missMat
#> Key: <id>
#>          id    x1    x2    x3     u     m
#>       <int> <int> <int> <int> <int> <num>
#>    1:     1     0     0     1     1     0
#>    2:     2     1     0     0     1     0
#>    3:     3     0     0     0     1     0
#>    4:     4     0     0     0     1     0
#>    5:     5     0     0     1     1     0
#>   ---                                    
#>  996:   996     0     0     0     1     0
#>  997:   997     1     1     0     1     0
#>  998:   998     0     1     0     1     0
#>  999:   999     1     0     0     1     0
#> 1000:  1000     1     0     0     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 21.820790 20.43769558        NA
#>    2:     2     1    NA        NA 41.30834431 41.063218
#>    3:     3     1    NA 19.800832 21.14481614 17.695432
#>    4:     4     0    NA  2.048093  0.03823499 -2.655493
#>    5:     5     0    NA 18.781027 19.19143369        NA
#>   ---                                                  
#>  996:   996     0    NA 20.459640 18.98130419 19.944863
#>  997:   997     1    NA        NA          NA 40.116043
#>  998:   998     1    NA 40.320403          NA 40.856016
#>  999:   999     0    NA        NA 20.27016776 19.921736
#> 1000:  1000     0    NA        NA 18.40629184 21.432758