c_dinosaur
c_dinosaur

Reputation: 41

Automatically Display Overall and Subgroup‐Specific Effects for a Predictor in gtsummary

I have a linear model with an interaction between a continuous predictor and a binary grouping variable. For example, consider the model

model <- lm(y ~ age + gender + X * Group, data = mydata)

where: X is a continuous predictor, Group is a binary factor with levels "A" (reference) and "B".

I want to produce a regression table that displays three rows for the effect of X:

One row for the overall effect (computed from a model without interaction; representing the whole cohort), One row for the effect of X in Group A (the reference group), and One row for the effect of X in Group B (which equals the effect in Group A plus the interaction term).

Is there any built-in way in gtsummary to automatically compute and display these subgroup‐specific effects? If not, what is the recommended workaround? I'm dealing a lot with interactions and I want a handy solution for the future to show associations in subgroups and at best (!) also the overall effect (without interaction).

If an overall effect is not easily includable (because that's actually another model), the slopes (+ CIs + p Value) for the interacting variable would suffice in one table with the other independent variables in the model.

Example data:

# Load the dataset and set up the grouping variable
data(mtcars)
mtcars$am <- factor(mtcars$am, labels = c("Automatic", "Manual"))

# Fit an interaction model: mpg ~ hp * am
model_int <- lm(mpg ~ cyl + hp * am, data = mtcars)

Prints only the reference variable and difference in slopes (interaction); however the the estimate and p value for the other category than the refrence is missing.

Any help or suggestions (even other libraries) would be appreciated!

Upvotes: 1

Views: 33

Answers (0)

Related Questions