Hi,
I’m having difficulty fitting the following model - it samples extremely slowly, even though I’ve run models with comparable structure / datapoints / number of parameters before. I suspect it has something to do with the way I’m trying to put random intercepts for subject into the lexicon_intercept and grammar_intercept terms, but I can’t quite figure out what might be going wrong. Any advice for changes (great or small) would be greatly appreciated.
data {
int<lower = 1> N_trials;
int<lower = 1> N_subjects;
int<lower = 1, upper = N_subjects> subject[N_trials];
int<lower = 0,upper = 1> shift_or_not[N_trials];
real frequency[N_trials];
real weight[N_trials];
real know_remote[N_trials];
real cosine_sim[N_trials];
}
parameters {
vector[N_subjects] lexicon_intercept_subject_adjustor;
real lexicon_intercept;
vector[N_subjects] grammar_intercept_subject_adjustor;
real grammar_intercept;
real b_weight;
real b_cosine;
real b_freq;
}
model {
real lexicon ;
real grammar;
real dep;
target += normal_lpdf(lexicon_intercept_subject_adjustor | 0, 2);
target += normal_lpdf(grammar_intercept_subject_adjustor | 0, 2);
target += normal_lpdf(lexicon_intercept | 0, 2);
target += normal_lpdf(grammar_intercept | 0, 2);
target += normal_lpdf(b_weight | 0, 1);
target += normal_lpdf(b_cosine | 0, 1);
target += normal_lpdf(b_freq | 0, 1);
for(n in 1:N_trials){
for (s in 1:N_subjects){
lexicon = (lexicon_intercept+ lexicon_intercept_subject_adjustor[s] + b_freq*frequency[n]+ b_cosine*cosine_sim[n]);
grammar = (grammar_intercept + grammar_intercept_subject_adjustor[s] + b_weight*weight[n]);
dep = inv_logit((know_remote[n] * lexicon)+(know_remote[n] * (1-lexicon) * grammar)+((1-know_remote[n]) * grammar));
shift_or_not[n] ~ bernoulli_logit(dep);
}
}
}
R code is here:
library(rstan)
library(tidyverse)
n_subjects <- simplified_data%>%
select(BetterSubject) %>%
distinct() %>%
summarise(
count = n()
)
data_list_simple <- list(N_trials = nrow(simplified_data),
shift_or_not = simplified_data$shift_or_not,
weight = simplified_data$SWP,
LocalBase = simplified_data$LocalBase.x,
frequency = simplified_data$ZeroFilledRemoteFreq,
know_remote = simplified_data$know_remote,
cosine_sim = simplified_data$ZerpFilledCosineSim,
subject = simplified_data$BetterSubject,
N_subjects = n_subjects$count
)
Data used is here: data.csv (250.2 KB)