'why function svyCreateTableOne works but i can´t print continuous results?

I´m having a problem printing results from svyCreateTableOne. In the beginning, all my variables are class numeric and I specify in vector "catvar" the ones that will be handled as categorical by svyCreateTableOne. I can only print results for categorical variables.

#all variables
listvar<- c("age","female","depre","manic","anxiety","subst",
                 "diuretics","lipid","nsaids","antiepileptics","tot_meds") 
    
    continuous <- c("age","tot_meds") 
    
    catvar <- listvar[!listvar %in% continuous] # specify that all other variables except the ones specified previously are categorical

    #create weighted survey
    adjusted_data <- svydesign(ids = ~ trt, data = dat.temp, weights = ~ sw)
    
    
    ## Weighted table with tableone package
    tabadj<-svyCreateTableOne(vars = listvar, strata = "trt", data = adjusted_data, factorVars = catvar)
    
    print(tabadj, test = FALSE, smd = TRUE)

Error in round(n, digits = digits) : non-numeric argument to mathematical function



Solution 1:[1]

RTools is not actually the issue. It sounds like there is an issue with an update of survey not working with an update of tableone.

Full details are here https://github.com/kaz-yos/tableone/issues/83

In short, this code will fix it.

svyQuant_alt <- function (vars, design, q = 0.5) {
res <- vector()
for (i in 1:length(vars)) {
var <- vars[i]
res[i] <- oldsvyquantile(design$variables[var], design = design,
quantiles = q[1], na.rm = TRUE)
}
out <- as.vector(res)
names(out) <- vars
out
}

environment(svyQuant_alt) <- asNamespace('tableone')
assignInNamespace("svyQuant", svyQuant_alt, ns = "tableone")

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Scott McClure