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

Open
#428 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
r
Domain
data

Research direction

The failing call is WAIC() applied to a ulam() fit in the rethinking package, which raises 'no applicable method' because the object class is not handled. Start by checking which WAIC method exists for the stanfit/map classes in R/ and whether the log_lik output from ulam(log_lik = TRUE) is stored where WAIC expects it. Done when WAIC(m5.8s2) returns a value or the docs state the supported path, and this stale thread has a clear answer.

Written by the indexing model from the issue text.

Description

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?

Dominant language
R
Stars
2.4k
Forks
632
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from rmcelreath/rethinking

All issues in rmcelreath/rethinking

Similar issues

More R issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.