Fixing a parameter value in a Stan model

2,309 views
Skip to first unread message

Tom Wallis

unread,
Jul 18, 2013, 5:27:15 PM7/18/13
to stan-...@googlegroups.com
Hello,

I'm currently trying to fit a quite complex nonlinear model using Stan. Since the parameters are interdependent the fits can fail regularly (most often with
No acceptably small step size could be found. Perhaps the posterior is not continuous?
error occurred during calling the sampler
; sampling not done
).

I'm trying to test reparameterizations and new model configurations. I need to post-process the stan output to examine the fits, and my post-processing functions expect named parameter vectors output by Stan's extract() function.

For development and otherwise, it would be great to be able to fix (i.e. not model) a parameter value, but still have Stan output a vector of "samples" of that value. Is there a simple way to do this in a stan model file?

As a simple example, suppose I'm fitting a model with parameters a, b, and c. In my case I specify priors over the log values of those parameters then exponentiate them for the model fit. 

e.g.:
log_c ~ normal(log(10), 1);
c <- exp(log_c);

** do stuff with c, a and b**

for testing, I'd like to be able to just write:
log_c <- log(10);

but have Stan still output the "parameter" log_c as a vector all of value log(10). Currently I need to alter my post-processing scripts so they don't expect the log_c parameter.

Is there a better way to do this?

Thanks for your help.



Andrew Gelman

unread,
Jul 18, 2013, 5:30:03 PM7/18/13
to stan-...@googlegroups.com
If you want to set a parameter theta to the fixed value A, you could always kluge it via:  theta ~ normal(A,.001);
As you might be aware, you can do this even if your parameter theta already has a prior.  Stan doesn't care, it just adds all the components together to compute the log posterior.

- Andrew

--
You received this message because you are subscribed to the Google Groups "stan users mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to stan-users+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Tom Wallis

unread,
Jul 18, 2013, 5:46:51 PM7/18/13
to stan-...@googlegroups.com
Hi Andrew,

Thanks for the suggestion; I had tried that and it still causes "no acceptably small step size" errors. Fixing the parameters completely seems to allow the model to converge just fine, but makes the post-processing more difficult. 

Tom




--
You received this message because you are subscribed to a topic in the Google Groups "stan users mailing list" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/stan-users/UMl1jWLGkx0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to stan-users+...@googlegroups.com.

Ben Goodrich

unread,
Jul 18, 2013, 6:10:58 PM7/18/13
to stan-...@googlegroups.com
On Thursday, July 18, 2013 5:27:15 PM UTC-4, Tom Wallis wrote:
for testing, I'd like to be able to just write:
log_c <- log(10);

but have Stan still output the "parameter" log_c as a vector all of value log(10). Currently I need to alter my post-processing scripts so they don't expect the log_c parameter.

Is there a better way to do this?

Put it into transformed parameters, even though there is no transformation really

transformed parameters {
  real log_c
;
  log_c
<- log(10);
}

Ben

Bob Carpenter

unread,
Jul 18, 2013, 8:07:21 PM7/18/13
to stan-...@googlegroups.com
Is there a reason you don't just define this
as transformed data?

transformed data {
vector[K] log_c;
log_c <- rep_vector(log(10), K);
}

Why would you want to output a constant vector?

If you only need output, put it in generated quantities.

If you need to use it and have it as output, define
it in transformed data, then definite it again in generated
quantities.

- Bob

Bob Carpenter

unread,
Jul 18, 2013, 8:19:53 PM7/18/13
to stan-...@googlegroups.com
On 7/18/13 5:46 PM, Tom Wallis wrote:
> Hi Andrew,
>
> Thanks for the suggestion; I had tried that and it still causes "no acceptably small step size" errors. Fixing the
> parameters completely seems to allow the model to converge just fine, but makes the post-processing more difficult.

Do your parameters constraints match their effective ranges?

If you define something like theta ~ normal(a,0.001),
then you might want to define theta with a constraint such as:

real<lower=a-0.01, upper=a+0.01> theta;

which should give you +/- 10 sd and make things a bit more
stable.

> On Thu, Jul 18, 2013 at 11:30 PM, Andrew Gelman <gel...@stat.columbia.edu <mailto:gel...@stat.columbia.edu>> wrote:
>
> If you want to set a parameter theta to the fixed value A, you could always kluge it via: theta ~ normal(A,.001);
> As you might be aware, you can do this even if your parameter theta already has a prior. Stan doesn't care, it just
> adds all the components together to compute the log posterior.

Hopefully, it won't come to this.

...
>> e.g.:
>> log_c ~ normal(log(10), 1);
>> c <- exp(log_c);

You have to make sure c doesn't overflow, but that shouldn't be
a problem. But why not just use lognormal on c directly?

- Bob
Reply all
Reply to author
Forward
0 new messages