problem using ulam() and log_lik=TRUE for rethinking package

195 views
Skip to first unread message

Hannah Waterhouse

unread,
Nov 3, 2021, 5:08:22 PM11/3/21
to davi...@googlegroups.com
Hello,
I'm wondering if someone can help me out with an issue I'm having.

I'm using ulam() for a bayesian model and it runs fine when I don't have log_lik=TRUE in it but once I add that in I get an error.

Here is my model:

diverse_f1 <-ulam(alist(
+   grossProd ~ dnorm(mu, sigma),
+   mu <- a +  b*(zScore),
+   zScore~dnorm(mu_x1, sigma_x1),
+   a ~ dnorm(2, 30),
+   b ~ dnorm(0, 100),
+   mu_x1~dnorm(0,100),
+   sigma_x1~dcauchy(0,2),
+   sigma ~ dcauchy(0,2)
+ ),data=d_full_f1,log_lik=TRUE,chains=4 , cores=4 ,start=list( B_impute = rep(0.5,26)))

Here is the error (ran on one chain for debug purposes, see error below....):
no parameter log_lik; sampling not done
no parameter log_lik; sampling not done
no parameter log_lik; sampling not done
no parameter log_lik; sampling not done
here are whatever error messages were returned
[[1]]
Stan model 'anon_model' does not contain samples.

[[2]]
Stan model 'anon_model' does not contain samples.

[[3]]
Stan model 'anon_model' does not contain samples.

[[4]]
Stan model 'anon_model' does not contain samples.

Stan model 'anon_model' does not contain samples.
Error in validObject(.Object) :
  invalid class “ulam” object: invalid object for slot "coef" in class "ulam": got class "NULL", should be or extend class "numeric"
In addition: Warning message:
In .local(object, ...) :
  some chains had errors; consider specifying chains = 1 to debug

Error on one chain:
no parameter log_lik; sampling not done
Stan model 'anon_model' does not contain samples.
Error in validObject(.Object) :
  invalid class “ulam” object: invalid object for slot "coef" in class "ulam": got class "NULL", should be or extend class "numeric"


Any insight would be greatly appreciated!

Best,
Hannah
--
Hannah Waterhouse, PhD 
Pronouns: She/Her
Soils and Biogeochemistry Graduate Group
University of California, Davis

Wesley Brooks

unread,
Nov 4, 2021, 3:03:32 PM11/4/21
to davi...@googlegroups.com
Hi Hannah,
I copied your question to the current D-RUG question forum, where it is more likely to be seen. Here is a link:  https://d-rug.discourse.group/t/stan-error-model-doesnt-sample/1506

I've tried to recreate your specific error, but without luck. It could be because I had to make up some toy data in order to test it. However, I do see at least one problem in your code: Your model includes no parameter called "B_impute", so the bit about "start=list( B_impute = rep(0.5,26))" can't do anything for you - I'd recommend deleting that.

Finally, a lot of people have been having problems with rstan, and it sounds like cmdstanr is generally preferred nowadays. In order to use cmdstanr, run this in R:

remotes::install_github( "stan-dev/cmdstanr" )
library( "cmdstanr" )
install_cmdstan()

Then, add this to your ulam() call, after chains=4: cmdstan=TRUE.

Let me know if that helps.
-W

--
Check out our R resources at https://d-rug.github.io/
And please post questions/comments at https://d-rug.discourse.group/
---
You received this message because you are subscribed to the Google Groups "Davis R Users' Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to davis-rug+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/davis-rug/CAPdpK6LhxnQzcHXpKr-sFqDkbPkBdDUNFPoYOS%2B%2BA%2BbBQ7mJQA%40mail.gmail.com.

Reply all
Reply to author
Forward
0 new messages