svyBayesmod {AuxSurvey} | R Documentation |
Bayesian Survey Model Estimation
Description
This function fits a Bayesian model using Stan for survey data. It allows you to specify the outcome formula, the function for Stan, and apply different types of survey analysis, including weighted or unweighted models, for both sample and population data. The function supports posterior estimation, confidence intervals (CIs), and MCMC diagnostics.
Usage
svyBayesmod(
svysmpl,
svypopu,
outcome_formula,
BayesFun,
subset = NULL,
family = gaussian(),
invlvls,
weights = NULL,
nskip = 1000,
npost = 1000,
nchain = 4,
printmod = TRUE,
doFigure = FALSE,
useTrueSample = FALSE,
stan_verbose = FALSE,
HPD_CI = FALSE,
seed = NULL
)
Arguments
svysmpl |
A dataframe or tibble representing the sample data ( |
svypopu |
A dataframe or tibble representing the population data ( |
outcome_formula |
A formula for Stan, specifying the outcome and predictors in the model. |
BayesFun |
The name of the Stan function to be used for fitting the Bayesian model. |
subset |
A character vector representing filtering conditions to select subsets of the sample and population.
Default is |
family |
The distribution family for the outcome variable. Currently, the following options are supported:
|
invlvls |
A numeric vector specifying the confidence levels for the credible intervals (CIs). If more than one value is specified, multiple CIs will be calculated. |
weights |
A numeric vector of case weights. The length of this vector should match the number of cases in |
nskip |
An integer specifying the number of burn-in iterations for each chain in the MCMC for Stan models. Default is 1000. |
npost |
An integer specifying the number of posterior sampling iterations for each chain in the MCMC for Stan models. Default is 1000. |
nchain |
An integer specifying the number of MCMC chains for Stan models. Default is 4. |
printmod |
A logical scalar; if |
doFigure |
A logical scalar; if |
useTrueSample |
A logical scalar; if |
stan_verbose |
A logical scalar; if |
HPD_CI |
A logical scalar; if |
seed |
An integer specifying the random seed for reproducibility. Default is |
Value
A list containing the Bayesian estimates and confidence intervals (CIs) for each subset or the entire dataset.
Each element in the list includes:
- estimate
: The Bayesian point estimate for the outcome.
- CI
: The credible intervals for the outcome estimate.
- Other elements based on the specified confidence levels in invlvls
.
Examples
## Example usage with survey data:
## Simulate sample and population data
data = simulate(N = 3000, discretize = 3, setting = 3, seed = 123)
population = data$population # Get population data
samples = data$samples # Get sample data
ipw = 1 / samples$true_pi # Compute inverse probability weights
## Define outcome formula and Stan function
outcome_formula = "Y1 ~ Z1 + Z2 + Z3 + (1|auX_3)"
BayesFun = "stan_glmer"
## Fit Bayesian model using weighted survey data
bayes_model = svyBayesmod(svysmpl = samples, svypopu = population,
outcome_formula = outcome_formula,
BayesFun = BayesFun, weights = ipw,
family = gaussian(), nskip = 2000, npost = 2000,
nchain = 2, printmod = TRUE, invlvls = 0.95, stan_verbose = TRUE)