Leah Schinasi
2014-Apr-04 13:49 UTC
[R] MICE, POST-PROCESSING imputations with two conditions
Dear R listserve,
I am writing with the hope or receiving assistance using the MICE package.My
troubles relate to post-processing imputations. I am attempting to impute
variables for which I want to specify two conditions using post-processing
imputation: 1) if the value of a variable representing the pesticide application
(PESTICIDE) is coded 0 to represent that the participant did not conduct task
then I want my duration of work in the task (DURR) and start year for the task
variables (START_DATE) to be coded as NA; 2) If the value of the variable
representing pesticide application task is coded 1 (did conduct task), then I
want my duration of work in the task and start year for the task to be imputed
using certain boundaries (restricting the values of the imputed date and
duration variables).
The two statements seem to work independently (post-processing statements are
recognized); however, I can't figure out how to combine them in one post
statement . Thus, I can't get my imputations to take the two conditions into
account; I can either restrict the variables to be set to missing if PESTICIDE
is 0, or I can get my imputations to be restricted to my specified boundaries,
but I can't get R to take both conditions into account simultaneously.
The following is the code that I am using. I am highlighting the two post
processing statements that I am having trouble with.:
ini<-mice(agrican.subb, print=FALSE, max=0)
pred<-ini$pred
pred["START_DATE",]<-1
pred["END_DATE",]<-0
pred[,"END_DATE"]<-0
pred[,"START_DATE"]<-0
pred[,"YEAR_BIRTH"]<-0
pred[,"year_ten"]<-0
pred[,"DIFF"]<-0
pred[,"ID"]<-0
pred[,"CORN"]<-0
method<-c(""," ", "", "",
"", "norm", "", "pmm", "",
"", "", "", "", "",
"norm")
post<-ini$post
post["START_DATE"]<-"imp[[j]][,i]<-squeeze(imp[[j]][,i],c(agrican.subb$YEAR_TEN,
agrican.subb$ENROLLMENT_YEAR))"
post["START_DATE"]<-"imp[[j]][p$data$PESTICIDE[!r[,j]]<1,i]<-NA"
post["DIFF"]<-"imp[[j]][,i]<-squeeze(imp[[j]][,i],c(0,
0))"
#post["DIFF"]<-"imp[[j]][p$data$PESTICIDE[!r[,j]]<1,i]<-NA"
imp<-mice(subb,post=post, pred=pred, seed=2332, method=method, maxit=3)
I will appreciate any advise that you can offer.
Thanks in advance!
Leah
Postdoctoral fellow
Section of Environment and Radiation
International Agency for Research on Cancer
150, cours Albert Thomas
69372 Lyon Cedex 08
France
schinasil@fellows.iarc.fr
Tel: [+33] (0)472 73 84 85
-----------------------------------------------------------------------
This message and its attachments are strictly confidenti...{{dropped:11}}