RStudio/R repeatedly crashes with a fatal error when running brms(), or rather when using plot() on the model produced by brm().
RMarkdown code is pasted here:
---
output:
pdf_document:
toc: true
toc_depth: 4
number_sections: true
html_document:
css: /Users/johnkingston/Dropbox/692F/fall17/lectures/css/Dillon_UMass.css
css: /Users/jkingstn/Dropbox/692F/fall17/lectures/css/Dillon_UMass.css
css: ~/Dropbox/Courses/LING609-Fall2014/Website/Dillon_UMass.css
css: /Users/jkingstn/Dropbox/692F/fall17/lectures/css/Dillon_UMass.css
Reanalysis of the vowel parsing results.
Updates:
14 May 21: Just Exp. 1
14 May 21: Separate analysis of condition to rule out including it in the analysis of the other manipulations.
The results of three experiments assessing the parsing of vowels are reanalyzed here using the brms package. In all three experiments, listeners were presented with short-to-long diphthong-duration continuum in a /C-ai-t/ string in the context of a sentence that had been manipulated to sound as though it were spoken at fast, moderate, or slow rate. In Experiment 1, the initial consonant was a /b/, and listeners were asked to respond that the target consisted of just one syllable, i.e., "Bight," or two, i.e., "Byatt." (Upper case is used here because the sentence conveyed that the responses were surnames.) In Experiment 2, transition durations were manipulated at the beginning of the target stimulus to produce a stop-glide /b-w/ continuum, while in Experiment 3, voice onset times were manipulated instead to produce voiced-voiceless /b-p/ continuum. In both of these latter experiments, listeners chose one from four possible responses on each trial; in Experiment 2, "Bight," "Byatt," "Wight," or "Wyatt," in Experiment 3, "Bight," "Byatt," "Pight," or "Pyatt."
Packages, etc.
#Load packages.
#```{r}
library(parallel)
library(rstan)
library(rstanarm)
library(brms)
library(bayesplot)
library(loo)
library(tidyr)
library(tidyverse)
library(tidybayes)
library(knitr)
library(scales)
require(grid)
require(ggpubr)
require(gsubfn)
library(purrr)
library(ggplot2)
#```
#Set up to save figures, and set options, theme, palette.
#```{r 'setup', echo=FALSE, cache=FALSE}
require("knitr")
opts_knit$set(root.dir = "/Users/jkingstn/Dropbox/current projects/vowel parsing/reanalysis_30jul20")
opts_chunk$set(dev = c("CairoPDF"), fig.align="center", fig.height = 9, fig.width = 8, out.width = "0.95\linewidth", fig.path='figures01/', pdf.options(encoding = "ISOLatin9.enc"))
options
options(digits = 4,
mc.cores = parallel::detectCores())
rstan_options(auto_write = TRUE)
ggplot theme
theme_set(theme_bw())
color-blind palette
cbbPalette <- c("#000000", "#E69F00", "#56B4E9", "#009E73", "#F0E442", "#0072B2", "#D55E00", "#CC79A7")
#```
#Working directory:
```{r, echo=FALSE}
getwd()
```
Prepare the data
Reading in the data.
```{r}
exp1 <- read.csv("bightByattCompiled_30jul20.csv",
header = TRUE,
as.is = TRUE)
head(exp1)
colnames(exp1)
```
#Reformatting.
```{r}
exp1 <- exp1 %>%
gather("slow_030":"fast_130", key = "speedDuration", value = "responses")
```
#Label conditions.
```{r}
exp1$speed <- substr(exp1$speedDuration, 1, 3)
exp1$nSpeed <- ifelse(exp1$speed == "slo", -1,
ifelse(exp1$speed == "fas", 1, 0))
exp1$duration <- as.numeric(substr(exp1$speedDuration, nchar(exp1$speedDuration)-2, nchar(exp1$speedDuration)))
unique(exp1$duration)
head(exp1)
```
#Identify the response and the maximum number of that response per stimulus and subject.
```{r}
exp1 %>% group_by(speed, duration, subject) %>%
summarise(sum(responses))
```
#The response being tallied is "Byatt," i.e., the two syllable response. The maximum number of "Byatt" responses per stimulus and subject is 20. Code below corrects to 20 five cases in which more than 20 "Byatt" responses were given to a stimulus.
```{r}
xtabs(~ responses + duration,
data = exp1)
exp1[exp1$responses > 20,]
exp1$responses <- ifelse(exp1$responses > 20, 20,
exp1$responses)
```
Bayesian Model
Using brms()
.
14 May 21: First, test the effect of condition.
```{r}
exp00 <- brm(
data = exp1,
family = binomial,
control = list(max_treedepth = 20, adapt_delta = 0.99),
responses | trials(20) ~ 1 + condition + (1 | condition/subject),
iter = 4000,
warmup = 1000,
thin = 10,
chains = 4,
cores = 4,
seed = 12
)
plot(exp00)
summary(exp00)