cbq {cbq}R Documentation

Fitting conditional binary quantile models

Description

The main function for running the conditional binary quantile model. The function returns a cbq cbq object that can be further investigated using standard functions such as plot, print, coef, and predict.

Usage

cbq(
  formula,
  data,
  q = NULL,
  vi = FALSE,
  nsim = 1000,
  grad_samples = 1,
  elbo_samples = 100,
  tol_rel_obj = 0.01,
  output_samples = 2000,
  burnin = NULL,
  thin = 1,
  CIsize = 0.95,
  nchain = 1,
  seeds = 12345,
  inverse_distr = FALSE,
  offset = 1e-20,
  mc_core = TRUE
)

Arguments

formula

An object of class "Formula" (or one that can be coerced to that class): a symbolic description of the model to be fitted.

data

A data frame containing the variables in the model.

q

The quantile value.

vi

Indicating whether variantional inference should be used instead of MCMC sampling procedure.

nsim

The number of iterations.

grad_samples

Passed to vb (positive integer), the number of samples for Monte Carlo estimate of gradients, defaulting to 1.

elbo_samples

Passed to vb (positive integer), the number of samples for Monte Carlo estimate of ELBO (objective function), defaulting to 100. (ELBO stands for "the evidence lower bound".)

tol_rel_obj

Passed to vb (positive double), the convergence tolerance on the relative norm of the objective, defaulting to 0.01.

output_samples

Passed to vb (positive integer), number of posterior samples to draw and save, defaults to 1000.

burnin

The number of burnin iterations.

thin

Thinning parameter.

CIsize

The size of confidence interval.

nchain

The number of parallel chains.

seeds

Random seeds to replicate the results.

inverse_distr

If FALSE, the ALD will not be reversed. The default is FALSE.

offset

Offset values to enhance sampling stability. The default value is 1e-20.

mc_core

Indicating whether the estimation will be run in multiple parallel chains. The default is TRUE.

Details

The model can be passed either as a combination of a formula and a data frame data, as in lm().

Convergence diagnotics can be performed using either print(object, "mcmc") or plot(object, "mcmc").

Value

A cbq object, which can be further analyzed with its associated plot.cbq, coef.cbq and print.cbq functions.

An object of class cbq contains the following elements

Call

The matched call.

formula

Symbolic representation of the model.

q

The quantile value.

nsim

The number of MCMC iterations.

burnin

The number of burnin periods.

thin

Thinning.

seeds

Random seeds.

CIsize

The size of confidence interval.

data

Data used.

x

Covaraites used.

y

The dependent variable.

xnames

Names of the covariates.

stanfit

Outputs from stan.

sampledf

A matrix of posterior samples.

summaryout

A summary based on posterior samples.

npars

Number of covariates.

ulbs

Lower and upper confidence bounds.

means

Estimates at the mean.

vi

Indicating whether variational inference has been performed.

output_samples

Sample outputs.

fixed_var

Variables estimated using fixed effects.

random_var

Variables estimated using random effects.

xq

Variables indicating the choice sets.

Author(s)

Xiao Lu

References

Lu, Xiao. (2020). Discrete Choice Data with Unobserved Heterogeneity: A Conditional Binary Quantile Model. Political Analysis, 28(2), 147-167. https://doi.org/10.1017/pan.2019.29

Examples

# Simulate the data
x <- rnorm(50)
y <- ifelse(x > 0, 1, 0)
dat <- as.data.frame(cbind(y, x))

# Estimate the CBQ model
model <- cbq(y ~ x, dat, 0.5, nchain = 1, mc_core = FALSE)

# Show the results
print(model)
coef(model)
plot(model)



[Package cbq version 0.2.0.2 Index]