I am running generalized additive models with mgcv::gam
and am trying to organize my results using broom:tidy
, but tidy
apparently does not exponentiate coefficients or confidence intervals for GAMs, though it does for regular glm
models. Is there a broom::tidy
method for exponentiating coefficients and CIs from GAMs? I ask specifically about tidy
because I would like to use the results in regression tables created by gtsummary
.
library(tidyverse)
library(magrittr)
library(mgcv)
library(parameters)
library(gtsummary)
library(broom)
# sample data
id <- 1:2000
gender <- sample(0:1, 2000, replace = T)
age <- sample(17:64, 2000, replace = T)
race <- sample(0:1, 2000, replace = T)
health_score <- sample(0:25, 2000, replace = T)
dead <- sample(0:1, 2000, replace = T)
days_enrolled <- sample(30:3000, 2000, replace = T)
df <- data.frame(id, gender, age, race, health_score, dead, days_enrolled)
# model
model <- gam(dead ~ gender + s(age) + race + s(health_score) + offset(log(days_enrolled)),
data = df, method = "REML", family = nb())
# both give the same output:
tidy(model, parametric = T, conf.int = T)
tidy(model, parametric = T, conf.int = T, exponentiate = T)
You can directly use tbl_regression()
to exponentiate your results. If this is not what you are after please let me know.
library(tidyverse)
library(mgcv)
library(parameters)
library(gtsummary)
library(broom)
# sample data
id <- 1:2000
gender <- sample(0:1, 2000, replace = T)
age <- sample(17:64, 2000, replace = T)
race <- sample(0:1, 2000, replace = T)
health_score <- sample(0:25, 2000, replace = T)
dead <- sample(0:1, 2000, replace = T)
days_enrolled <- sample(30:3000, 2000, replace = T)
df <- data.frame(id, gender, age, race, health_score, dead, days_enrolled)
# model
model <- gam(dead ~ gender + s(age) + race + s(health_score) + offset(log(days_enrolled)),
data = df, method = "REML", family = nb())
tbl_regression(model, exponentiate = TRUE)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.