willte
July 26, 2019, 11:38am
1
If I write the following:
parameters {
vector[5] beta;
}
model {
//priors
beta ~ normal(0,1);
beta[3] ~ normal(1,1);
}
Does this put a prior of N(0,1) on beta coefficients 1,2,4,5 and N(1,1) on beta coefficient 3?
In other words, does the final line override the prior specified for beta[3]
in the penultimate line?
1 Like
Technically, the sampling statements
beta ~ normal(0,1);
beta[3] ~ normal(1,1);
are largely equivalent to
target += normal_lpdf(beta | 0,1);
target += normal_lpdf(beta[3] | 1,1);
with the exception that the former statements drop constant terms in the target log probability density.
So, no, there’s no overriding. target
is incremented by both normal_lpdf(beta[3] | 0,1)
and normal_lpdf(beta[3] | 1,1)
.
3 Likes
It seems that it is not doing what you are looking for:
edit: @jjramsey explains why it does not work like this.
parameters {
vector[5] beta;
real beta3_I_want;
}
model {
//priors
beta ~ normal(0,1);
beta[3] ~ normal(1,1);
beta3_I_want ~ normal(1,1);
}
Maybe you can use an index?
in this case index <- c(1,2,4,5)
.
data {
int P;
int index[P];
}
parameters {
vector[5] beta;
real beta3_I_want;
}
model {
//priors
beta[index] ~ normal(0,1);
beta[3] ~ normal(1,1);
beta3_I_want ~ normal(1,1);
}
1 Like
willte
July 26, 2019, 12:53pm
4
Really helpful responses, thanks.
I will work with @tiagocc solution for now. One follow up, there is no way to directly write the indices in stan rather than pass them as data in the data
block? Something like this:
model {
beta[1,2,4,5] ~ normal(0,1)
beta[3] ~ normal(1,1)
}
(I’ve tried that particular solution and it generates a syntax error)
I would like to avoid writing something like this:
model {
beta[1] ~ normal(0,1)
beta[2] ~ normal(0,1)
beta[3] ~ normal(1,1)
beta[4] ~ normal(0,1)
beta[5] ~ normal(0,1)
}
What about this?:
model {
beta[1:2] ~ normal(0,1)
beta[3] ~ normal(1,1)
beta[4:5] ~ normal(0,1)
}