Hi there,

I am pretty new to R/RStan, so apologies in advance if this doesn’t make much sense. I have uploaded the RStan file I have been using to this post. When I run the following R code:

library(readr)

library(“rstan”)

options(mc.cores=parallel::detectCores())

rstan_options(auto_write = TRUE)

setwd(“c:/Users/jlevy/Dropbox (Sydney Uni)/Twins reference point/Analysis_XW/twin data/BHM”)

library(readxl)

sample ← read_csv(“/Users/jlevy/Dropbox (Sydney Uni)/Twins reference point/Analysis_XW/twin data/BHM/for_rstan_JL.csv”)

N=nrow(sample)

nsubj=max(sample[‘sid’])

subjs=unlist(sample[‘sid’])

choices=unlist(sample[‘chosea’])

x1a=unlist(sample[‘x1a’])

x2a=unlist(sample[‘x2a’])

x3a=unlist(sample[‘x3a’])

x4a=unlist(sample[‘x4a’])

x1b=unlist(sample[‘x1b’])

x2b=unlist(sample[‘x2b’])

x3b=unlist(sample[‘x3b’])

x4b=unlist(sample[‘x4b’])

p1a=unlist(sample[‘p1a’])

p2a=unlist(sample[‘p2a’])

p3a=unlist(sample[‘p3a’])

p4a=unlist(sample[‘p4a’])

p1b=unlist(sample[‘p1b’])

p2b=unlist(sample[‘p2b’])

p3b=unlist(sample[‘p3b’])

p4b=unlist(sample[‘p4b’])

sid=unlist(sample[‘sid’])

sq=unlist(sample[‘sq’])

eva=unlist(sample[‘eva’])

evb=unlist(sample[‘evb’])

maxmin=unlist(sample[‘maxmin’])

minmax=unlist(sample[‘minmax’])

xatmaxp=unlist(sample[‘xatmaxp’])

fit<- stan(file=‘bhm_5rp_JL.stan’,

data=list(N=N,nsubj=nsubj,subjs=subjs,choices=choices,x1a=x1a,x2a=x2a,x3a=x3a,x4a=x4a,

x1b=x1b,x2b=x2b,x3b=x3b,x4b=x4b,p1a=p1a,p2a=p2a,p3a=p3a,p4a=p4a,p1b=p1b,p2b=p2b,p3b=p3b,p4b=p4b,sid=sid,sq=sq,eva=eva,evb=evb,maxmin=maxmin,minmax=minmax,xatmaxp=xatmaxp),

warmup=2500,

chains=4,

iter=10000,

init_r=1,

verbose=FALSE)

print(fit)

fit_ss ← extract(fit,permuted=TRUE)

I get the following error message:

**Error in stanc(file = file, model_code = model_code, model_name = model_name, : ****

** parser failed badly

Can someone please advise?

Thanks in advance!

bhm_5rp_JL.stan (18.3 KB)