knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%",
  message = FALSE,
  warning = FALSE
)

sostools

Codecov test coverage

This is just a collection of functions I use in my research that I use frequently. Other functions I use infrequently can be found in my snippets repo. Since a lot of this is stuff that I use for my personal work, it's not guaranteed to work flawlessly in other contexts.

Installation

You can install the development version from GitHub with:

# install.packages("devtools")
devtools::install_github("tsostarics/sostools", build_vignettes = TRUE)

Easily reference coefficients in prose

Here is a simple example of referencing the values of a model summary without needing to hand write or format it yourself. See ?get_coef for more information. make_coef_getter is a function factory that provides a shorthand if you have multiple models you're working with.

library(sostools)
library(tidyverse)
mdl <- lm(mpg ~ cyl * gear, data = mtcars) # Create model
coefs <- enlist_coefs(mdl) # Create coefficients
get_coef1 <- make_coef_getter(mdl) # Using the model object directly
get_coef2 <- make_coef_getter(coefs) # Using the list of coefficients we made
get_coef("cyl:gear", coefs)
get_coef1("cyl:gear")
get_coef2("cyl:gear")

Here we can get the formatted values of a write up easily with in-line R code. You could say something like: We found no significant effect of cylinder r get_coef2("cyl") or gear r get_coef2("gear") nor a significant interaction between the two r get_coef2("cyl:gear").

You can also use these with Bayesian models fit with brms, which will give you the $\beta$ estimate as well as the credible interval.

Contrast coding functionality

This functionality has been exported to a standalone package, please visit tsostarics/contrastable



tsostarics/sostools documentation built on Nov. 22, 2022, 7:26 p.m.