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
# step 1 (before) | |
tmp <- installed.packages() | |
installedpackages <- as.vector(tmp[is.na(tmp[,"Priority"]), 1]) | |
save(installedpackages, file="installed_packages.rda") | |
# now install new version of R | |
# step 2 (after) | |
load("installed_packages.rda") | |
for(i in 1:length(installedpackages)){ |
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 table of required sample sizes for various correlation effect sizes | |
# and various levels of desired power in a study | |
# you need the pwr package | |
library(pwr) | |
# vector of effect sizes to explore | |
effect_sizes <- seq(from = 0.05, to = 0.95, by = 0.05) | |
# vector of desired power |
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
Piece | Start | End | |
---|---|---|---|
Bishop | a4 | e8 | |
Rook | e6 | d5 | |
Bishop | b3 | a4 | |
Knight | h4 | c4 | |
Knight | b1 | d5 | |
Bishop | d6 | b4 | |
Knight | e5 | a1 | |
Queen | g3 | e7 | |
Bishop | b8 | a1 |
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
#------------------------------------------------------------------------------ | |
### Packages & functions | |
library(dplyr) | |
library(afex) | |
library(here) | |
# generate data from a multivariate normal distribution with known | |
# correlations between values | |
mvrnorm <- function(n, nValues, meanValues, sdValues, corMatrix) { |
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(pwr) | |
library(effsize) | |
library(ggplot2) | |
# set "true" effect size and the effect size entered into power analysis | |
true_effect <- 0.2 | |
power_effect <- 1.0 | |
# How many participants required? | |
power_analysis <- pwr.t.test(d = power_effect, |
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
# iterate over starting parameters and assess density----------------- | |
do_fit <- function(current_data){ | |
# mu <- seq(from = 0.2, to = 1.8, by = 0.2) | |
# sigma <- seq(from = 0.05, to = 0.65, by = 0.2) | |
# tau <- seq(from = 0.05, to = 0.85, by = 0.2) | |
mu <- 0.5 | |
sigma <- 0.05 |
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
# sample size | |
n <- 500 | |
# simulate data for each predictor | |
# (note predictor b is categorical) | |
predictor_a <- rnorm(n, 0, 1) | |
predictor_b <- rbinom(n, 1, .5) | |
# population-level beta values | |
b_predictor_a <- -0.20 |
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) | |
library(rstan) | |
rstan_options(auto_write = TRUE) | |
#--- declare the data | |
# n_c = total number of people who drink caffeine | |
# n_nc = total number of people who do not drink caffeine | |
# p_c = observed proportion of people who drink caffeine that have a favourite mug | |
# p_nc = observed proportion of people who drink caffeine that DO NOT have a favourite mug | |
stan_data <- list( |
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
mod_1 <- brm(value ~ questionnaire * condition, | |
data = idealised_data, | |
seed = 42, | |
cores = 4) | |
mod_2 <- brm(value ~ questionnaire + condition, | |
data = idealised_data, | |
seed = 42, | |
cores = 4) |
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
# gaussian kernel function | |
gaussian_kernel <- function(u){ | |
(1 / sqrt(2 * pi)) * exp(-0.5 * u ^ 2) | |
} | |
# kernel density estimate function | |
kde <- function(n, data, x_limit, y_limit, h_x, h_y){ | |
x <- seq(from = x_limit[1], |