Skip to content

Instantly share code, notes, and snippets.

View jvcasillas's full-sized avatar

Joseph V. Casillas jvcasillas

View GitHub Profile
@jvcasillas
jvcasillas / ddm_sims.R
Created December 21, 2021 03:31
ddm_sims
library(tidyverse)
# DDM simulation function
sim_ddm <- function(drift_rate, boundary_separation, bias, ndt, n_sims, seed = NULL) {
set.seed(seed)
sim_df = NULL
for (sim in 1:n_sims){
step = 1
value = bias
n = 1
task_comp_plot <- task_comp %>%
mutate(., phon = fct_recode(phon, "/b/" = "b", "/d/" = "d", "/g/" = "g",
"/p/" = "p", "/t/" = "t", "/k/" = "k"),
phon = fct_relevel(phon, '/b/', '/d/', '/g/',
'/p/', '/t/', '/k/')) %>%
ggplot(., aes(x = phon, y = vot_scaled, group = task_sum)) +
geom_hline(yintercept = 0, lty = 3) +
stat_interval(aes(y = .prediction), data = task_preds,
position = position_dodge(0.5)) +
stat_pointinterval(aes(y = .value, fill = factor(task_sum)),
@jvcasillas
jvcasillas / vowel_space.tex
Created October 7, 2019 00:32
Vowel space in TiKz
% !TEX encoding = UTF-8 Unicode
\documentclass[convert={density=400,size=500x500,outext=.png}]{standalone}
\usepackage{tikz}
\usetikzlibrary{backgrounds}
% \usepackage[active,tightpage,psfixbb]{preview}
\usepackage{tipa}
% \PreviewEnvironment{pgfpicture}
% \setlength\PreviewBorder{2pt}
df_pm %>%
mutate(., grade = fct_relevel(grade, "pk3", "pk4", "kin", "1st")) %>%
ggplot(., aes(x = grade, y = response, color = group)) +
facet_grid(. ~ language) +
stat_summary(fun.data = mean_cl_boot, geom = 'pointrange', size = 1.5,
position = position_dodge(0.5), pch = 21, fill = "white") +
ylim(0, 1)
# GAM analysis -----------------------------------------------------------------
#
# Resources:
# - https://arxiv.org/abs/1703.05339
# - https://github.com/soskuthy/gamm_intro
# set modality to ordered variable and relevel so production is reference
prodShadow_gamm <- prodShadow %>%
filter(., group == 'midd', picName == 0,
@jvcasillas
jvcasillas / tost_ex.R
Created February 21, 2019 18:29
Example of two one-sided t tests (to test equivalence)
# Load libraries
library("tidyverse")
library("TOSTER")
# Set seed for reproducibility
set.seed(10)
# Working memory means for 3 groups
wm_n <- rnorm(mean = 8.67, sd = 1.15, n = 12)
wm_nin <- rnorm(mean = 9.04, sd = 2.11, n = 26)
@jvcasillas
jvcasillas / vowel_plot_example.R
Last active January 22, 2018 02:25
Example for plotting vowels using ggplot
# Plot vowel formants
# - Include elipses,
# - group/vowel means
# - greyscale
# Load tidyverse and phonR package (I choose this because you said you
# had alrady used it)
library(phonR)
library(tidyverse)
@jvcasillas
jvcasillas / euc.dist
Created April 11, 2015 22:43
Euclidean distance
euc.dist <- function(x1, x2){
x <- sqrt(sum((x1 - x2)^2))
return(x)
}
@jvcasillas
jvcasillas / dPrime
Last active August 29, 2015 14:11
dPrime
#####################################
# Functions for linguistic research #
# Joseph V. Casillas #
# Last update: 12-10-2014 #
#####################################
# Calculate d prime in discrimination experiments.
# Takes a df with the columns:
# - stimDiff (actual stimuli are different)
# - stimSame (actual stimuli are the same)
@jvcasillas
jvcasillas / ident_sigmoid
Created May 14, 2014 17:24
ident_sigmoid
# Plot Spectrum Proportion
my_data$group <- factor(my_data$group, levels = c("EL", "NE", "LL"))
df<-with(my_data, aggregate(fpro, list(group=group, fstim=fstim), mean))
df$se<-with(my_data, aggregate(fpro, list(group=group, fstim=fstim), function(x) sd(x)/sqrt(10)))[,3]
gp<-ggplot(df, aes(x=fstim, y=x, colour=group, ymin=x-se, ymax=x+se))
gp +geom_line(aes(linetype=group), size = .4) +
geom_point(aes(shape=group)) +
geom_ribbon(alpha = 0.15, linetype=0) +
#geom_errorbar(aes(ymax=x+se, ymin=x-se)) +
ylim(0, 1) +