Why does pool function in r give "Error: $ operator is invalid for atomic vectors" error?

Viewed 52

My first question on Stackoverflow...sorry for any inconvenience and imprecision. I'm performing an analysis on multiple imputated dataset, generated with mice package. I used split function to generate the data.frame list and, on each data.frame, I added an IPTW variable estimated on each data.frame separately. With my data ready, I performed the models of interest (weighted Cox models with cph function) and put the results in a list (fit0). When I try to run

pool(fit0)

I get the message:

Error: $ operator is invalid for atomic vectors

I looked into pool function and I find the problem could be in pool.fitlist subfunction. At the beginning of the pool.fitlist, there's a summary that only want extract the coefficients of the models from my list, but if I try to run it out of the function (after a as.mira transformation of my list of results) I get again the error message:

Error: $ operator is invalid for atomic vectors

Looking to my results, I found that

> is.atomic(fit0$analyses[[2]]$coefficients)
[1] TRUE

Any idea how to solve this little drawback?

EDIT: I add the code and the fake data of example. Initially I create 4 short data.frame and put them in a list

n <- 6
d1 <- data.frame(id=1:n, 
                 event=c(0,1,1,1,1,1),
                 time=c(19.67, 11.94, 7.86, 1.58, 48.55, 36.18),
                 age=c(59,75,38,67,68,41),
                 drug=c("Yes","No","Yes","Yes","Yes","Yes"),
                 w=c(0.07229, 0.52002, 0.04708, 0.06576, 0.08355, 0.04033)
)
d2 <- data.frame(id=1:n, 
                 event=c(0,1,1,1,1,1),
                 time=c(19.67, 11.94, 7.86, 1.58, 48.55, 36.18),
                 age=c(59,75,38,67,68,41),
                 drug=c("Yes","No","Yes","Yes","Yes","Yes"),
                 w=c(0.0687, 0.5395, 0.0289, 0.1070, 0.1536, 0.1178)
)

d3 <- data.frame(id=1:n, 
                 event=c(0,1,1,1,1,1),
                 time=c(19.67, 11.94, 7.86, 1.58, 48.55, 36.18),
                 age=c(59,75,38,67,68,41),
                 drug=c("Yes","No","Yes","Yes","Yes","Yes"),
                 w=c(0.01654, 0.44411, 0.06588, 0.07772, 0.05326, 0.03234)
)
d4 <- data.frame(id=1:n, 
                 event=c(0,1,1,1,1,1),
                 time=c(19.67, 11.94, 7.86, 1.58, 48.55, 36.18),
                 age=c(59,75,38,67,68,41),
                 drug=c("Yes","No","Yes","Yes","Yes","Yes"),
                 w=c(0.02490, 1.00000, 0.21502, 0.08058, 0.11399, 0.07635)
)

ld <- list(d1,d2,d3,d4)

After than I generate preform the IPTW models and gather the results in a list and use the pool function:

modelFit0 <- vector("list", 4)

for(i in 1:4) {
  
  res <- cph(Surv(time,event)~ rcs(age,3) + drug,
              data=ld[[i]], weights=w)
  modelFit0[[i]] <-res

}  

pool.fit.OS <- pool(modelFit0)

Here is where I get:

> pool.fit.OS <- pool(modelFit0)
Error: $ operator is invalid for atomic vectors
In addition: Warning message:
In get.dfcom(object, dfcom) : Infinite sample size assumed.

Hope this is a valide reproducible example.

I use cph packeage from rms library. These are my sessionInfo:
R version 4.1.2 (2021-11-01)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19043)
other attached packages: rms_6.2-0 [...]

0 Answers
Related