Thanks, Bob.
On 3/31/2014 5:25 AM, Bob Carpenter wrote:
> On Mar 29, 2014, at 9:45 PM, Linas Mockus <
linasm...@gmail.com> wrote:
>
>> I found the solution for 2-compartmental model in WinBUGS:
>> for (t in 1 : N) {
>> model_c <- B1 * exp (-lambda1 * time [t]) +
>> B2 * exp (-lambda2 * time [t]) +
>> B3 * exp (-ka * time [t]);
>> sigma <- sqrt (sigma_m * sigma_m * model_c * model_c +
>> sigma_a * sigma_a);
>> concentration [t] ~ normal (model_c, sigma);
>> }
>>
>> However for some combination of parameters model_c is negative as well as concentration. When using explicit likelihood function I assign very low number to the likelihood whenever model_c<0 - don't know if it is a good practice but basically I tell the solver not to explore infeasible set of parameters. How to do this in stan?
> Priors on B1, B2, B3 would be the way to go, or even hard constraints
> making them positive if that makes sense for the model. Or equivalently,
> putting them inside the exp() function as additive terms.
>
> There's a square(x) function, by the way, which is a bit more
> efficient than x * x. (And we really need to add normal distributions
> parameterized with variance and precision, which would avoid that
> sqrt operation, too --- it's just going to get squared again inside
> the density!).
>
> You could also constrain concentration to be positive, though you'll
> still get odd behavior with model_c going below 0 (it's symmetric around
> 0 in the sigma term).
> B1, B2, B3 are functions of ka, lambda1, lambda2. Therefore the only
> way I see is to constrain the concentration. If I put hard constraint
> real <lower=0> B then I get:
>
>
>
> Invalid value of B2: Error in function validate transformed params
> N4stan5agrad3varE: B2 is -466692.48703089252:0, but must be greater than
> 0Rejecting proposed initial value with zero density.
>
>
>
> How to constrain concentration to be positive? For the time being I
> will assume that sigma_a=0 although I saw WinBUGS examples which have both multiplicative and additive noise.
>> Also, I generate predictive posterior in generated quantities block:
>> for (t in 1 : N_pred) {
>> model_c <- B1 * exp (-lambda1 * time_pred [t]) +
>> B2 * exp (-lambda2 * time_pred [t]) +
>> B3 * exp (-ka * time_pred [t]);
>> sigma <- sqrt (sigma_m * sigma_m * model_c * model_c +
>> sigma_a * sigma_a);
>> concentration_pred [t] <- normal_rng (model_c, sigma);
>> }
>> For some reason traceplot gives for stanfit object:
>> Error in mcmc.list(x) : Arguments must be mcmc objects
> Could you write back with exactly what you're trying to do and the
> full model? traceplot only works for quantities declared as parameters,
> transformed parameters, or generated quantities.
I am still working on traceplot. I found a way how to plot my own
traces using fit@sim$samples but traceplot is more convenient.
Traceplot stopped working when I upgraded to the latest stan version -
so perhaps generated quantities is not a culprit.
Linas
>