Skip to content

Instantly share code, notes, and snippets.

View gongcastro's full-sized avatar
👁️

Gonzalo García-Castro gongcastro

👁️
View GitHub Profile
@gongcastro
gongcastro / correlaciones_multinivel.R
Created May 18, 2020 19:00
Interpretando matrices de correlación en modelos multinivel con {`lme4`}
# Interpretando matrices de correlación en modelos multinivel usando lme4
# Gonzalo García-Castro, gonzalo.garciadecastro@upf.edu
#### cargar paquetes #######################
library(dplyr) # para manipular variables y usar pipes
library(lme4) # para ajustar modelos mixtos
library(tibble) # para pasar nombres de filas como una columna
library(tidyr) # para pasar de una tabla en formato ancho a una en formato largo
library(janitor) # para limpiar nombres de variables
library(ggplot2) # para viualizar datos
@gongcastro
gongcastro / importing_multiple
Created July 5, 2020 22:31
Accompanying code for my 2020-07-05 post on how to efficiently import and merge multiple datasets in R, comparing several combinations of available functions.
#### 2020-07-05_import-multiple ###########################
# Gonzalo García-Castro, gonzalo.garciadecastro@upf.edu
# Center for Brain and Cognition, Universitat Pompeu Fabra
#### set up ###############################################
# load packages
library(dplyr)
library(tidyr)
library(ggplot2)
library(data.table)
@gongcastro
gongcastro / simulate_eyetracking.R
Created August 12, 2020 08:45
Simulate data to analyse with eyetrackingR.
#### eyetrackingR with simulated data ###################
# Gonzalo García-Castro, gonzalo.garciadecastro@upf.edu
# Center for Brain and Cognition, Universitat Pompeu Fabra
#### set up ##############################################
# load packages
library(dplyr) # for manipulating data
library(tidyr) # for reshaping dataframes
library(eyetrackingR) # for processing eye-tracking data
@gongcastro
gongcastro / waves.R
Created October 26, 2020 16:09
Animated waves using ggplot and gganimate
library(tidyverse)
library(gganimate)
x <- seq(-4*pi, 4*pi, by = pi/50)
k <- seq(4*pi, -4*pi, by = -pi/50)
y <- t(sapply(x, function(x) sin(x-k)))
d <- as.data.frame(cbind(as.matrix(x), y))
colnames(d) <- c("x", k)
d <- pivot_longer(d, -x, "k", values_to = "y") %>%
mutate_at(vars(k), as.numeric)
@gongcastro
gongcastro / mask.R
Last active November 24, 2020 15:21
Compute pairwise orthographic and phonological distance across translation equivalents of "mask"
#### mask ----------------------------------------------------------------------
# import packages
library(tidyverse)
library(readxl)
library(stringdist)
#### import data ---------------------------------------------------------------
# you can download the data from https://drive.google.com/file/d/18SeJTiM2-JXR9SOqEg22wdkvNL3OxG3u/view?usp=sharing
@gongcastro
gongcastro / polynomials.R
Last active January 21, 2021 15:08
Wrappers to generate the data, plots and animations for the post on polynomial regression.
#### 2020-10-17-visualising-polynomial-regression -----
#### set up -------------------------------------------
# load packages
library(tidyverse)
library(gganimate)
library(data.table)
library(magick)
library(here)
@gongcastro
gongcastro / get_childes_frequencies.R
Created July 7, 2021 09:02
Custom function to extract lexical frequencies from the CHILDES corpora.
# extract lexical frequencies from CHILDES
# you may need to install the following packages:
# install.packages(c("dplyr", "stringr", "tidyr", "chidesr"))
get_childes_frequency <- function(
token, # word(s) form to look up, e.g. c("table", "mesa")
languages = c("cat", "spa"), # languages in which to look up the word form
... # other arguments (see ?childesr::get_speaker_statistics)
){
# animate the Beta distribution
# parameter vectors
x = collect(0.01:0.01:0.99); # sampling space
α = collect(0.1:0.1:10);
β = collect(0.1:0.1:10);
# only β=5 is used, but I don't want to mess up the code
# extract probability densities for all combinations of parameters
y = zeros(length(x), length(α), length(β)); # pre-alocate
# get audio duration
# set up ----
library(audio)
library(purrr)
library(dplyr)
library(tidyr)
library(ggplot2)
library(PraatR)
library(stringr)
@gongcastro
gongcastro / CONTRIBUTING.md
Created November 16, 2021 16:10 — forked from briandk/CONTRIBUTING.md
A basic template for contributing guidelines that I adapted from Facebook's open source guidelines

Contributing to Transcriptase

We love your input! We want to make contributing to this project as easy and transparent as possible, whether it's:

  • Reporting a bug
  • Discussing the current state of the code
  • Submitting a fix
  • Proposing new features
  • Becoming a maintainer

We Develop with Github