Stan model does not contain samples

Now I have create a stan file named as moments.stan .The stan file is syntactically correct , but when I run the R software , Stan model ‘moments’ does not contain samples. What I should do ?Thank you so much.

Hi @xiaodi321,

This can happen for many reasons so it would be best if you could share the Stan model and small reproducible example. In this way, we can help you figure out what the problem is.

Cheers

Ok,thank you a lot . I hope you can give me some uesful advices.
My main is to estimate the beta using generalized methods of moment.

Thank you very much@tiagocc ,I want to know that is there an error in using the stan function in the R program. The parameter I want to estimate is the vector beta,so are there any questions?

Your inits function does not return anything. It should return a named list, so you can correct it to

inits <- function(){
  list(beta = beta_init0)
}

I am so sorry .I made a great mistake ,thank you so much @jtimonen.Futhermore ,when I try it ,there is also the same result.

There is warning message :“Log probability evaluates to log(0), i.e. negative infinity.”,what I should do ?
Thank you very much.

You had

  cov_onepart =rep_matrix(0,p,p);
  for (i in 1:n){
    tm=col(m,i);
    cov_onepart_o +=tm*tm';
  }

and cov_onepart_o was not set to any value. I think you should have

  cov_onepart_o =rep_matrix(0,p,p);
  for (i in 1:n){
    tm=col(m,i);
    cov_onepart_o +=tm*tm';
  }

I am so carelessness,thank you for your help .Now I have solve the problem.

bhm_5rp_JL.stan (18.3 KB)
twin_bhm_JL.R (2.1 KB)

Hi there,

I receive the following error messages when I run the stan and R files attached:

Stan model ‘anon_model’ does not contain samples.

And in the progress window I get:

Chain 1: Rejecting initial value:
Chain 1: Log probability evaluates to log(0), i.e. negative infinity.

Can someone please advise?

Thanks in advance!

With such a complex model, this is not something that is going to be easy for an external user to debug. The best approach here is to either start with a simpler model and iteratively add complexity until you encounter the issue, or add print("lp = ", target()) statements at various points in your model to identify the section of the code where the log-probability evaluates to log(0)

Thank you! That makes sense. I’ll give that a try.