WAIC and PSIS error

compare( Ass.C , Ass.A , func=WAIC)
compare( Ass.C , Ass.A , func=PSIS)

I got that error for both of them

Error in if (left == var) { : the condition has length > 1

Hi, @May: It’d help to debug if you could give us a reproducible example that defines Ass.C and Ass.A and has the relevant includes.

My model is

xbar<-mean(D$Age)
D$Th14.z <- standardize(D$X14k)
D$cond <- D$Condition + 1
Ass.A<- quap(
    alist(
        D$Th14.z ~ dnorm( mu , sigma ) ,
        mu <- a+b*(Age-xbar),
        a~ dnorm( 0, 0.2) ,
        b~dnorm(0,0.5),
        sigma ~ dexp( 1 )
    ) , data=D )

and the other model is

Ass.C<- quap(
    alist(
        D$Th14.z ~ dnorm( mu , sigma ) ,
        mu <- a[cond]+b[cond]*(Age-xbar),
        a[cond]~ dnorm( 0, 0.2) ,
        b[cond]~dnorm(0,0.5),
        sigma ~ dexp( 1 )
    ) , data=D )

Thanks. Now we just need someone who knows the relevant package like @yuling or @avehtari or @Jonah.

That seems to be rethinking package quap function - RDocumentation

Looking at the documentation quap doesn’t support WAIC or PSIS. I think it’s best to ask @richard_mcelreath (not sure if he visits here) for further help.

quap definitely supports PSIS and WAIC. I suspect the problem is that the model code references the data frame D inside the model formula, which leads to parsing errors. The data frame should never be named in the model formula. Examples below show first that PSIS works and then that referencing data frame in formula leads to error.

data(cars)
flist1 <- alist(
    dist ~ dnorm( mu , sigma ) ,
    mu <- a+b*speed ,
    c(a,b) ~ dnorm(0,1) , 
    sigma ~ dexp(1)
)
fit <- quap( flist1 , start=list(a=40,b=0.1,sigma=20) , data=cars )
PSIS(fit)

flist2 <- alist(
    cars$dist ~ dnorm( mu , sigma ) ,
    mu <- a+b*speed ,
    c(a,b) ~ dnorm(0,1) , 
    sigma ~ dexp(1)
)
fit <- quap( flist2 , start=list(a=40,b=0.1,sigma=20) , data=cars )
PSIS(fit)

Ah, I was mislead by the doc saying

Methods are defined for coef , summary , logLik , vcov , nobs , deviance , link , DIC, and show .

Here DIC is listed, but no PSIS or WAIC.

It finally works when I removed the reference for the data frame.
Thank you very much. I really appreciate your help.