Skip to content

Instantly share code, notes, and snippets.

Avatar

Jack Bailey jackobailey

View GitHub Profile
@jackobailey
jackobailey / gist:6fdc627485e3e3b469f4aa963db1d9c2
Last active Jul 24, 2020
AMEs for continuous variables and categorical outcomes
View gist:6fdc627485e3e3b469f4aa963db1d9c2
bayes_dydx.default_mn <- function(model, data = NULL, variable, stepsize = 1e-7, re_formula = NULL){
# Check that everything is running properly and that the
# user has provided all of the relevant information.
if(is.null(model) == T){
stop("Please provide a model to the function using the 'model =' argument (e.g. model = m1)")
} else if(is.null(variable) == T){
@jackobailey
jackobailey / gist:0d29d2f2229cfe9d83c1672488308882
Created Jul 24, 2020
Predictive margins for categorical models
View gist:0d29d2f2229cfe9d83c1672488308882
bayes_margin.factor_mn <- function(model, variable = NULL, data = NULL, draws = NULL, n = NULL, re_formula = NA){
# Check that everything is running properly and that the
# user has provided all of the relevant information.
if(is.null(model) == T){
stop("Please provide a model to the function using the 'model =' argument (e.g. model = m1)")
} else if(is.null(variable) == T){
View gist:758df4a4c853ab4aab2389c32c5654c7
bayes_dydx.factor_mn <- function(model, variable = NULL, data = NULL, draws = NULL, n = NULL, re_formula = NA){
# Check that everything is running properly and that the
# user has provided all of the relevant information.
if(is.null(model) == T){
stop("Please provide a model to the function using the 'model =' argument (e.g. model = m1)")
View gist:46d61c07e88f1c92e36d107023514a81
# Load packages using the 'librarian' package
librarian::shelf(tidyverse,
tidybayes,
brms,
here)
# Create function to simulate the outcome scale for arbitrary
# prior distributions
rlikert <- function(n = 1e3,
t1 = -0.84,
View gist:0982c89326c36b12d6fa6d6f182189be
# Load packages
library(brms)
library(tidybayes)
library(tidyverse)
library(magrittr)
library(reshape2)
library(margins)
# Function 1: Compute numerical derivatives for continuous variables ----------
bayes_dydx.default <- function(model, data = NULL, variable, stepsize = 1e-7, re_formula = NULL){
View gist:e819f8b358b676acad79dee8bfde0039
# Install and load packages
librarian::shelf(brms, tidybayes, tidyverse, magrittr, margins)
# Create "posterior_ame" function
posterior_ame <- function(model, variable, eps = 1e-7){
# Get model outcome
resp <- model$formula$resp
# Omit outcome variable from data
View gist:a6edbaff94395a7f3b750a55aa092e14
# Load packages
library(tidyverse)
library(brms)
library(broom)
# We need to simulate data from an ordinal distribution. This is hard.
# Unlike many distributions, treatment effects can affect the mean *and*
# the sd of the latent y* distribution that underlies the ordinal distribution
# (see Liddell & Kruschke (2018) and Bürkner & Vuorre (2019))
@jackobailey
jackobailey / UoM_Harvard.csl
Last active Aug 3, 2018 — forked from jbhaddow/mbsharvard1.1.csl
University of Manchester Harvard Reference Format
View UoM_Harvard.csl
<?xml version="1.0" encoding="UTF-8"?>
<style xmlns="http://purl.org/net/xbiblio/csl" class="in-text" version="1.0" demote-non-dropping-particle="sort-only">
<info>
<title>Manchester Business School Harvard Reference format 1.1 (Author-Date)</title>
<id>http://www.zotero.org/styles/mbsharvard1.1</id>
<link href="http://www.zotero.org/styles/mbsharvard1.1" rel="self"/>
<author>
<name>James Haddow</name>
<email>jbh78@me.com</email>
</author>