Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WAIC not computing from ulam() model, even with log_lik = TRUE #428

Open
szmoe opened this issue Mar 27, 2024 · 4 comments
Open

WAIC not computing from ulam() model, even with log_lik = TRUE #428

szmoe opened this issue Mar 27, 2024 · 4 comments

Comments

@szmoe
Copy link

szmoe commented Mar 27, 2024

Hello, I've been trying to solve the practice problem from Monte Carlo Chapter, and I can't compute WAIC from ulam model.

N <- 100
height <- rnorm(N,10,2)
leg_prop <- runif(N,0.4,0.5)
leg_left <- leg_prop*height +
    rnorm( N , 0 , 0.02 )
leg_right <- leg_prop*height +
    rnorm( N , 0 , 0.02 )
d <- data.frame(height,leg_left,leg_right)

output <- capture.output(m5.8s2 <- ulam(
  alist(
    height ~ dnorm( mu , sigma ) ,
    mu <- a + bl*leg_left + br*leg_right ,
    a ~ dnorm( 10 , 100 ) ,
    bl ~ dnorm( 2 , 10 ) ,
    br ~ half_normal(1, 10),
    sigma ~ dcauchy( 0 , 1 )
  ),
  data=d, chains=4, start=list(a=10,bl=0,br=1,sigma=1), log_lik = TRUE))

print(WAIC(m5.8s2))

When I run the above code, I got error message:

Error in UseMethod("WAIC") :
no applicable method for 'WAIC' applied to an object of class "ulam" . How do I solve this, please?

@rmcelreath
Copy link
Owner

I don't know what's wrong on your end, but this works fine for me:

m <- ulam(
  alist(
    height ~ dnorm( mu , sigma ) ,
    mu <- a + bl*leg_left + br*leg_right ,
    a ~ dnorm( 10 , 100 ) ,
    bl ~ dnorm( 2 , 10 ) ,
    br ~ half_normal(1, 10),
    sigma ~ dcauchy( 0 , 1 )
  ),
  data=d, chains=4, cores=4 , log_lik = TRUE)

@szmoe
Copy link
Author

szmoe commented Mar 27, 2024

Thank you for the reply. I can run the model and get the precis output, but other than that, I can't do a thing- can't compute waic or do traceplots, etc. So, I have been using brms for the chapter at the moment.

Not sure if it is related but I did this https://discourse.mc-stan.org/t/problem-with-cmdstan-unpacking/29041/5 to get ulam() to work on my Rstudio. Other than that, I followed the book. But, I am using 1st edition of the book, so maybe I miss some new snippets here and there for it to work. Thank you very much.

@rmcelreath
Copy link
Owner

Since map2stan is no longer supported, and the code in the 1st edition is for map2stan, you are going to have some problems. You can't just replace map2stan with ulam unfortunately.

@szmoe
Copy link
Author

szmoe commented Mar 27, 2024

Got it! I will do the exercises with brms at the moment and will try this again when I can get the new edition. Thank you very much :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants