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> |
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)) |
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 |
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){ |
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, |
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)") | |
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){ |
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){ |
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 |