简体   繁体   中英

Multiple imputation using mice package

I'm not R user but I use R only to rum multiple imputation using mice package. Since I updated R from version 3.6.3 to version 4.0.4, I encountered problem with the imputed data when I call it from R to STATA. The problem is when I run a survival analysis all subjects were treated as died (status=1) while the status variable includes (alive and died). I would be grateful if you please check my R code. I have named the variables for this platform as var1, var2, var3, var4. This is my R script

library (MASS)
library (lattice)
library(splines)
library(survival)
library (Rcpp)
library (mice)

#reading data 
hla=read.dta("R:/mypath")

attach(dataname)
names(dataname)

#create data frame 
dataframe=data.frame(var1, var2, var3, var4, na) 

names(dataframe)

#generate automatic prediction matrix
predmatrix=quickpred(dataframe)
predmatrix

#ImputationSettings
maxIter=20
imputations=10

#Imputation settings
#set timer on
ptm=proc.time()      

imp10=mice(dataframe,m=imputations,maxit=maxIter,
method=c(
"",#var1
"pmm",#var2
"pmm",#var3
"logreg",#var4
""),#na

predictorMatrix=predmatrix,seed=100)

#extract original and imputed data in long form
ImputedData=complete(imp10,action="long",include=TRUE)
#export data to Stata file
write.dta(ImputedData,"R:/mypath/data.dta")```

The syntax is correct, the problem was when calling the imputed data from R to STATA. Recording and relabelling to some of the categorical variables are needed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM