Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
........10........20........30........40........50 | |
.......60........70........80........90.......100 | |
......110.......120.......130.......140.......150 | |
......160.......170.......180.......190.......200 | |
......210.......220.......230.......240.......250 | |
......260.......270.......280.......290.......300 | |
......310.......320.......330.......340.......350 | |
......360.......370.......380.......390.......400 | |
......410.......420.......430.......440.......450 | |
......460.......470.......480.......490.......500 |
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
--- | |
title: "MVN + Regression Interactions" | |
author: "Eoin Travers" | |
date: "`r Sys.Date()`" | |
output: html_document | |
--- | |
https://twitter.com/realHollanders/status/1605462357697667072?s=20&t=sfGV7iiPavt6DwCrMdks-w | |
```{r} |
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
# This version is more complicated, but can handle > 2 models and throws an error on non-nested models. | |
import numpy as np | |
from scipy import stats | |
import statsmodels.formula.api as smf | |
import pandas as pd | |
def likelihood_ratio_test(*models): | |
'''Model comparison via likelihood ratio chi-square test | |
See https://en.wikipedia.org/wiki/Likelihood-ratio_test | |
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
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() |
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
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 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 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 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 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) |
NewerOlder