How can I simulate a dataset with a missing not at Random situation in R? I have a dataset with two categorical variables that are missing at random, so I want to create a simulation study with missing not at random in R. I want to compare the results afterwards.
 A: There's of course many different missing not at random scenarios. Here are two that are easy to simulate and have some practical relevance:

*

*A simple to simulate one is to set the outcome to missing depending on the outcome that becomes missing. I.e. the probability of missingness is determined by (and varies according to) the true outcome value. The probability could also vary based on other covariates. A variant is to have some unobserved latent variable that correlates with covariates, the outcome of interest and the missingness probability.

*A common scenario in (randomised) clinical trials that compare a treatment with a placebo is that when patients stop taking their intervention a) will often (on the past this was even often an automatic rule) stop trial participation and b) different things happen to patients in each group thereafter. In the placebo group not much might change compared to patients that remain in the trial (although if patients quit due to poor intermediate outcomes, there might be some regression to the mean). In the treatment group, the treatment effect will usually disappear (for some drugs almost immediately and for some gradually), or there might even be a rebound effect. If you are interested in a treatment policy estimand, you want to impute those unobserved off-treatment values, which a standard imputation under MAR does not do.

