Hey all,
I’m replicating a study and am using R and Stan for the first time right now. I want to get the bayes factor comparing two models, but while using Stan to fit them, I get the following error message:
‘’’
SYNTAX ERROR, MESSAGE(S) FROM PARSER:
error in ‘model2bbc2c1011e_model_one’ at line 21, column 15
19: // likelihood
20: for (i in 1:N) {
21: response ~ bIn * ingroupNorm + bBoth * bothShown + bOut * ingroupNorm * bothShown;
^
22: }
PARSER EXPECTED:
Error in stanc(file = file, model_code = model_code, model_name = model_name, :
failed to parse Stan model ‘model_one’ due to the above error.
In addition: Warning message:
In readLines(file, warn = TRUE) :
incomplete final line found on ‘C:\Users\Jens Huth\Desktop\02_main\model_one.stan’
‘’’
these are the two Stan models I tried to come up with:
data {
int<lower=1> N;
int<lower=0,upper=1> ingroupNorm;
int<lower=0,upper=1> bothShown ;
int<lower=1,upper=7> response ;
}
parameters {
real<lower=0> bIn;
real bBoth;
}
transformed parameters{
real<lower=0> bOut = -0.85 / 0.6 * bIn;
}
model{
// priors
bIn ~ normal( 0.6/0.75 * 1.02 , 0.5 );
bBoth ~ normal( 0 , 0.5 );
// likelihood
for (i in 1:N) {
response ~ bIn * ingroupNorm + bBoth * bothShown + bOut * ingroupNorm * bothShown;
}
}
data {
int<lower=1> N;
int<lower=0,upper=1> ingroupNorm;
int<lower=0,upper=1> bothShown ;
int<lower=1,upper=7> response ;
int<lower=0,upper=1> ingroupAgree ;
int<lower=0,upper=1> outgroupDisagree ;
}
parameters {
real<lower=0> bIn;
real bBoth;
}
transformed parameters{
real bOut = -0.85 / 0.6 * bIn;
}
model{
// priors
bIn ~ normal( 0.6/0.75 * 1.02 , 0.5 );
bBoth ~ normal( 0 , 0.5 );
// likelihood
for (i in 1:N) {
response ~ bIn * ingroupNorm * ingroupAgree + bBoth * bothShown + bOut * ingroupNorm * bothShown * outgroupDisagree;
}
}
The priors I want to use are:
bIn, which is suppossed to have anormal distribution with a mean of (0.6/0.75) * 1:02 = 0.816, a standard deviation of 0.5 and restricted to be greater than 0
bBoth as a weakly informative prior, represented by a normal distribution with a mean of 0 and standard deviation of 0.5
bOut, which is a transformation of bIn with bOut = -(0.85/0.6) * bIn
And the models are suppossed to look like the following:
Model 1 = bIn * ingroupNorm + bBoth * bothShown + bOut * ingroupNorm * bothShown
Model 2 = bIn * ingroupNorm * ingroupAgree + bBoth * bothShown + bOut * ingroupNorm * bothShown * outgroupDisagree
And the bayes factor of BF = (Model1 / Model2)
If you need to look at the data or the R code too, here’s our Github link: GitHub - thonor111/XPLab_2021_Group_7
I think the problem is just the syntax error, but as it is my first time working with stan and R, any suggestions on improving the code are also very welcome, gladly with explanation.
Also my first post here so I hope I didn’t do too much wrong.