Description
R function time1(x, m) and timex(x, inacol, nacol, m) return the imputed data based on propensity score and beta distribution (see details in reference paper). This multiple imputation is to impute the missing values according to time series and the later imputed values are dependent on the prior imputed data, which is different from R package "MICE" and SAS PROCE MI where the imputation is performed based on regression models.Usage
time1(x, m)
timex(x, inacol, nacol, m)
Arguments
x data frame of longtitudinal binary data to imputem number of replicates
inacol a list of the column numbers/names before timex without NAs
nacol the number of time before time x, for example total times is 5, to impute the time 3, nacol=2.
Examples
Copy the full R code from HERE or run the following scripts in R Gui:Download the function code on Mac:
download.file("https://raw.github.com/devilszhang/blog/master/timex.r", destfile="./timex.r", method="curl")
Download the function code on Windows:
download.file("https://raw.github.com/devilszhang/blog/master/timex.r", destfile="./timex.r")
Source the code:
source("./timex.r")
Access the demo data from HERE or using:
require(RCurl)
x<-read.table(textConnection(getURL("https://raw.github.com/devilszhang/blog/master/longdata.txt")), header=T)
x<-read.table(textConnection(getURL("https://raw.github.com/devilszhang/blog/master/longdata.txt")), header=T)
#Impute day0
x$t1imp<-time1(polio52, 5)#Impute day4
x$t1imp<-time1(polio52, 5)#Impute day4
inacol<-c("t1imp")
nacol<-c("day4")
x$t2imp<-timex(x, inacol, nacol, 1) #Impute day11
nacol<-c("day4")
x$t2imp<-timex(x, inacol, nacol, 1) #Impute day11
inacol<-c("t1imp", "t2imp")
nacol<-c("day11")
x$t3imp<-timex(x, inacol, nacol, 2) #Impute day18
nacol<-c("day11")
x$t3imp<-timex(x, inacol, nacol, 2) #Impute day18
inacol<-c("t1imp", "t2imp", "t3imp")
nacol<-c("day18")
x$t4imp<-timex(x, inacol, nacol, 3) #Impute day25
nacol<-c("day18")
x$t4imp<-timex(x, inacol, nacol, 3) #Impute day25
inacol<-c("t1imp", "t2imp", "t3imp", "t4imp")
nacol<-c("day25")
x$t5imp<-timex(x, inacol, nacol, 4)
#complete data
complx<-x[, c("t1imp", "t2imp", "t3imp", "t4imp", "t5imp")]
complx
nacol<-c("day25")
x$t5imp<-timex(x, inacol, nacol, 4)
#complete data
complx<-x[, c("t1imp", "t2imp", "t3imp", "t4imp", "t5imp")]
complx