Skip to contents

This function removes or masks the observed variables y of simulated data (an object of class simstatespace) to mimic a measurement schedule, attrition, and missing occasions. The latent variables eta stay complete (the truth).

Usage

SimMissing(
  x,
  keep = NULL,
  dropout = NULL,
  mar = NULL,
  prob = NULL,
  occasion = FALSE
)

Arguments

x

Object of class simstatespace.

keep

Optional integer vector of the occasions every person keeps, or a list of n such vectors, for example, attr(schedule, "index") from ScheduleBurst().

dropout

Optional number or numeric vector by occasion. Probability of leaving at each occasion (the first element of a vector is not used).

mar

Optional list with the elements a and b. With occasion = TRUE, a is a number and b a number or a vector of length k. Otherwise, a is a number or a vector of length k, and b is a number or a vector of length k (each variable on its own previous value) or a k by k matrix (row \(v\) for variable \(v\)).

prob

Optional number, numeric vector by occasion, or n by occasion matrix. Probability of missingness completely at random.

occasion

Logical. If occasion = TRUE, mar and prob mask whole occasions. If occasion = FALSE, they mask each variable independently.

Value

Returns x with the changed data and the element missing, a list with the call (call) and the proportion of missing values of y (rate).

Details

The mechanisms are applied in this order:

  1. keep: each person keeps the listed occasions; the other rows are removed, not masked, so the time column shows the schedule.

  2. dropout: from the second occasion on, a person leaves at occasion \(t\) with probability \(h_{t}\) (monotone attrition); y is missing from then on.

  3. mar: missing at random, given the previous observed values. With occasion = TRUE, occasion \(t\) is missing with probability \( \operatorname{logit}^{-1} \left( a + \mathbf{b}^{\prime} \mathbf{y}_{t - 1}^{\ast} \right) \); otherwise, variable \(v\) is missing with probability \( \operatorname{logit}^{-1} \left( a_{v} + \mathbf{b}_{v}^{\prime} \mathbf{y}_{t - 1}^{\ast} \right) \), where \(\mathbf{y}_{t - 1}^{\ast}\) holds the last observed value of each variable. The first occasion is not masked.

  4. prob: missing completely at random.

With occasion = TRUE, mar and prob mask whole occasions; otherwise, each variable is masked independently.

See also

Other Measurement Design Functions: ScheduleBurst(), ScheduleExp(), ScheduleRandom()

Author

Ivan Jacob Agaloos Pesigan

Examples

set.seed(42)
sim <- SimSSMVARFixed(
  n = 5,
  time = 50,
  mu0 = c(0, 0),
  sigma0_l = diag(2),
  alpha = c(0, 0),
  beta = 0.5 * diag(2),
  psi_l = diag(2)
)
# missing completely at random and attrition
miss <- SimMissing(x = sim, prob = 0.1, dropout = 0.01)
miss$missing$rate
#> [1] 0.288
# missing at random, on the previous values
miss <- SimMissing(
  x = sim,
  mar = list(a = -2, b = c(1, 0)),
  occasion = TRUE
)
head(as.data.frame(miss))
#>   id time         y1        y2
#> 1  1    0 -0.5315017 0.8212527
#> 2  1    1  1.9516988 0.7093611
#> 3  1    2         NA        NA
#> 4  1    3         NA        NA
#> 5  1    4         NA        NA
#> 6  1    5  0.3366242 1.1218288