Error with "does not contain samples"

1,437 views
Skip to first unread message

Cairo Liu

unread,
Jul 9, 2015, 4:37:49 PM7/9/15
to stan-...@googlegroups.com

Dear Mailing users,

I just started to learn Rstan and I was trying to create a hierarchical model with user-specific parameters. The models looks good at first sight. But I cannot distract the coefficients of the model and it shows the error below:

> print(fit, "mu1")
Stan model 'mymodel' does not contain samples.


I have attached the code and data that I used. 

It will be much appreciated if someone can help me solve this problem. 

Thank you very much. 
Cairo's inquiry.txt
xdata4.csv

Ben Goodrich

unread,
Jul 9, 2015, 6:36:03 PM7/9/15
to stan-...@googlegroups.com, klcai...@gmail.com
On Thursday, July 9, 2015 at 4:37:49 PM UTC-4, Cairo Liu wrote:
> print(fit, "mu1")
Stan model 'mymodel' does not contain samples.

There should have been an earlier ouput to the effect of

Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Exception thrown at line 48:
stan
::math::normal_log: Scale parameter has dimension = 2, expecting dimension = 943; a function was called with arguments of different scalar, array, vector, or matrix types, and they were not consistently sized;  all arguments must be scalars or multidimensional values of the same shape.
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 initial value:
 
Error evaluating the log probability at the initial value.


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

error occurred during calling the sampler
; sampling not done

This is due to the fact that in this line
lambda0 ~ normal(0,sigsq_lambda0);  #the effect of age and gender
lambda0 is of length U and sigsq_lambda0 is of length K1.

Ben


Cairo Liu

unread,
Jul 10, 2015, 10:40:01 PM7/10/15
to stan-...@googlegroups.com
Thank you very much Ben!  I tried to set the length of sigsq_lambda0 to U and it works! Although my computer has not enough capacity to run the model.... it stucks for hours and still can't give me the coefficients. Still, thank you very much! I didn't expect to get my problem solved so soon online. 



On Thursday, July 9, 2015 at 4:37:49 PM UTC-4, Cairo Liu wrote:

Ben Goodrich

unread,
Jul 11, 2015, 12:07:10 AM7/11/15
to stan-...@googlegroups.com, klcai...@gmail.com
On Friday, July 10, 2015 at 10:40:01 PM UTC-4, Cairo Liu wrote:
Thank you very much Ben!  I tried to set the length of sigsq_lambda0 to U and it works! Although my computer has not enough capacity to run the model.... it stucks for hours and still can't give me the coefficients. Still, thank you very much! I didn't expect to get my problem solved so soon online. 

Well, your code has

for(i in 1:U)
 
lambda[i] ~ multi_normal(mu1,Sigma1);

which does 943 multivariate normal evaluations when lambda is not even used elsewhere in the model. So that is probably a mistake, in addition to being inefficient.

Ben

Reply all
Reply to author
Forward
0 new messages