Error in extract()

Greetings:

I have successfully run my stan code and I am interested in extracting the posterior distribution of my model.

I am receiving the following error:
Error in extract(full_fit.global.inter, pars = “par1”) :
object of type ‘S4’ is not subsettable

However I can successfully extract them with:
junk <- as.data.frame(full_fit.reg.inter, pars=“par1”);

Does anyone have any ideas why I am running into the extract problem? Also Note: I was previously able to extract these values with no problem, but have since then modified my R code making changes which should have no impact running STAN section, just moving sections that occurred after my STAN run into new R codes to simplify my original code, and have also terminated Rstudio (which is my user interface) and restarted - rerun, and received the error when using extract.

Thank you in advance.

I think you are clashing with the extract function in another package. Try using rstan::extract.

1 Like

This is a good idea in general…

Thank you that worked!

I have the same issue with extract function, but it is not related to the source package. Any suggestion? Is this because this is a brm object?

rstan::extract(fit4)
Error in (function (classes, fdef, mtable)  : 
  unable to find an inherited method for function ‘extract’ for signature ‘"brmsfit"’

Also, I don’t seem to be able to extract elements by fit4$chains or any other elements from the brm object. What is the best way to extract the elements of model results.

With a brms object, the actual model fit is in the fit element of the list returned by brm. So, in your case, you would run:

rstan::extract(fit4$fit)

I haven’t used extract before, but I think with a brmsfit object (like fit4) you can get “tidy” draws by running:

d = as_draws_df(fit4)