bayeslist {bayeslist} | R Documentation |
Fitting Bayesian sensitive item models
Description
The main function for estimating Bayesian sensitive item models.
The function returns a bayeslist
object that can be further investigated using standard functions such as summary
, plot
, print
, predict
, and coef
. The model can be passed using a formula
as in lm()
. Convergence diagnotics can be performed using either print(object, "mcmc")
or plot(object, "trace")
.
Usage
bayeslist(
formula,
data,
treat,
J,
type = "outcome",
nsim = 1000,
burnin = NULL,
thin = 1,
CIsize = 0.95,
nchain = 1,
seeds = 12345,
vb = FALSE,
only_vb = FALSE,
prior = NULL,
direct_item = NULL,
direct_item_misreport = NULL,
double_list = NULL,
double_list_treat = NULL,
aux_info = NULL,
aux_g = NULL,
aux_h = NULL,
BL_a = NULL,
BL_b = NULL,
conjugate_distance = FALSE,
conjugate_k = NULL,
predictvar = NULL,
predictvar_type = "binary",
parallel = TRUE,
robust = FALSE
)
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. |
treat |
Variable name of the treatment. |
J |
Number of control items. |
type |
Type of the model. Options include "outcome", "predict", "misreport", for the sensitive item outcome model, predictor model and misreport model, respectively. |
nsim |
The number of iterations. |
burnin |
The number of burnin iterations. |
thin |
Thinning parameter. |
CIsize |
The size of posterior confidence interval. |
nchain |
The number of parallel chains. |
seeds |
Random seeds to replicate the results. |
vb |
Logic. If TRUE, variational approximation will be used to supply initial values. The default is FALSE. |
only_vb |
Logic. If TRUE, only variational approximation will be calculated. The default is FALSE. |
prior |
Prior types. Options include "auxiliary", "double_list", "direct_item", and "BL" for beta-logistic prior. If NULL, no informative priors will be used. |
direct_item |
Variable name of the direct item. |
direct_item_misreport |
Variable name of the direct item for the misreporting model. |
double_list |
Variable name of the second list. |
double_list_treat |
Treatment variable of the second list. |
aux_info |
Auxiliary information for the informative priors. list(G,h,g), where: G (number of subgroups), h (auxiliary information for each subgroup), and g (subgroup indicator). If is.NULL, the following two parameters need to be specified when estimating the model with prior = "auxiliary". |
aux_g |
Auxiliary information for the informative priors: name of the variable indicating the group of each observation. |
aux_h |
Auxiliary information for the informative priors: name of the variable containing information of prevalence for each group |
BL_a |
The first shape hyperparameter for the beta-logistic prior, indicating the prior number of affirmative answers to the sensitive item. |
BL_b |
The second shape hyperparameter for the beta-logistic prior, indicating the prior number of non-affirmative answers to the sensitive item. |
conjugate_distance |
Logic. Indicating whether conjugate distance prior should be used. The default is FALSE. |
conjugate_k |
Degrees of freedom to be scaled by conjugate distance prior. The default is NULL. |
predictvar |
Variable name of the outcome to be predicted. |
predictvar_type |
The type of the outcome variable to be predicted. Options include "linear" and "binary". The default is "binary". |
parallel |
Logic. Indicating whether to do paralell computing. The default is TRUE. |
robust |
Logic. Indicating whether to impose robust constraints on the intercept-only model. The default is FALSE. |
Value
A bayeslist
object. An object of class bayeslist
contains the following elements
Call
The matched call.
formula
Symbolic representation of the model.
type
Model type
nsim
Number of iterations.
Burnin
Number of burnin iterations.
thin
Thinning.
seeds
Random seeds for reproducibility. The default is 12345.
CIsize
Size of the posterior confidence interval.
data
Data used.
X
Independent variables.
Y
Dependent variables.
xnames
Names of the independent variables.
stanfit
Output from stan.
sampledf
Posterior samples.
summaryout
Summary of the stan-fit object.
npars
Number of control variables.
only_vb
Whether only viariational approximation is used.
prior
Informative prior types.
direct_item
Direct item.
double_list
The second list.
aux_info
Auxiliary information.
ulbs
Upper and lower bounds based on the specified confidence interval.
means
Mean estimates.
treat
Treatment.
outcome
Outcome to be predicted.
direct
Direct item for the misreport model.
robust
Robust indicator.
References
Lu, X. and Traunmüller, R. (2021). Improving Studies of Sensitive Topics Using Prior Evidence: A Unified Bayesian Framework for List Experiments, SSRN, doi:10.2139/ssrn.3871089.
Examples
# Estimate sensitive item outcome model using Sri Lanka data on male sexual violence
# Load Sri Lanka list experiment data
data(srilanka)
# Model 1: intercept-only outcome model without prior information:
mod1 <- bayeslist(sexaussault ~ 1, data = srilanka, treat = "treatment", J = 3,
type = "outcome", nsim = 200, thin = 1, CIsize = 0.95, nchain = 1,
seeds = 342321, prior = NULL, parallel = TRUE)
summary(mod1) # summary of estimates
predict(mod1) # predicted prevalence for each observation
plot(mod1,"trace") # trace plot
plot(mod1,"coef") # coefficient plot
plot(mod1, only_prev = TRUE) # prevalence plot
# Model 2: multivariate outcome model without prior information:
mod2 <- bayeslist(sexaussault ~ age + edu, data = srilanka, treat = "treatment", J = 3,
type = "outcome", nsim = 200, thin = 1, CIsize = 0.95, nchain = 1,
seeds = 342321, prior = NULL, parallel = TRUE)
summary(mod2) # summary of estimates
predict(mod2) # predicted prevalence for each observation
plot(mod2,"trace") # trace plot
plot(mod2,"coef") # coefficient plot
plot(mod2) # prevalence + coefficient plot
# Model 3: intercept-only outcome model with prior information from medicolegal reports, i.e.,
# with a prior beta-logistic distribution BL(38, 146).
a <- 38; b <-146
mod3 <- bayeslist(sexaussault ~ 1, data = srilanka, treat = "treatment", J = 3,
type = "outcome", nsim = 200, thin = 1, CIsize = 0.95, nchain = 1,
seeds = 342321, prior = "BL", BL_a = a, BL_b = b,, parallel = TRUE)
summary(mod3)
predict(mod3)
plot(mod3,"trace")
plot(mod3,"coef")
plot(mod3, only_prev = TRUE)
# Model 4: multivariate outcome model with prior information from a direct item.
# Load London list experiment data
data(london)
mod4 <- bayeslist(listCount ~ agegrp + gender + social_grade + qual,data = london, J = 4,
treat = "listTreat", seeds = 4597, nsim = 200, nchain = 1,
prior = "direct_item", direct_item = "baselineTurnout")
summary(mod4)
predict(mod4)
plot(mod4,"trace")
plot(mod4,"coef")
plot(mod4)