Reputation: 4200
I have a model summary from a mediation::mediate
call, which I would like to export to LaTeX. Consider this example (from the documentation).
# install.packages("mediation")
library("mediation")
set.seed(2014)
data("framing", package = "mediation")
med.fit <- lm(emo ~ treat + age + educ + gender + income, data = framing)
out.fit <- glm(cong_mesg ~ emo + treat + age + educ + gender + income, data = framing, family = binomial("probit"))
med.out <- mediate(med.fit, out.fit, treat = "treat", mediator = "emo", robustSE = TRUE, sims = 100)
I would now like to export the summary()
of med.out
to a LaTeX table. (Importantly, all coefficients should be included!).
med.out %>% summary()
# Gives the following output:
# Causal Mediation Analysis
# Quasi-Bayesian Confidence Intervals
# Estimate 95% CI Lower 95% CI Upper p-value
# ACME (control) 0.0791 0.0351 0.15 <2e-16 ***
# ACME (treated) 0.0804 0.0367 0.16 <2e-16 ***
# ADE (control) 0.0206 -0.0976 0.12 0.70
# ADE (treated) 0.0218 -0.1053 0.12 0.70
# Total Effect 0.1009 -0.0497 0.23 0.14
# Prop. Mediated (control) 0.6946 -6.3109 3.68 0.14
# Prop. Mediated (treated) 0.7118 -5.7936 3.50 0.14
# ACME (average) 0.0798 0.0359 0.15 <2e-16 ***
# ADE (average) 0.0212 -0.1014 0.12 0.70
# Prop. Mediated (average) 0.7032 -6.0523 3.59 0.14
# ---
# Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
# Sample Size Used: 265
# Simulations: 100
I tried the following which are all not (quite) working.
med.out %>% modelsummary::modelsummary() # produces output but misses coefficients
med.out %>% texreg::texreg() # produces error
med.out %>% xtable::xtable() # produces error
med.out %>% kableExtra::kable() # produces error
Does someone know of a smarter solution than getting the values from the object individually (e.g. med.out$d1
etc.)?
----EDIT----
Similar questions do not answer this.
mediation::mediate()
)med.out$d1
). I have a large number of models and even doing so with a custom function is not feasible, so I am looking for a more standardized solution.Upvotes: 1
Views: 455