0
votes

I am trying to impute missing values using the Amelia R-package. My problem is, I'm trying to impute variables, for which the possible values are dependent upon other variables I'm trying to impute. For example: I'm trying to impute age at menopause but I'm also imputing wether a woman is post-menopausal or not. If a woman is pre-menopausal, the menopausal age is not applicable/always 888. (how) can I do this in R?

I found an example of a similar function in Stata: conditional(), on a Stata help page: http://www.stata.com/stata12/multiple-imputation/#conditional I don't have access to Stata, but it illustrates exactly what I would like to do. Help is much appreciated!

edit:

A different example, this time with data: If i want to impute both smoking status (1= never smoker, 2= former smoker, 3= current smoker) and the number of pack years (= average number of packs a day times years smoked), then I do not want amelia to impute pack years more than 0 for the people that are never smokers.. Example data:

structure(list(id = 1:20, smoking = c(NA, 1L, 1L, 1L, 2L, 3L, NA, 2L, 1L, 2L, NA, 2L, 2L, NA, 2L, 2L, NA, 3L, NA, NA), packyears = c(NA, 0, 0, 0, 20, 40, NA, 30, 0, 15, NA, 20, 25, NA, 10, 15, NA, 40, NA, NA)), .Names = c("id", "smoking", "packyears"), row.names = c(NA, -20L), class = "data.frame") 

Now I would run:

a.out<-amelia(df, m=5, idvars=c("id"), noms=c("smoking"))

But then Amelia might impute non-zero values for packyears in never smokers, which is impossible in real life.. I'm not sure whether this will be the result in this example data set, but impossible values did occur in my real dataset, where there are more covariates (see example above).

2

2 Answers

1
votes

Based on the documentation, it appears that you are interested in amelia() function. Could you use an ifelse() or similar conditional then call amelia()?

Could you please post some data or an example for a better response?

0
votes

You can use the bounds argument to amelia() in order to impose logical bounds on the imputation. This vignette explains it.