rmcelreath/rethinking

ulam fits missing @stanfit slot?

jebyrnes opened this issue · 2 comments

I was working with rethinking for a demo, and found that there is no longer anything in the @stanfit slot with ulam models? Here's a reprex. Using rethinking 2.4.0, cmdstanr 0.7.1,

library(rethinking)
data("reedfrogs")

reedfrogs$d <- scale(reedfrogs$density) |> as.numeric()

reed_bb_mod <- alist(
  # likelihood
  surv ~ dbetabinom(density, prob, theta),
  
  # DGP
  logit(prob) <- a + b*d,
  
  # priors
  a ~ dnorm(0,2),
  b ~ dnorm(0,2),
  theta ~ dexp(1)
)

reed_bb_fit <- ulam(reed_bb_mod, 
                    data=reedfrogs[,c("d", "density", "surv")], 
                    chains = 3)

reed_bb_fit@stanfit

which yields

Error: no slot of name "stanfit" for this object of class "ulam"

I checked what slots are there

> slotNames(reed_bb_fit)
[1] "call"           "model"          "coef"          
[4] "vcov"           "data"           "start"         
[7] "pars"           "formula"        "formula_parsed"

Since the revision that made cmdstanr default, ulam is using attributes for the model objects. You can still extract, but it could be either stanfit or cstanfit, depending upon the call. See: https://github.com/rmcelreath/rethinking/blob/master/R/ulam-function.R#L1547

Thanks!