Learn R Programming

pumBayes (version 1.0.2)

post_rank: Generate Quantile Ranks for Legislators

Description

This function calculates quantile ranks for each legislator based on posterior samples of beta parameters from MCMC. The function can handle any specified quantiles, such as median (0.5), and is flexible to support other quantiles provided as input.

Usage

post_rank(beta, quantiles = c(0.5))

Value

A data frame containing the legislators' names, party affiliations, states, and their ranks at each specified quantile. If the median is included, it will be named `median` in the output. The output data frame is sorted in ascending order based on the values in the median column.

Arguments

beta

A matrix of posterior samples of beta obtained from MCMC, with columns representing legislators.

quantiles

A numeric vector specifying the quantiles to be calculated for the ranks (default is `c(0.5)` for median rank).

Examples

Run this code
data(h116)
h116.c = preprocess_rollcall(h116)
hyperparams <- list(beta_mean = 0, beta_var = 1, alpha_mean = c(0, 0),
                    alpha_scale = 5, delta_mean = c(-2, 10), delta_scale = sqrt(10))
control <- list(num_iter = 2, burn_in = 0, keep_iter = 1, flip_rate = 0.1)
h116.c.pum <- sample_pum_static(h116.c, hyperparams,
                                  control, pos_leg = grep("SCALISE", rownames(h116.c$votes)),
                                  verbose = FALSE, pre_run = NULL, appended = FALSE)
h116.c.beta.pum.rank = post_rank(beta = h116.c.pum$beta, quantiles = c(0.5))

Run the code above in your browser using DataLab