Hello everyone,
I’m new to Stan, and looking at the blog or documentation, I haven’t found the answer to my question.
I would like to have a simple linear model with one independent variable. I can’t measure exactly the independent variable values, but I can put them in bins and I can estimate a rough distribution for these bins.
What is the best way to do that in stan?
I was thinking at something like:
data {
int N;
vector[N] dependent_oserved;
vector[N] independent_cat;
}
parameters {
real<lower=0> b0;
real b1;
vector<lower=0, upper=1>[N] independent;
vector[N] dependent;
}
model {
b0 ~ normal(0,10);
b1 ~ normal(0,10);
for (i in 1:N) {
if (independent_cat[i] == 'factor_1') {
independent[i] ~ normal(1,0.45);
}
if (independent_cat[i] == 'factor_2') {
independent[i] ~ normal(1,5);
}
}
dependent_oserved ~ normal(dependent,.5);
dependent ~ normal(b0 + b1*independent, 10);
}"
But how could I implement this in stan? Or is there a better way to approach this problem?
Best regards
Luca