View gist:64a6a625b52d6f6885b112905f90037e
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' Compute the Block-WeightedCleavage Saliance Index | |
#' | |
#' | |
#' | |
#' @param data A crosstab of cell percentages. | |
#' @param cleavage A character vector containing the names of the parties in the cleavage bloc. | |
#' @param opposition A character vector containing the names of the parties in the opposition bloc. | |
#' @param elec_1 The name of the column containing vote shares at time 1. | |
#' @param elec_2 The name of the column containing vote shares at time 2. | |
#' @return A numeric vector |
View gist:6fdc627485e3e3b469f4aa963db1d9c2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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){ |
View gist:0d29d2f2229cfe9d83c1672488308882
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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)) |
View UoM_Harvard.csl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> |