我有一个 Stan 代码,其中一个模型参数取决于另一个参数。我总共有 5 个参数:mu, alpha,beta, gamma, delta。现在 beta 在某种程度上依赖于 alpha——
beta> 1- (alpha/1.17)
.参数块目前看起来像:
parameters{
real<lower=0> mu;
real<lower=0,upper=1.17> alpha;
real beta;
real<lower=1> gamma;
real<lower=0> delta;
}
如何将 beta 的下限放在参数块内?
代码是:
expcode="
functions{
real loglikelihood(int N,
real mu,
real alpha,
real beta,
real gamma,
real delta,
real[] t,
real[] m,
real[] rts,
real magmin,
real tmax,
real betalim){
real tempA;
real sumtermA;
real a;
real tempB;
real final;
sumtermA=log(mu);
for(j in 2:N){
tempA=mu;
for(i in 1:(j-1)){
tempA += beta*(exp(alpha*(m[i]-magmin)))*(gamma - 1) * delta^(gamma- 1) *(1 / (t[j]-t[I]+delta)^gamma);
}
sumtermA += log(tempA);
}
tempB=0;
for(j in 1:N){
tempB += beta*(exp(alpha*(m[j]-magmin)))*(1-((delta^(gamma- 1))/((tmax-t[j]+delta)^(gamma-1))));
}
a= mu*tmax;
final= sumtermA-a-tempB+sum(rts);
return(final);
}
}
data{
int<lower=0> N;
real<lower=0> t[N];
real<lower=0> m[N];
real rts[N];
real<lower=0> tmax;
real<lower=0> magmin;
real<lower=0> betalim;
}
parameters{
real<lower=0> mu;
real<lower=0,upper=betalim> alpha;
real<lower=0> beta;
real<lower=1> gamma;
real<lower=0> delta;
}
model{
mu~normal(1.5,1.5);
alpha~normal(0,0.1);
beta~normal(0,0.1);
gamma~normal(1.12,0.16);
delta~gamma(0.1,0.1);
//likelihood
target+= (loglikelihood(N,mu,alpha,beta,gamma,delta,t,m,rts,magmin,tmax,betalim));
}
"
data<- list(N=300,t=runif(300,0,1),m=runif(300,2,9),rts=runif(300,-3,3),tmax=1,magmin=2,betalim=1.17)