| Title: | Conditional Binary Quantile Models |
|---|---|
| Description: | Estimates conditional binary quantile models developed by Lu (2020) <doi:10.1017/pan.2019.29>. The estimation procedure is implemented based on Markov chain Monte Carlo methods. |
| Authors: | Xiao Lu [aut, cre] |
| Maintainer: | Xiao Lu <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.2.0.4 |
| Built: | 2026-05-22 09:59:13 UTC |
| Source: | https://github.com/cran/cbq |
Bayesian estimation of conditional binary quantile models.
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
Stan Development Team (2019). RStan: the R interface to Stan. R package version 2.19.2. https://mc-stan.org
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.
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 )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 )
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 |
elbo_samples |
Passed to |
tol_rel_obj |
Passed to |
output_samples |
Passed to |
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. |
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").
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
CallThe matched call.
formulaSymbolic representation of the model.
qThe quantile value.
nsimThe number of MCMC iterations.
burninThe number of burnin periods.
thinThinning.
seedsRandom seeds.
CIsizeThe size of confidence interval.
dataData used.
xCovaraites used.
yThe dependent variable.
xnamesNames of the covariates.
stanfitOutputs from stan.
sampledfA matrix of posterior samples.
summaryoutA summary based on posterior samples.
nparsNumber of covariates.
ulbsLower and upper confidence bounds.
meansEstimates at the mean.
viIndicating whether variational inference has been performed.
output_samplesSample outputs.
fixed_varVariables estimated using fixed effects.
random_varVariables estimated using random effects.
xqVariables indicating the choice sets.
Xiao Lu
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
# 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)# 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)
Create a table of coefficient results from a cbq object.
## S3 method for class 'cbq' coef(object, ...)## S3 method for class 'cbq' coef(object, ...)
object |
A |
... |
Further arguments passed to or from other methods. |
A table of coefficients with their corresponding lower and upper bounds.
dald calculates probability densities of asymmetric Laplace distributions.
dald(x, mu, p, sigma)dald(x, mu, p, sigma)
x |
Random variable. |
mu |
Position parameter. |
p |
Quantile. |
sigma |
Scale parameter. |
probability density of x.
inverse generates inverse function of any given function.
inverse(f, mu, p, sigma, lower = -10000, upper = 10000)inverse(f, mu, p, sigma, lower = -10000, upper = 10000)
f |
pald function |
mu |
Position parameter. |
p |
Quantile. |
sigma |
Scale parameter. |
lower |
Lower bound. |
upper |
Upper bound. |
inversed pald
circGLM
Check if a predictor is dichotomous, adopted from package circGLM
is.dichotomous(x)is.dichotomous(x)
x |
A character or numerical vector to be tested. |
A logical, TRUE if the x has dummy coding (0, 1),
FALSE otherwise.
pald calculates cumulative densities of asymmetric Laplace distributions.
pald(x, mu, p, sigma)pald(x, mu, p, sigma)
x |
Random variable. |
mu |
Position parameter. |
p |
Quantile. |
sigma |
Scale parameter. |
cumulative probability density of x.
Plot traceplots from a cbq object.
plot_coef.cbq(object, ...)plot_coef.cbq(object, ...)
object |
A |
... |
Additional parameters to be passed to the plot function. |
None.
Plot traceplots from a cbq object.
plot_trace.cbq(object, ...)plot_trace.cbq(object, ...)
object |
A |
... |
Additional parameters to be passed to the traceplot function. |
None.
General plot function for cbq objects, which dispatches the chosen
type of plotting to the corresponding function.
## S3 method for class 'cbq' plot(x, type = "trace", ...)## S3 method for class 'cbq' plot(x, type = "trace", ...)
x |
A |
type |
Character string giving the type of plotting. The options are
|
... |
Additional arguments to be passed to subsequent plot functions. |
None.
Create a vector of predictions from a cbq object.
## S3 method for class 'cbq' predict(object, data, ci = 0.95, ...)## S3 method for class 'cbq' predict(object, data, ci = 0.95, ...)
object |
A |
data |
Data used for prediction. |
ci |
Confidence interval. The default is 0.95. |
... |
Further arguments passed to or from other methods. |
A vector of predictions.
Print cbq coefficients
print_coef.cbq(object, digits = 3)print_coef.cbq(object, digits = 3)
object |
A |
digits |
Number of digits to display. |
None.
This prints a number of diagnostics about the results of a cbq objects
print_mcmc.cbq(object, ...)print_mcmc.cbq(object, ...)
object |
A |
... |
Additional arguments to be passed to the print function. |
None.
cbq object.Print the main results from a cbq object.
print_text.cbq(object, digits = 3)print_text.cbq(object, digits = 3)
object |
A |
digits |
Number of digits to display. |
General print function for cbq objects, which dispatches the chosen type
of printing to the corresponding function.
## S3 method for class 'cbq' print(x, type = "text", ...)## S3 method for class 'cbq' print(x, type = "text", ...)
x |
A |
type |
Character string giving the type of printing, such as
|
... |
Additional arguments to be passed to print functions. |
None.
qald calculates quantiles values of asymmetric Laplace distributions.
qald(y, mu, p, sigma)qald(y, mu, p, sigma)
y |
quantile value. |
mu |
Position parameter. |
p |
Quantile. |
sigma |
Scale parameter. |
quantile value.
rald generates random numbers from asymmetric Laplace distributions.
rald(n, mu, p, sigma)rald(n, mu, p, sigma)
n |
Number of random numbers to be generated. |
mu |
Position parameter. |
p |
Quantile. |
sigma |
Scale parameter. |
random numbers.