[R] Generate missing data patterns

Coen van Hasselt coenvanhasselt at gmail.com
Wed Dec 2 19:14:01 CET 2009


Hi Andreas,

> ## does not exactly what i want, because i get rows
> ## of missinges pattern which are not in R
> X[rbinom(100,1,p[1])==1,R[1,]==1] <- NA
> X[rbinom(100,1,p[2])==1,R[2,]==1] <- NA
> X[rbinom(100,1,p[3])==1,R[3,]==1] <- NA
> X[rbinom(100,1,p[4])==1,R[4,]==1] <- NA

If you run these lines directly after each other,  the same rows can
be selected multiple times and result in combined missingness
patterns. At least the propabilities for missingness you defined will
be different, because for instance 111 can also be created by a
combination of two other patterns.

> Another question is what to to if want the missing pattern R and simulate a
> certain amount of missingnes mybe about 10 %?

Maybe have a look at sample()?

Coen




More information about the R-help mailing list