tbl_rgression() gtsummary with lm model generated with custom function

51 Views Asked by At
library(gtsummary)
packageVersion("gtsummary")
run_custom_lm <- function(dependent_var, independent_vars, data) {
  formula_str <- paste(dependent_var, "~", paste(independent_vars, collapse = "+"))
  lm_model <- lm(formula_str, data = data)
  return(lm_model)
}

model_custom_fun <- run_custom_lm("mpg", c("hp", "wt", "qsec"), data = mtcars)
model_generic_fun <- lm(mpg ~ hp + wt + qsec, data = mtcars)

tbl_regression(model_generic_fun, tidy_fun = tidy_standardize) |> as_kable()

#———
tidy_standardize(): Estimating standardized coefs with
`parameters::standardize_parameters(model = x, ci = 0.95)`
tidy_standardize(): Estimating standardized coefs with
`parameters::standardize_parameters(model = x, ci = 0.95)`
✖ There was an error calling `tidy_fun()`. Most likely, this is because the
function supplied in `tidy_fun=` was misspelled, does not exist, is not
compatible with your object, or was missing necessary arguments (e.g. `conf.level=` or `conf.int=`). See error message below.
Error:
! Error: Unable to refit the model with standardized data. Try instead
   to standardize the data (standardize(data)) and refit the model manually.
0

There are 0 best solutions below