If you find yourself doing something over and over, you can probably write a function for it.
One is example is the regression tables we created yesterday.
logistic_model <- glm(glasses ~ eyesight_cat + sex_cat + income,
data = nlsy, family = binomial()
)
poisson_model <- glm(nsibs ~ eyesight_cat + sex_cat + income,
data = nlsy, family = poisson()
)
logbinomial_model <- glm(glasses ~ eyesight_cat + sex_cat + income,
data = nlsy, family = binomial(link = "log")
)
tbl_regression(
poisson_model,
exponentiate = TRUE,
label = list(
sex_cat ~ "Sex",
eyesight_cat ~ "Eyesight",
income ~ "Income"
)
)
Even though this is already a function, we can wrap it in a new function!
We can refer generically to model
and then put the model we want a table for as an argument
tidy_fun
argument (from the regression exercises yesterday)