0

I would like to use CreateTableOne() to calculate SMD(standardized mean difference) of variables between two groups(grou=0 and grou=1) after Mice imputed. But I found that CreateTableOne() could not be nested inside with().

library(tableone)
library(MICE)
data("nhanes2")
vars=c("bmi","chl","age","hyp")
catvars=c("age","hyp")
data_im=mice(nhanes2,m=5,seed=6666)
pool(with(data_im,CreateTableOne(vars = vars, factorVars= catvars,strata = "hyp", test =TRUE)))

# **Error in ModuleStopIfNotDataFrame(data) : 
#   argument "data" is missing, with no default

How to calculate SMD of imputed dataset through pool()?

tumidou
  • 35
  • 5
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Feb 23 '23 at 19:09
  • @MrFlick Ok, I take the ```data("nhanes2")``` for example in Edit. – tumidou Feb 23 '23 at 19:27

1 Answers1

0

You can get all the tables with

with(data_im, CreateTableOne(
  vars = vars, 
  data=as.data.frame(mget(ls())), 
  factorVars=catvars,strata = "hyp", test =TRUE))

We use mget() to grab all the variables in the environment and turn them into a data.frame.

This will return a list of TableOne objects. But there's no method to pool such objects so it's not clear how you want to calculate SMD. There are no groups in this example. If you want advice on how to combine statistical values from multiple imputations, you should ask for statistical advice at [stats.se] instead.

MrFlick
  • 195,160
  • 17
  • 277
  • 295
  • OK,thanks so much. Could you also help me with this question https://stackoverflow.com/questions/75548093/with-mice-package-how-to-create-a-list-of-models-from-a-list-of-variables-to-te, it seems to be the same type of this one. – tumidou Feb 23 '23 at 20:00