multiple imputation and bootstrapping code didn't work

Dears I am trying to do imputation however the code didn't work regardless that when I run the same code for the Tutorial it worked , don't know what the problem is

<- for(i in 1:70){imputeEQ5DQALYmean <- imputeEQ5DQALYmean + complete(imputeQALYEQ, i)}

# Error in, complete(imputeQALYEQ, i)) : ‘+’ only defined for equally-sized data frames
and in other runs it gave me the following comment 
# In Ops.factor(left, right) : ‘+’ not meaningful for factors

I think theres insufficient information to help you , aside from reading back to you the error messages.
Can you provide the tutorial you are basing your work on ?

ITS about how to do deal with missing data is that what you needed to know?

I'm trying not to pepper you with questions, it would be easier to read the tutorial you read, I would have thought.

Hope this will help

data2 <- read.csv("Tutorial5_MIQuestion2.csv")
View(data2) # open up data viewer to check dataset looks reasonable

data2 <- Tutorial5_MIQuestion2

#generate QALYS
data2$qol_0mth <- 0
data2$QALY <- ((0.25*(data2$qol_3mth+data2$qol_0mth))+(0.25*(data2$qol_6mth+data2$qol_3mth))+(0.5*(data2$qol_12mth+data2$qol_6mth))+(1*(data2$qol_24mth+data2$qol_12mth)))/2

# install.packages("mice") # Install package. Only need to do this once on your machine
library(mice) # load package (needs to be done for every new R session)
md.pattern(data2) # use the md.pattern function in the mice library to look at the missing data

#create data matrix using only the variables to be included in the imputation
# alternatively you can select the variable in the imputation function call, but the notation is messy. 
data2_sub <- data2[,c("QALY","sex", "age")]

# Impute the missing values, specifying 20 imputed data sets. 
impute <- mice(data2_sub , m=20, seed = 1234)
impute80 <- mice.mids(impute, maxit=60, seed = 1234, print=F)

#From extra imputations decide to use 80 rather than 20
impute.extra <- mice(data2_sub , m=80, seed = 1234)

# To obtain the mean across the 80 imputations allowing for within and between variability use the following commands
impdat <- complete(impute.extra,action="long",include = FALSE)
pool_mean <- with(impdat, by(impdat, .imp, function(x) c(mean(x$QALY),sd(x$QALY))))

#Average imputed data set for bootstrapping
impute_mean <- rep(0, length(complete(impute.extra, 1)))
for(i in 1:80){impute_mean <- impute_mean + complete(impute.extra, i)}
impute_mean <- impute_mean/80

#Bootstrap CI
library(boot) # load the boot library

# define function to be used for bootstrapping (taking the mean of TxSurv and NonTxSurv)
boot_function1 <- function(dat, d) {
  E <- dat[d,] # allows boot to select sample 

Bootstrap_impute <- boot(impute_mean, boot_function1, R=5000)

#Bootstrap CI, type=c("norm", "perc", "bca"), index=1) #

sorry it showed you replied to the codes but im not sure what did you do exactly
would you please clarify it for me.

Thanks so much

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.