Reputation: 1
I am trying to perform a bootstrapped logistic regression with backwards selection using boot.stepAIC()
on a multiple imputed dataset (created using mice). The dataset consists of a couple of columns with numerical as well as categorical data. I am imputing five times using RF creating a mids-dataset.
Using a function, I would like to go through the different imputed datasets and bootstrap a logistic regression 1000 times. However, no matter what I try the following error keeps popping up:
Error in eval(mf, parent.frame()) : object 'dTMP' not found
Setup:
library(mice)
library(miceadds)
library(bootStepAIC)
sample data
df <- data.frame(
age = as.numeric(c(55,33,78,NA,32,22,NA,98,44,23)),
sex = factor(c(1,0,1,NA,0,1,0,NA,0,1)),
AA = factor(c(0,1,NA,1,1,0,0,0,NA,1)),
BB = factor(c(0,NA,1,0,0,0,NA,1,NA,1)),
Sodium = as.numeric(c(140, 144, 140, 139,
140,140,NA,141,144,145)),
CKD = factor(c(0,1,0,1,1,0,1,0,1,0)),
type = factor(c("A", "B", "A", "B","A","A","B","B","A", "B"))
)
mice_object <- mice(df, method = "rf", m = 5, set.seed = 10)
subset data
imputed_data <- miceadds::subset_datlist(mice_object,
expr_subset=expression(type == "A"), toclass = "mids")
select variables from subset
imputed_data <- miceadds::subset_datlist(imputed_data,
select = c("age", "sex", "AA", "BB", "Sodium", "CKD"), toclass =
"mids")
bootstrapping function
selectedboot = lapply(seq_along(1:imputed_data$m), function(i) {
dTMP = complete(imputed_data , i)
Mglm = glm(CKD ~ ., data = dTMP, family = binomial)
Bresult = boot.stepAIC(Mglm, data = dTMP, B = 1000, direction =
'backward')
return(Bresult)
})
I already tried running through different variations for seq_along(1:mice_object$m)
as this part of the code seemed to be the problem because the object "dTMP" can not be made in the second line of the function.
What am I overlooking?
Edit: added sample data and additional steps taken before bootstrapping function. Analysis is subsetted and specific variables are selected in the subset using miceadds. This should replicate the problem.
Edit2: removed a typo from the example code.
Upvotes: 0
Views: 621