Skip to content

Instantly share code, notes, and snippets.

View mike-lawrence's full-sized avatar

Mike Lawrence mike-lawrence

  • Halifax, Nova Scotia, Canada
View GitHub Profile
@mike-lawrence
mike-lawrence / mike_podcast_picks.txt
Created February 4, 2023 15:07
Mike’s podcast picks!
Mike’s Podcast picks
————
Comedic (all should be started at S01E01)
————
The adventure zone
Mission to Zyxx
Beef & Dairy Network Podcast
————
@mike-lawrence
mike-lawrence / hwg_sufficient.stan
Created January 18, 2023 19:39
hierarchical within-subjects gaussian with sufficient stats and reduce_sum
functions{
real partial_lpdf(
array[] real real_array_to_slice
, int start
, int end
, real sigma
, vector Zc
, matrix iZc_chol_mat
, matrix iZc
, array[] matrix iZc_
@mike-lawrence
mike-lawrence / _.rproj
Created January 17, 2021 19:43
Hierarchical Within-Subjects model with Gaussian measurement noise
Version: 1.0
RestoreWorkspace: No
SaveWorkspace: No
AlwaysSaveHistory: No
QuitChildProcessesOnExit: Yes
EnableCodeIndexing: Yes
UseSpacesForTab: No
NumSpacesForTab: 4
@mike-lawrence
mike-lawrence / helper_functions.r
Last active May 14, 2021 02:32
Stan vs LME4 for hiearchical within-subjects designs with binomial outcomes
#' Installs any packages not already installed
#' @examples
#' \dontrun{
#' install_if_missing(c('tidyverse','github.com/stan-dev/cmdstanr'))
#' }
install_if_missing = function(pkgs){
missing_pkgs = NULL
for(this_pkg in pkgs){
@mike-lawrence
mike-lawrence / helper_functions.r
Created January 5, 2021 05:41
hierarchical within-subjects model with Gaussian outcome & reduced-redundant-computation
#' Installs any packages not already installed
#' @examples
#' \dontrun{
#' install_if_missing(c('tidyverse','github.com/stan-dev/cmdstanr'))
#' }
install_if_missing = function(pkgs){
missing_pkgs = NULL
for(this_pkg in pkgs){
@mike-lawrence
mike-lawrence / composed_divergences.r
Last active January 3, 2021 21:19
composed_divergences
#preamble (installs/imports & custom functions) ----
# specify the packages used:
required_packages = c(
'rethinking' #for rlkjcorr & rmvrnom2
, 'crayon' #for coloring terminal output
, 'tidyverse' #for all that is good and holy
, 'progress' #for progress bar
, 'github.com/stan-dev/cmdstanr' #for Stan stuff
, 'github.com/mike-lawrence/ezStan' #for extra Stan stuff (here just get_contrast_matrix)
@mike-lawrence
mike-lawrence / binom_sim.r
Last active November 27, 2020 15:31
code to generate and plot posterior distributions for binomial outcomes
# load packages and define helper functions ----
library(cmdstanr) #for bayes goodness
library(posterior) #for posterior::as_draws_df()
library(progress) # for progress bars
library(viridis) #for better color scales
library(tidyverse) #for all that is good and holy
# helper function to create a progess bar in the global env
create_global_pb = function(x){
pb <<- progress::progress_bar$new(
@mike-lawrence
mike-lawrence / main.r
Created June 14, 2020 07:43
reliability simulation
# load packages used ----
library(tidyverse)
library(broom)
options(dplyr.show_progress=TRUE)
# define a function to simulate an experiment ----
simulate_experiment = function(
# simulation parameters ----
within_subject_noise = 1
@mike-lawrence
mike-lawrence / 2x2.r
Last active March 24, 2020 12:50
LMER power simulations
library(tidyverse)
library(broom)
library(lme4)
#set default contrasts to halfsum (this matters!)
halfsum_contrasts = function (...) contr.sum(...) * 0.5
options(contrasts = c('halfsum_contrasts','contr.poly'))
run_sim = function(N,K,seed,do_checks=F){
@mike-lawrence
mike-lawrence / example_data.dput
Created March 2, 2020 17:39
dput of some example data
This file has been truncated, but you can view the full file.
structure(list(toj_condition = structure(c(1L, 2L, 1L, 2L, 1L,
2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L,
2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L,
2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L,
2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L,
2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L,
2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L,
2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L,
2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L,
2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L,