In R, I am trying to use tableone::CreateTableOne in order to calculate smd (standardized mean differences) on a dataframe. I used this tutorial (https://cran.r-project.org/web/packages/tableone/vignettes/smd.html) - the code runs and nicely produces the desired output table, including the smd.
However, if I use my own data, e.g. the test data below, I get the table but without smd. Probably I did some stupid mistake, but after trying a lot of things (only numeric, smaller or larger dataset, categorial variables as factor (as in r help) or character (as in tutorial)...) I cannot figure out why I do not get smd.
# package tableone for CreateTableOne
if (!require("tableone")) install.packages("tableone"); library("tableone")
# producible test data
set.seed(1234)
d <- data.frame(age = rnorm(n = 200, mean = 50, 9),
hair = as.factor(sample(x = c("brown", "black", "blond"), 200, replace = T)),
group = sample(x = c("sick", "healthy"), 200, replace = T))
str(d)
# calculate and print the table
tabUnmatched <- tableone::CreateTableOne(vars = c("age", "hair"), strata = "group", data = d, test = FALSE, smd = TRUE)
print(tabUnmatched)
results in the following table, WITHOUT smd (and no error message):
Stratified by group
healthy sick
n 90 110
age (mean (SD)) 49.18 (7.97) 49.72 (10.10)
hair (%)
black 30 (33.3) 35 (31.8)
blond 33 (36.7) 43 (39.1)
brown 27 (30.0) 32 (29.1)
What am I doing wrong, what do I need to do to get smd output?
errr...this?