Skip to content

Instantly share code, notes, and snippets.

View mattansb's full-sized avatar

Mattan S. Ben-Shachar mattansb

View GitHub Profile
@mattansb
mattansb / qq_worm_plot.R
Last active December 1, 2019 00:18
make qq plots with worm holes
# From https://twitter.com/mattansb/status/1199936633413476358
qq_worm_plot <- function(x, distribution = "norm", ...) {
d <- match.fun(paste0("d",distribution))
p <- match.fun(paste0("p",distribution))
q <- match.fun(paste0("q",distribution))
dparams <- list(...)
if (!require(ggplot2)) stop("Need 'ggplot2' to use this function")
@mattansb
mattansb / BFBayesFactor_2_emmeans.R
Created May 12, 2019 08:07
This is my attempt at an `emmeans` integration for `BayesFactor` R package
#' @export
recover_data.BFBayesFactor <- function (object,index = 1, ...) {
object <- object[index]
data <- object@data
formula <- as.formula(object@numerator[[1]]@longName)
trms <- delete.response(terms(eval(formula, parent.frame())))
# Remove random effects
random_ <- object@numerator[[1]]@dataTypes=='random'
library(tidyverse)
library(emmeans)
library(gganimate)
library(tweenr)
# Setup data --------------------------------------------------------------
n <- 200
df <- tibble(X1 = rnorm(n,100,15),
X2 = rnorm(n,30,5),