1

このモデルを Stan で実行しようとしていました。私はそれの実行中の JAGS バージョン (高度な自己相関パラメーターを返す) を持っており、おそらく問題なく実行される二重指数 (2 つのレート) の CDF として定式化する方法を知っています。しかし、私はこのバージョンを、類似しているがより複雑なモデルの出発点として使用したいと考えています.

今では、このようなモデルは Stan では不可能ではないかと疑っています。おそらく、ブール値の合計を取ることによって離散性が導入されるため、Stan は勾配を計算できない可能性があります。

これが事実かどうか、またはこのモデルで何か間違った方法で何かを行っているかどうか、誰かが知っていますか? モデルコードの下に表示されるエラーを貼り付けます。

よろしくお願いします

Model:

data {
    int y[11]; 
    int reps[11];
    real soas[11]; 

}
parameters {
    real<lower=0.001,upper=0.200> v1;
    real<lower=0.001,upper=0.200> v2;

}


model {
    real dif[11,96];
    real cf[11];

    real p[11];

    real t1[11,96];
    real t2[11,96];

    for (i in 1:11){
        for (r in 1:reps[i]){     
            t1[i,r]  ~ exponential(v1);
            t2[i,r]  ~ exponential(v2);
            dif[i,r] <-  (t1[i,r]+soas[i]<=(t2[i,r]));

            }
        cf[i] <- sum(dif[i]);
        p[i]  <-cf[i]/reps[i];
        y[i] ~ binomial(reps[i],p[i]); 
    }

}

ここにいくつかのダミーデータがあります:

psy_dat = { 
         'soas' :  numpy.array(range(-100,101,20)),
            'y' :  [47, 46, 62, 50, 59, 47, 36, 13, 7, 2, 1],
         'reps' :  [48, 48, 64, 64, 92, 92, 92, 64, 64, 48, 48]
          }

エラーは次のとおりです。

DIAGNOSTIC(S) FROM PARSER:
Warning (non-fatal): Left-hand side of sampling statement (~) contains a non-linear transform of a parameter or local variable.
You must call increment_log_prob() with the log absolute determinant of the Jacobian of the transform.
Sampling Statement left-hand-side expression:
get_base1(get_base1(t1,i,"t1",1),r,"t1",2) ~ exponential_log(...)
Warning (non-fatal): Left-hand side of sampling statement (~) contains a non-linear transform of a parameter or local variable.
You must call increment_log_prob() with the log absolute determinant of the Jacobian of the transform.
Sampling Statement left-hand-side expression:
get_base1(get_base1(t2,i,"t2",1),r,"t2",2) ~ exponential_log(...)

そして実行時に:

Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
 stan::prob::exponential_log(N4stan5agrad3varE): Random variable is nan:0, but must not be nan!
 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
 Rejecting proposed initial value with zero density.


Initialization between (-2, 2) failed after 100 attempts. 
 Try specifying initial values, reducing ranges of constrained values, or   reparameterizing the model

このモデルの動作する JAGS バージョンを次に示します。

   model {
   for ( n in 1 : N  ) { 
     for (r in 1 : reps[n]){
       t1[r,n] ~ dexp(v1)
       t2[r,n] ~ dexp(v2)
       c[r,n] <- (1.0*((t1[r,n]+durs[n])<=t2[r,n]))
     } 
     p[n] <- max((min(sum(c[,n]) /  (reps[n]),0.99999999999999)),   1-0.99999999999999)) 
     y[n] ~ dbin(p[n],reps[n])
   }

   v1 ~ dunif(0.0001,0.2)
   v2 ~ dunif(0.0001,0.2)
   }

min() と max() に関して: この投稿を参照してください https://stats.stackexchange.com/questions/130978/observed-node-inconsistent-when-binomial-success-rate-exactly-one?noredirect=1 #comment250046_130978 .

4

1 に答える 1