I need help to understand what is inside posterior_samples function (brms R package)

Hello everybody,
I analyzed a 46 dichotomous items matrix using the Bayesian 1PL (brms R package). Here is the synthax I used:

formula_va_1pl <- bf(Xb16 ~ 1 + (1 | It16) + (1 | P16))
prior_va_1pl   <- prior("normal(0, 3)", class = "sd", group = "It16") +  prior("normal(0, 3)", class = "sd", group = "P16")
fit_va_1pl     <- brm(formula = formula_va_1pl,
                 data = X16,
                 family = brmsfamily("bernoulli","logit"),
                 prior = prior_va_1pl)

I wish to extract the MCMC chains of every items under investigation. I find that posterior_samples function need to be used here. For example:

samples <- posterior_samples(fit_va_1pl,)

Nevertheless, I don’t understand clearly what is the specific MCMC chain values for the first chain regarding difficulty of item 4 for example.

                 Thanking you VERY MUCH in advance…

Just to be clear - you are able to access the complete set of samples from all chains, but you need to access the individual chains separately? If so, why would you need this? (if that’s what you want to do, you would need to use rstan::extract or as.matrix.stanfit on the underlying stanfit object, which you should be able to access via fit_va_1pl$fit).

Hope that helps!

I seem to understand your question to be the same as martinmodrak.

In using posterior_samples you get a return of all chains, they are in long form

If you want to add the chain, call

samples <- posterior_samples(fit_va_1pl, add_chain = TRUE)

You then get a column with chain identified.

1 Like