Reputation: 169
I am using the gtsummary package to build various tables. However, I am encountering problems when creating tables with tbl_regression and tbl_uvregression when the results come from a survey-weighted binomial regression fitted with the svyVGAM package.
To illustrate the issue more clearly, I created the example below to highlight the error that R points out.
library(survey)
library(svyVGAM)
library(gtsummary)
# Example dataset
set.seed(123)
n <- 1000
# Example data
example_data <- data.frame(
n_events = rpois(n, lambda = 2), # Count outcome variable
age = rnorm(n, mean = 45, sd = 15),
income = rnorm(n, mean = 3000, sd = 1000),
education = rnorm(n, mean = 8, sd = 2),
sex = factor(rbinom(n, 1, 0.5), labels = c("Male", "Female")), # Changed to sex as factor
survey_weight = runif(n, 0.5, 1.5) # Survey weights
)
# Create survey design
svy_design <- svydesign(
ids = ~1, # No clustering
weights = ~survey_weight,
data = example_data
)
# Fit negative binomial model
nb_model <- svy_vglm(
n_events ~ age + income + education + sex,
family = negbinomial(),
design = svy_design
)
# View summary
summary(nb_model)
When I run the scripts, the following errors appear:
> tbl_mutually_adjusted <- tbl_regression(
+ nb_model,
+ exponentiate = TRUE,
+ tidy_fun = broom.helpers::tidy_parameters
+ )
✖ Unable to identify the list of variables.
This is usually due to an error calling `stats::model.frame(x)`or `stats::model.matrix(x)`.
It could be the case if that type of model does not implement these methods.
Rarely, this error may occur if the model object was created within
a functional programming framework (e.g. using `lappy()`, `purrr::map()`, etc.).
> tbl_unadjusted <- tbl_uvregression(
+ nb_model,
+ exponentiate = TRUE,
+ tidy_fun = broom.helpers::tidy_parameters
+ )
Error in UseMethod("tbl_uvregression") :
no applicable method for 'tbl_uvregression' applied to an object of class "svy_vglm"
>
Upvotes: 0
Views: 39