Pairs() returning error on STAN model

rstan version 2.16.2

I am running model 10.3stan in McEalreath’s book Statistical rethinking.

library(rethinking) 
 data(chimpanzees)
 d <- chimpanzees

 m10.3 <- map(
   alist(
     pulled_left ~ dbinom( 1 , p ) ,
     logit(p) <- a + (bp + bpC*condition)*prosoc_left ,
     a ~ dnorm(0,10) ,
     bp ~ dnorm(0,10) ,
     bpC ~ dnorm(0,10)
   ) ,
   data=d )


d2 <- d
 d2$recipient <- NULL
 # re-use map fit to get the formula
 m10.3stan <- map2stan( m10.3 , data=d2 , iter=1e4 , warmup=1000 )
 precis(m10.3stan)  ### this works
 # code 10.13
 pairs(m10.3stan)  ## THIS DOES NOT WORK 

error:Error in linbin2D(x, gpoints1, gpoints2) : object 'F_lbtwod' not found

Any idea what object ‘F_lbtwod’ not found means?

Rversion: 3.4.0
Rstudio: 1.0.143

Thank you

I guess there is no pairs method for a map2stan object. You could do pairs(m10.3stan$stanfit) instead.

I just ran into this earlier today. I think it has to do with the latest R version.

from another project:

This isn’t something I can reproduce, unfortunately. If it persists, please make an issue on github for it: https://github.com/rmcelreath/rethinking/issues

@richard_mcelreath Which version of R are you running? This only started happening to me when I upgraded to 3.4

When I do pairs(m10.3stan$stanfit) I get this error:

Error in m10.3stan$stanfit : $ operator not defined for this S4 class

I haven’t tried it myself but if it’s an S4 class then I would try @ instead of $.

Also, if your model happens to have a lot of parameters I would specify a small subset of them when calling pairs or else the plot can take a long time to render and also be hard to read.

Thanks. When I do

pairs(m10.3stan@stanfit)

I get

 Error in linbin2D(x, gpoints1, gpoints2) : object 'F_lbtwod' not found

Looks like the error @aaronjg mentioned above. Can you successfully use the pairs method with a model fit directly using rstan (rather than rstan via rethinking)? You could test it using one of the example models:

library("rstan")
fit <- stan_demo("eight_schools") # you may be prompted to allow it to download example models
pairs(fit, pars = c("theta[1]", "theta[2]", "lp__"))

This seems to be an old topic, but for those who struggle with the same problem: Reinstalling the KernSmooth package from CRAN solved the problem for me.