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).
Arguments
- x
Object of class
simstatespace.- keep
Optional integer vector of the occasions every person keeps, or a list of
nsuch vectors, for example,attr(schedule, "index")fromScheduleBurst().- 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
aandb. Withoccasion = TRUE,ais a number andba number or a vector of lengthk. Otherwise,ais a number or a vector of lengthk, andbis a number or a vector of lengthk(each variable on its own previous value) or akbykmatrix (row \(v\) for variable \(v\)).- prob
Optional number, numeric vector by occasion, or
nby occasion matrix. Probability of missingness completely at random.- occasion
Logical. If
occasion = TRUE,marandprobmask whole occasions. Ifoccasion = 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:
keep: each person keeps the listed occasions; the other rows are removed, not masked, so thetimecolumn shows the schedule.dropout: from the second occasion on, a person leaves at occasion \(t\) with probability \(h_{t}\) (monotone attrition);yis missing from then on.mar: missing at random, given the previous observed values. Withoccasion = 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.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()
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