@Guido_Biele I’m trying to implement this on a very simple model. Your code chunk says yHat[n]
but I’m guessing that is a typo and it should be i
instead of n
. I tried making that change and i get the following error:
SYNTAX ERROR, MESSAGE(S) FROM PARSER:
Probabilty functions with suffixes _lpdf, _lpmf, _lcdf, and _lccdf,
require a vertical bar (|) between the first two arguments.
error in 'model_no_groups_with_weights' at line 21, column 35
-------------------------------------------------
19: }
20: for(i in 1:N){
21: target += normal_lpdf(yHat[i], sigma) * weights[i];
^
22: }
-------------------------------------------------
PARSER EXPECTED: "|"
Then I replaced the ,
for a |
as indicated in the error message, but I got a different error:
error in 'model_no_groups_with_weights' at line 21, column 42
-------------------------------------------------
19: }
20: for(i in 1:N){
21: target += normal_lpdf(yHat[i]|sigma) * weights[i];
^
22: }
-------------------------------------------------
In case is helpful, this is my full stan code:
data {
int<lower=0> N; // number of data items
int<lower=0> K; // number of predictors
vector[N] y; // outcome vector
vector[K] x[N]; // predictor matrix
vector<lower=0>[N] weights; // model weights
}
parameters {
real alpha; // intercept
vector[K] beta; // coefficients for predictors
real<lower=0> sigma; // error sd
}
model {
real yHat[N];
for(i in 1:N){
yHat[i] = alpha + dot_product(x[i], beta);
}
for(i in 1:N){
target += normal_lpdf(yHat[i]|sigma) * weights[i];
}
beta ~ normal(0,1);
}
What am I doing wrong?
Thanks again!