This file contains hidden or 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
from psychopy import visual | |
from psychopy.tools.colorspacetools import hsv2rgb | |
import numpy as np | |
win = visual.Window( | |
size=[800, 600], fullscr=False, screen=0, | |
gammaErrorPolicy='ignore', | |
color=(1, 1, 1), colorSpace='rgb', units='height') | |
class CompoundStim(): |
This file contains hidden or 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
library(tidyverse) | |
# Arguments: Sigma of old predictor, Sigma of new predictor, N cases | |
compare_methods = function(s0, s1, n){ | |
print(c(s0, s1, n)) | |
y = rnorm(n, 0, 1) | |
x0 = y + rnorm(n, 0, s0) # Old predictor | |
x1 = y + rnorm(n, 0, s1) # New predictor to evaluate | |
m0 = lm(y ~ x0) |
This file contains hidden or 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
library(brms) | |
library(rstan) | |
## Simulate data | |
bxy = 2 | |
bxz = 3 | |
byz = 4 | |
e = .1 | |
n = 1000 |
This file contains hidden or 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
import numpy as np | |
import matplotlib.pyplot as plt | |
def plot_top(names, values, n_top=10, | |
order=None, | |
alpha=.25, | |
ax=None, figsize=None): | |
'''Plot the top N values, then squeeze in the rest | |
This file contains hidden or 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
library(tidyverse) | |
# Simulate data under 1-cluster solution: | |
# Two Gaussians, with different means, same SD. | |
m1 = 10 | |
m2 = 20 | |
sd = 10 | |
n1 = 50 | |
n2 = 50 | |
x1 = rnorm(n1, m1, sd) |
This file contains hidden or 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
# Coin Flip MAP Bootstrap | |
library(tidyverse) | |
theme_set(theme_bw(base_size=18)) | |
# Data | |
outcomes = c(rep(0, 5), rep(1, 15)) # True probability = 0.75 | |
n_trials = length(outcomes) | |
# Beta Prior |
This file contains hidden or 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
#' Plot matrix as heatmap | |
#' @description | |
#' `plot_covariance_matrix()` adds an appropriate `fill_label` | |
#' `plot_correlation_matrix()` also sets limits to ±1 | |
#' | |
#' Make sure to import dplyr and ggplot (or tidyverse)! | |
#' @param mat Matrix to plot | |
#' @param labeller Function or list used to rename rows/cols | |
#' @param digits Digits to round values to (default 2) | |
#' @param limit Limit (±) of colour scale. Defaults to `abs(max(value))` |
This file contains hidden or 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
--- | |
title: "glm_prevelance" | |
author: "Eoin Travers" | |
output: html_document | |
--- | |
```{r} | |
library(tidyverse) | |
binom_smooth = function (link = "probit", ...) { | |
geom_smooth(method = "glm", |
This file contains hidden or 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
plot_measurement_invariance = function(model){ | |
factor_loadings = parameterEstimates(model) %>% | |
rename(estimate = est, low = ci.lower, high = ci.upper) %>% | |
mutate(rhs = factor(rhs, levels = unique(rhs)), | |
lhs = factor(lhs, levels = unique(lhs)), | |
label = paste(lhs, op, rhs), | |
type = case_when( | |
op == '=~' ~ 'Loading', | |
op == '~~' ~ 'Covariance', | |
op == '~1' ~ 'Mean', |
This file contains hidden or 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
generate_spaced_dates = function(n_samples, gap = 21, | |
total_period = 365, | |
n_iter=1e12){ | |
x = runif(n_samples, 0, total_period) %>% sort() %>% round() | |
for(i in 1:1e12){ | |
is_acceptable = min(diff(x)) >= 21 | |
if(is_acceptable) { | |
break | |
} else { | |
x = runif(n_samples, 0, total_period) %>% sort() %>% round() |