Aggregate posterior draws into subgroups by a factor

subgroup_average_posterior(posterior_samples, groups, weights = NULL)

Arguments

posterior_samples

A matrix of posterior samples, with MCMC draws down the rows

groups

A factor defining the desired subgroups. Must have length ncol(posterior_samples)

weights

Optional weights, for computing a weighted subgroup average

Value

A matrix of size (number of MCMC samples) x (number of subgroups) containing posterior draws of the subgroup averages

Details

Aggregate posterior draws into subgroups by a factor and return a new matrix of posterior draws for the subgroup (weighted) average