knitr::opts_chunk$set(echo = FALSE)
library("academicWriteR")
library("lme4")
library("lmerTest")
library("brms")
library("tidyverse")
# Testing: try to see if you can determine the doc type and use it to 
# set how the functions work
doc_type <- knitr::opts_knit$get('rmarkdown.pandoc.to')
use_latex <- dplyr::if_else(doc_type == "latex", TRUE, FALSE)
doc_type
use_latex

Fit models and inline printing

mod1 <- lm(mpg ~ wt * drat, data = mtcars)
mod2 <- glm(mpg ~ wt, data = mtcars, family = "gaussian")
mod3 <- lmer(Reaction ~ 1 + Days + (1|Subject), data = sleepstudy)
mod4 <- glmer(cbind(incidence, size - incidence) ~ period + (1 | herd),
              data = cbpp, family = binomial)
mod5 <- brm(mpg ~ wt, data = mtcars, file = here::here("testing_files", "mod5"))

r print_model_param(mod1, "wt")
r print_model_param(mod2, "(Intercept)")
r print_model_param(mod3, "(Intercept)")
r print_model_param(mod4, "(Intercept)")
r print_model_param(mod5, "wt")

\clearpage

```{=openxml}

# Printing models to tables

## lm

```r
mod_to_table(
  mod1, 
  font_size = 12, 
  left_align = 1, 
  param_names = c(Intercept = "(Intercept)", 
                  WT = "wt", 
                  DRAT = "drat", 
                  `WT x DRAT` = "wt:drat"), 
  col = c(1, 2), width = 1.5
  )


lmer

mod_to_table(
  mod3, 
  font_size = 12, 
  left_align = 1, 
  param_names = c(Intercept = "(Intercept)"), 
  col = 1, width = 1.5
  )


glmer

mod_to_table(
  mod4, 
  font_size = 12, 
  left_align = 1, 
  param_names = c(Intercept = "(Intercept)"), 
  col = 1, width = 1.5
  )


brms

mod_to_table(
  mod5, 
  font_size = 12, 
  left_align = 1, 
  #param_names = c(Intercept = "b_Intercept"), 
  col = c(1, 3), width = 1.5
  )

```{=openxml}

```r
mod_to_table(
  mod1, font_size = 11, 
  param_names = c(Intercept = "(Intercept)", 
                  `$\\delta VOT_{hi}$` = "wt", 
                  `\\textipa{[BSsoODP]}` = "drat"))


jvcasillas/academicWriteR documentation built on Dec. 28, 2024, 5:09 p.m.