| Title: | Bayesian Probit Choice Modeling |
|---|---|
| Description: | Bayes estimation of probit choice models in cross-sectional and panel settings. The package can analyze binary, multivariate, ordered, and ranked choices, as well as heterogeneity of choice behavior among deciders. The main functionality includes model fitting via Gibbs sampling, tools for convergence diagnostic, choice data simulation, in-sample and out-of-sample choice prediction, and model selection using information criteria and Bayes factors. The latent class model extension facilitates preference-based decider classification, where the number of latent classes can be inferred via the Dirichlet process or a weight-based updating heuristic. This allows for flexible modeling of choice behavior without the need to impose structural constraints. For a reference on the method, see Oelschlaeger and Bauer (2021) <https://trid.trb.org/view/1759753>. |
| Authors: | Lennart Oelschläger [aut, cre] (ORCID: <https://orcid.org/0000-0001-5421-9313>), Dietmar Bauer [ctb] (ORCID: <https://orcid.org/0000-0003-2920-7032>) |
| Maintainer: | Lennart Oelschläger <[email protected]> |
| License: | GPL-3 |
| Version: | 1.2.0.9000 |
| Built: | 2026-06-03 06:56:40 UTC |
| Source: | https://github.com/loelschlaeger/rprobitb |
In {RprobitB}, alternative specific covariates must be named in the
format "<covariate>_<alternative>". This helper function generates the
format for a given choice_data set.
as_cov_names(choice_data, cov, alternatives)as_cov_names(choice_data, cov, alternatives)
choice_data |
[ |
cov |
[ |
alternatives |
[ |
The choice_data input with updated column names.
data("Electricity", package = "mlogit") cov <- c("pf", "cl", "loc", "wk", "tod", "seas") alternatives <- 1:4 colnames(Electricity) Electricity <- as_cov_names(Electricity, cov, alternatives) colnames(Electricity)data("Electricity", package = "mlogit") cov <- c("pf", "cl", "loc", "wk", "tod", "seas") alternatives <- 1:4 colnames(Electricity) Electricity <- as_cov_names(Electricity, cov, alternatives) colnames(Electricity)
This function checks the input form.
check_form(form, re = NULL, ordered = FALSE)check_form(form, re = NULL, ordered = FALSE)
form |
[
Multiple covariates (of one type) are separated by a In the ordered probit model ( |
re |
[ |
ordered |
[ |
A list that contains the following elements:
The input form.
The name choice of the dependent variable in form.
The input re.
A list vars of three character vectors of covariate names of
the three covariate types.
A boolean ASC, determining whether the model has ASCs.
overview_effects() for an overview of the model effects
This function checks the compatibility of submitted parameters for the prior distributions and sets missing values to default values.
check_prior( P_f, P_r, J, ordered = FALSE, mu_alpha_0 = numeric(P_f), Sigma_alpha_0 = 10 * diag(P_f), delta = 1, mu_b_0 = numeric(P_r), Sigma_b_0 = 10 * diag(P_r), n_Omega_0 = P_r + 2, V_Omega_0 = diag(P_r), n_Sigma_0 = J + 1, V_Sigma_0 = diag(J - 1), mu_d_0 = numeric(J - 2), Sigma_d_0 = diag(J - 2) )check_prior( P_f, P_r, J, ordered = FALSE, mu_alpha_0 = numeric(P_f), Sigma_alpha_0 = 10 * diag(P_f), delta = 1, mu_b_0 = numeric(P_r), Sigma_b_0 = 10 * diag(P_r), n_Omega_0 = P_r + 2, V_Omega_0 = diag(P_r), n_Sigma_0 = J + 1, V_Sigma_0 = diag(J - 1), mu_d_0 = numeric(J - 2), Sigma_d_0 = diag(J - 2) )
P_f |
[ |
P_r |
[ |
J |
[ |
ordered |
[ |
mu_alpha_0 |
[ |
Sigma_alpha_0 |
[ |
delta |
[ |
mu_b_0 |
[ |
Sigma_b_0 |
[ |
n_Omega_0 |
[ |
V_Omega_0 |
[ |
n_Sigma_0 |
[ |
V_Sigma_0 |
[ |
mu_d_0 |
[ |
Sigma_d_0 |
[ |
A priori-distributions:
for all
for all
An object of class RprobitB_prior, which is a list containing all
prior parameters.
check_prior(P_f = 1, P_r = 2, J = 3, ordered = TRUE)check_prior(P_f = 1, P_r = 2, J = 3, ordered = TRUE)
This function returns the choice probabilities of an RprobitB_fit
object.
choice_probabilities(x, data = NULL, par_set = mean)choice_probabilities(x, data = NULL, par_set = mean)
x |
An object of class |
data |
Either |
par_set |
Specifying the parameter set for calculation and either
|
A data frame of choice probabilities with choice situations in rows and
alternatives in columns. The first two columns are the decider identifier
"id" and the choice situation identifier "idc".
data <- simulate_choices(form = choice ~ covariate, N = 10, T = 10, J = 2) x <- fit_model(data) choice_probabilities(x)data <- simulate_choices(form = choice ~ covariate, N = 10, T = 10, J = 2) x <- fit_model(data) choice_probabilities(x)
This function classifies the deciders based on their allocation to the components of the mixing distribution.
classification(x, add_true = FALSE)classification(x, add_true = FALSE)
x |
An object of class |
add_true |
Set to |
The relative frequencies of which each decider was allocated to the classes during the Gibbs sampling are displayed. Only the thinned samples after the burn-in period are considered.
A data.frame.
The row names are the decider identifiers.
The first C columns contain the relative frequencies with which the deciders are allocated to classes. Next, the columnest' contains the
estimated class of the decider based on the highest allocation frequency.
If add_true = TRUE, the next column true contains the true class
memberships.
update_z() for the updating function of the class allocation vector.
This function extracts the estimated model effects.
## S3 method for class 'RprobitB_fit' coef(object, ...) ## S3 method for class 'RprobitB_coef' print(x, ...) ## S3 method for class 'RprobitB_coef' plot(x, sd = 1, het = FALSE, ...)## S3 method for class 'RprobitB_fit' coef(object, ...) ## S3 method for class 'RprobitB_coef' print(x, ...) ## S3 method for class 'RprobitB_coef' plot(x, sd = 1, het = FALSE, ...)
object |
An object of class |
... |
Currently not used. |
x |
An object of class |
sd |
[ |
het |
[ |
An object of class RprobitB_coef.
This function computes the probability for each observed choice at the (normalized, burned and thinned) samples from the posterior.
These probabilities are required to compute the WAIC and the
marginal model likelihood mml.
compute_p_si(x, ncores = parallel::detectCores() - 1, recompute = FALSE)compute_p_si(x, ncores = parallel::detectCores() - 1, recompute = FALSE)
x |
An object of class |
ncores |
[ If set to 1, no parallel backend is used. |
recompute |
[ |
The object x, including the object p_si, which is a matrix of
probabilities, observations in rows and posterior samples in columns.
This helper function returns the estimated covariance matrix of the mixing distribution.
cov_mix(x, cor = FALSE)cov_mix(x, cor = FALSE)
x |
An object of class |
cor |
[ |
The estimated covariance matrix of the mixing distribution. In case of multiple classes, a list of matrices for each class.
This function creates lagged choice covariates from the data.frame
choice_data, which is assumed to be sorted by the choice occasions.
create_lagged_cov(choice_data, column = character(), k = 1, id = "id")create_lagged_cov(choice_data, column = character(), k = 1, id = "id")
choice_data |
[ |
column |
[ |
k |
[ |
id |
[ |
Say that choice_data contains the column column. Then, the
function call
create_lagged_cov(choice_data, column, k, id)
returns the input choice_data which includes a new column named
column.k. This column contains for each decider (based on id)
and each choice occasion the covariate faced before k choice
occasions. If this data point is not available, it is set to
NA. In particular, the first k values of column.k will
be NA (initial condition problem).
The input choice_data with the additional columns named
column.k for each element column and each number k
containing the lagged covariates.
choice_data <- data.frame(id = rep(1:2, each = 3), cov = LETTERS[1:6]) create_lagged_cov(choice_data, column = "cov", k = 1:2)choice_data <- data.frame(id = rep(1:2, each = 3), cov = LETTERS[1:6]) create_lagged_cov(choice_data, column = "cov", k = 1:2)
Transform increments to thresholds
d_to_gamma(d)d_to_gamma(d)
d |
[ |
The threshold vector of length J + 1.
d_to_gamma(c(0, 0, 0))d_to_gamma(c(0, 0, 0))
This function performs MCMC simulation for fitting different types of probit models (binary, multivariate, mixed, latent class, ordered, ranked) to discrete choice data.
fit_model( data, scale = "Sigma_1,1 := 1", R = 1000, B = R/2, Q = 1, print_progress = getOption("RprobitB_progress", default = TRUE), prior = NULL, latent_classes = NULL, fixed_parameter = list(), save_beta_draws = FALSE )fit_model( data, scale = "Sigma_1,1 := 1", R = 1000, B = R/2, Q = 1, print_progress = getOption("RprobitB_progress", default = TRUE), prior = NULL, latent_classes = NULL, fixed_parameter = list(), save_beta_draws = FALSE )
data |
An object of class |
scale |
[ |
R |
[ |
B |
[ |
Q |
[ |
print_progress |
[ |
prior |
[ |
latent_classes |
[
The following specifications are used for the weight-based updating scheme:
|
fixed_parameter |
[ See the vignette on model definition for definitions of these variables. |
save_beta_draws |
[ |
An object of class RprobitB_fit.
prepare_data() and simulate_choices() for building an
RprobitB_data object
update() for estimating nested models
transform() for transforming a fitted model
set.seed(1) form <- choice ~ var | 0 data <- simulate_choices(form = form, N = 100, T = 10, J = 3, re = "var") model <- fit_model(data = data, R = 1000) summary(model)set.seed(1) form <- choice ~ var | 0 data <- simulate_choices(form = form, N = 100, T = 10, J = 3, re = "var") model <- fit_model(data = data, R = 1000) summary(model)
This helper function returns the covariates and the choices of specific choice occasions.
get_cov(x, id = NULL, idc = NULL, id_label = NULL, idc_label = NULL)get_cov(x, id = NULL, idc = NULL, id_label = NULL, idc_label = NULL)
x |
Either an object of class |
id, idc
|
[ If |
id_label, idc_label
|
[ If |
A subset of the choice_data data frame specified in prepare_data().
data <- simulate_choices( form = product ~ price, N = 10, T = 1:10, J = 3, ranked = TRUE ) get_cov(data, id = 2)data <- simulate_choices( form = product ~ price, N = 10, T = 1:10, J = 3, ranked = TRUE ) get_cov(data, id = 2)
Gibbs sampler for probit models
gibbs_sampler( sufficient_statistics, prior, latent_classes, fixed_parameter, R, B, print_progress, ordered, ranked, save_beta_draws = FALSE )gibbs_sampler( sufficient_statistics, prior, latent_classes, fixed_parameter, R, B, print_progress, ordered, ranked, save_beta_draws = FALSE )
sufficient_statistics |
[ |
prior |
[ |
latent_classes |
[
The following specifications are used for the weight-based updating scheme:
|
fixed_parameter |
[ See the vignette on model definition for definitions of these variables. |
R |
[ |
B |
[ |
print_progress |
[ |
ordered |
[ |
ranked |
[ |
save_beta_draws |
[ |
This function is not supposed to be called directly, but rather via
fit_model.
A list of Gibbs samples for
Sigma,
alpha (only if P_f > 0),
s, z, b, Omega (only if P_r > 0),
d (only if ordered = TRUE),
and a vector class_sequence of length R, where the r-th
entry is the number of classes after iteration r.
Compute ordered probit log-likelihood
ll_ordered(d, y, sys, Tvec)ll_ordered(d, y, sys, Tvec)
d |
[ |
y |
[ |
sys |
[ |
Tvec |
[ |
The ordered probit log-likelihood value.
d <- c(0, 0, 0) y <- matrix(c(1, 2, 1, NA), ncol = 2) sys <- matrix(c(0, 0, 0, NA), ncol = 2) Tvec <- c(2, 1) ll_ordered(d = d, y = y, sys = sys, Tvec = Tvec)d <- c(0, 0, 0) y <- matrix(c(1, 2, 1, NA), ncol = 2) sys <- matrix(c(0, 0, 0, NA), ncol = 2) Tvec <- c(2, 1) ll_ordered(d = d, y = y, sys = sys, Tvec = Tvec)
This function approximates the model's marginal likelihood.
mml(x, S = 0, ncores = parallel::detectCores() - 1, recompute = FALSE) ## S3 method for class 'RprobitB_mml' print(x, log = FALSE, ...) ## S3 method for class 'RprobitB_mml' plot(x, log = FALSE, ...)mml(x, S = 0, ncores = parallel::detectCores() - 1, recompute = FALSE) ## S3 method for class 'RprobitB_mml' print(x, log = FALSE, ...) ## S3 method for class 'RprobitB_mml' plot(x, log = FALSE, ...)
x |
An object of class |
S |
[ |
ncores |
[ If set to 1, no parallel backend is used. |
recompute |
[ |
log |
[ |
... |
Currently not used. |
The model's marginal likelihood for a model and data
is required for the computation of Bayes factors. In general, the
term has no closed form and must be approximated numerically.
This function uses the posterior Gibbs samples to approximate the model's
marginal likelihood via the posterior harmonic mean estimator.
To check the convergence, call plot(x$mml), where x is the output
of this function. If the estimation does not seem to have
converged, you can improve the approximation by combining the value
with the prior arithmetic mean estimator. The final approximation of the
model's marginal likelihood than is a weighted sum of the posterior harmonic
mean estimate and the prior arithmetic mean estimate,
where the weights are determined by the sample sizes.
The object x, including the object mml, which is the model's
approximated marginal likelihood value.
This function approximates the Gibbs sample mode.
mode_approx(samples)mode_approx(samples)
samples |
[ |
The (approximated) mode.
samples <- oeli::rmixnorm( n = 1000, mean = matrix(c(-2, 2), ncol = 2), Sigma = matrix(c(1, 1), ncol = 2), proportions = c(0.7, 0.3) ) hist(samples) mean(samples) # expected: 0.7 * (-2) + 0.3 * 2 = -0.8 mode_approx(samples) # expected: -2samples <- oeli::rmixnorm( n = 1000, mean = matrix(c(-2, 2), ncol = 2), Sigma = matrix(c(1, 1), ncol = 2), proportions = c(0.7, 0.3) ) hist(samples) mean(samples) # expected: 0.7 * (-2) + 0.3 * 2 = -0.8 mode_approx(samples) # expected: -2
This function returns a table with several criteria for model comparison.
model_selection( ..., criteria = c("npar", "LL", "AIC", "BIC"), add_form = FALSE ) ## S3 method for class 'RprobitB_model_selection' print(x, digits = 2, ...)model_selection( ..., criteria = c("npar", "LL", "AIC", "BIC"), add_form = FALSE ) ## S3 method for class 'RprobitB_model_selection' print(x, digits = 2, ...)
... |
One or more objects of class |
criteria |
[
|
add_form |
[ |
x |
An object of class |
digits |
[ |
See the vignette on model selection for more details.
A data.frame, criteria in columns, models in rows.
This function extracts the number of model parameters of an
RprobitB_fit object.
npar(object, ...) ## S3 method for class 'RprobitB_fit' npar(object, ...)npar(object, ...) ## S3 method for class 'RprobitB_fit' npar(object, ...)
object |
An object of class |
... |
Optionally more objects of class |
Either a numeric value (if just one object is provided) or a numeric vector.
This function gives an overview of the effect names, whether the covariate is alternative-specific, whether the coefficient is alternative-specific, and whether it is a random effect.
overview_effects( form, re = NULL, alternatives, base = tail(alternatives, 1), ordered = FALSE )overview_effects( form, re = NULL, alternatives, base = tail(alternatives, 1), ordered = FALSE )
form |
[
Multiple covariates (of one type) are separated by a In the ordered probit model ( |
re |
[ |
alternatives |
[ If |
base |
[ Ignored and set to By default, |
ordered |
[ |
A data.frame, each row is a effect, columns are the effect name
"effect", and booleans whether the covariate is alternative-specific
"as_value", whether the coefficient is alternative-specific
"as_coef", and whether it is a random effect "random".
check_form() for checking the model formula specification.
overview_effects( form = choice ~ price + time + comfort + change | 1, re = c("price", "time"), alternatives = c("A", "B"), base = "A" )overview_effects( form = choice ~ price + time + comfort + change | 1, re = c("price", "time"), alternatives = c("A", "B"), base = "A" )
P_r = 2 only)This function plots the allocation of decision-maker specific coefficient vectors
beta given the allocation vector z, the class means b,
and the class covariance matrices Omega.
plot_class_allocation(beta, z, b, Omega, ...)plot_class_allocation(beta, z, b, Omega, ...)
beta |
[ |
z |
[ |
b |
[ |
Omega |
[ |
... |
Optional visualization parameters:
|
Only applicable in the two-dimensional case, i.e. only if P_r = 2.
No return value. Draws a plot to the current device.
This function plots an estimated bivariate contour mixing distributions.
plot_mixture_contour(means, covs, weights, names)plot_mixture_contour(means, covs, weights, names)
means |
The class means. |
covs |
The class covariances. |
weights |
The class weights. |
names |
The covariate names. |
An object of class ggplot.
means <- list(c(0, 0), c(2, 2)) covs <- list(diag(2), 0.5 * diag(2)) weights <- c(0.7, 0.3) names <- c("A", "B") plot_mixture_contour(means, covs, weights, names)means <- list(c(0, 0), c(2, 2)) covs <- list(diag(2), 0.5 * diag(2)) weights <- c(0.7, 0.3) names <- c("A", "B") plot_mixture_contour(means, covs, weights, names)
This function draws receiver operating characteristic (ROC) curves.
plot_roc(..., reference = NULL)plot_roc(..., reference = NULL)
... |
One or more |
reference |
The reference alternative. |
No return value. Draws a plot to the current device.
This function is the plot method for an object of class RprobitB_fit.
## S3 method for class 'RprobitB_fit' plot(x, type, ignore = NULL, ...)## S3 method for class 'RprobitB_fit' plot(x, type, ignore = NULL, ...)
x |
An object of class |
type |
[
|
ignore |
[ |
... |
Currently not used. |
No return value. Draws a plot to the current device.
set.seed(1) form <- choice ~ var | 0 data <- simulate_choices(form = form, N = 100, T = 10, J = 3, re = "var") model <- fit_model( data = data, R = 100, latent_classes = list(C = 2, "dp_update" = TRUE) ) plot(model, type = "mixture") plot(model, type = "acf", ignore = c("s", "Omega", "Sigma")) plot(model, type = "trace", ignore = c("s", "Omega", "Sigma")) plot(model, type = "class_seq")set.seed(1) form <- choice ~ var | 0 data <- simulate_choices(form = form, N = 100, T = 10, J = 3, re = "var") model <- fit_model( data = data, R = 100, latent_classes = list(C = 2, "dp_update" = TRUE) ) plot(model, type = "mixture") plot(model, type = "acf", ignore = c("s", "Omega", "Sigma")) plot(model, type = "trace", ignore = c("s", "Omega", "Sigma")) plot(model, type = "class_seq")
This function computes the point estimates of an RprobitB_fit.
Per default, the mean of the Gibbs samples is used as a point estimate.
However, any statistic that computes a single numeric value out of a vector of
Gibbs samples can be specified for FUN.
point_estimates(x, FUN = mean)point_estimates(x, FUN = mean)
x |
An object of class |
FUN |
A function that computes a single numeric value out of a vector of numeric values. |
An object of class RprobitB_parameter.
data <- simulate_choices(form = choice ~ covariate, N = 10, T = 10, J = 2) model <- fit_model(data) point_estimates(model) point_estimates(model, FUN = median)data <- simulate_choices(form = choice ~ covariate, N = 10, T = 10, J = 2) model <- fit_model(data) point_estimates(model) point_estimates(model, FUN = median)
This function computes the prediction accuracy of an RprobitB_fit
object. Prediction accuracy means the share of choices that are correctly
predicted by the model, where prediction is based on the maximum choice
probability.
pred_acc(x, ...)pred_acc(x, ...)
x |
An object of class |
... |
Optionally specify more |
A numeric.
This function predicts the discrete choice behaviour.
## S3 method for class 'RprobitB_fit' predict(object, data = NULL, overview = TRUE, digits = 2, ...)## S3 method for class 'RprobitB_fit' predict(object, data = NULL, overview = TRUE, digits = 2, ...)
object |
An object of class |
data |
Either
|
overview |
[ |
digits |
[ |
... |
Currently not used. |
Predictions are made based on the maximum predicted probability for each choice alternative.
See the vignette on choice prediction for a demonstration on how to visualize the model's sensitivity and specificity by means of a receiver operating characteristic (ROC) curve.
Either a table if overview = TRUE or a data frame otherwise.
set.seed(1) data <- simulate_choices(form = choice ~ cov, N = 10, T = 10, J = 2) data <- train_test(data, test_proportion = 0.5) model <- fit_model(data$train) predict(model) predict(model, overview = FALSE) predict(model, data = data$test) predict( model, data = data.frame("cov_A" = c(1, 1, NA, NA), "cov_B" = c(1, NA, 1, NA)), overview = FALSE )set.seed(1) data <- simulate_choices(form = choice ~ cov, N = 10, T = 10, J = 2) data <- train_test(data, test_proportion = 0.5) model <- fit_model(data$train) predict(model) predict(model, overview = FALSE) predict(model, data = data$test) predict( model, data = data.frame("cov_A" = c(1, 1, NA, NA), "cov_B" = c(1, NA, 1, NA)), overview = FALSE )
This function prepares choice data for estimation.
prepare_data( form, choice_data, re = NULL, alternatives = NULL, ordered = FALSE, ranked = FALSE, base = NULL, id = "id", idc = NULL, standardize = NULL, impute = "complete_cases" )prepare_data( form, choice_data, re = NULL, alternatives = NULL, ordered = FALSE, ranked = FALSE, base = NULL, id = "id", idc = NULL, standardize = NULL, impute = "complete_cases" )
form |
[
Multiple covariates (of one type) are separated by a In the ordered probit model ( |
choice_data |
[ |
re |
[ |
alternatives |
[ If |
ordered |
[ |
ranked |
[ |
base |
[ Ignored and set to By default, |
id |
[ |
idc |
[ |
standardize |
[ Covariates of type 1 or 3 have to be addressed by
If |
impute |
A character that specifies how to handle missing covariate entries in
|
Requirements for the data.frame choice_data:
It must contain a column named id which contains unique
identifier for each decision maker.
It can contain a column named idc which contains unique
identifier for each choice situation of each decision maker.
If this information is missing, these identifier are generated
automatically by the appearance of the choices in the data set.
It can contain a column named choice with the observed
choices, where choice must match the name of the dependent
variable in form.
Such a column is required for model fitting but not for prediction.
It must contain a numeric column named p_j for each alternative
specific covariate p in form and each choice alternative j
in alternatives.
It must contain a numeric column named q for each covariate q
in form that is constant across alternatives.
In the ordered case (ordered = TRUE), the column choice must
contain the full ranking of the alternatives in each choice occasion as a
character, where the alternatives are separated by commas, see the examples.
See the vignette on choice data for more details.
An object of class RprobitB_data.
check_form() for checking the model formula
overview_effects() for an overview of the model effects
create_lagged_cov() for creating lagged covariates
as_cov_names() for re-labeling alternative-specific covariates
simulate_choices() for simulating choice data
train_test() for splitting choice data into a train and test subset
data <- prepare_data( form = choice ~ price + time + comfort + change | 0, choice_data = train_choice, re = c("price", "time"), id = "deciderID", idc = "occasionID", standardize = c("price", "time") ) ### ranked case choice_data <- data.frame( "id" = 1:3, "choice" = c("A,B,C", "A,C,B", "B,C,A"), "cov" = 1 ) data <- prepare_data( form = choice ~ 0 | cov + 0, choice_data = choice_data, ranked = TRUE )data <- prepare_data( form = choice ~ price + time + comfort + change | 0, choice_data = train_choice, re = c("price", "time"), id = "deciderID", idc = "occasionID", standardize = c("price", "time") ) ### ranked case choice_data <- data.frame( "id" = 1:3, "choice" = c("A,B,C", "A,C,B", "B,C,A"), "cov" = 1 ) data <- prepare_data( form = choice ~ 0 | cov + 0, choice_data = choice_data, ranked = TRUE )
This function computes the Gelman-Rubin statistic R_hat.
R_hat(samples, parts = 2)R_hat(samples, parts = 2)
samples |
[ If it is a matrix, each column gives the samples for a separate chain. |
parts |
[ |
NA values in samples are ignored. The degenerate case is indicated by NA.
The Gelman-Rubin statistic is bounded by 1 from below. Values close to 1
indicate reasonable convergence.
The Gelman-Rubin statistic.
no_chains <- 2 length_chains <- 1e3 samples <- matrix(NA_real_, length_chains, no_chains) samples[1, ] <- 1 Gamma <- matrix(c(0.8, 0.1, 0.2, 0.9), 2, 2) for (c in 1:no_chains) { for (t in 2:length_chains) { samples[t, c] <- sample(1:2, 1, prob = Gamma[samples[t - 1, c], ]) } } R_hat(samples)no_chains <- 2 length_chains <- 1e3 samples <- matrix(NA_real_, length_chains, no_chains) samples[1, ] <- 1 Gamma <- matrix(c(0.8, 0.1, 0.2, 0.9), 2, 2) for (c in 1:no_chains) { for (t in 2:length_chains) { samples[t, c] <- sample(1:2, 1, prob = Gamma[samples[t - 1, c], ]) } } R_hat(samples)
This function creates an object of class RprobitB_parameter, which
contains the parameters of a probit model.
If sample = TRUE, missing parameters are sampled. All parameters are
checked against the values of P_f, P_r, J, and N.
Note that parameters are automatically ordered with respect to a
non-ascending s for class identifiability.
RprobitB_parameter( P_f, P_r, J, N, C = 1, ordered = FALSE, alpha = NULL, s = NULL, b = NULL, Omega = NULL, Sigma = NULL, Sigma_full = NULL, beta = NULL, z = NULL, d = NULL, sample = TRUE ) ## S3 method for class 'RprobitB_parameter' print(x, ..., digits = 4)RprobitB_parameter( P_f, P_r, J, N, C = 1, ordered = FALSE, alpha = NULL, s = NULL, b = NULL, Omega = NULL, Sigma = NULL, Sigma_full = NULL, beta = NULL, z = NULL, d = NULL, sample = TRUE ) ## S3 method for class 'RprobitB_parameter' print(x, ..., digits = 4)
P_f |
[ |
P_r |
[ |
J |
[ |
N |
[ |
C |
[ |
ordered |
[ |
alpha |
[ |
s |
[ |
b |
[ |
Omega |
[ |
Sigma |
[ In case of |
Sigma_full |
[ Ignored if Internally, |
beta |
[ |
z |
[ |
d |
[ |
sample |
[ |
x |
An |
... |
[ |
digits |
[ |
An object of class RprobitB_parameter, which is a named list with the
model parameters.
RprobitB_parameter(P_f = 1, P_r = 2, J = 3, N = 10, C = 2)RprobitB_parameter(P_f = 1, P_r = 2, J = 3, N = 10, C = 2)
Sample allocation
sample_allocation(prob)sample_allocation(prob)
prob |
[ |
An integer 1:C.
sample_allocation(c(0.5, 0.3, 0.2))sample_allocation(c(0.5, 0.3, 0.2))
This function simulates choice data from a probit model.
simulate_choices( form, N, T = 1, J, re = NULL, alternatives = NULL, ordered = FALSE, ranked = FALSE, base = NULL, covariates = NULL, true_parameter = list() )simulate_choices( form, N, T = 1, J, re = NULL, alternatives = NULL, ordered = FALSE, ranked = FALSE, base = NULL, covariates = NULL, true_parameter = list() )
form |
[
Multiple covariates (of one type) are separated by a In the ordered probit model ( |
N |
[ |
T |
[ |
J |
[ |
re |
[ |
alternatives |
[ If |
ordered |
[ |
ranked |
[ |
base |
[ Ignored and set to By default, |
covariates |
[ |
true_parameter |
[ See the vignette on model definition for definitions of these variables. |
See the vignette on choice data for more details.
An object of class RprobitB_data.
check_form() for checking the model formula
overview_effects() for an overview of the model effects
create_lagged_cov() for creating lagged covariates
as_cov_names() for re-labelling alternative-specific covariates
prepare_data() for preparing empirical choice data
train_test() for splitting choice data into a train and test subset
### simulate data from a binary probit model with two latent classes data <- simulate_choices( form = choice ~ cost | income | time, N = 100, T = 10, J = 2, re = c("cost", "time"), alternatives = c("car", "bus"), true_parameter = list( "alpha" = c(-1, 1), "b" = matrix(c(-1, -1, -0.5, -1.5, 0, -1), ncol = 2), "C" = 2 ) ) ### simulate data from an ordered probit model data <- simulate_choices( form = opinion ~ age + gender, N = 10, T = 1:10, J = 5, alternatives = c("very bad", "bad", "indifferent", "good", "very good"), ordered = TRUE, covariates = list( "gender" = rep(sample(c(0, 1), 10, replace = TRUE), times = 1:10) ) ) ### simulate data from a ranked probit model data <- simulate_choices( form = product ~ price, N = 10, T = 1:10, J = 3, alternatives = c("A", "B", "C"), ranked = TRUE )### simulate data from a binary probit model with two latent classes data <- simulate_choices( form = choice ~ cost | income | time, N = 100, T = 10, J = 2, re = c("cost", "time"), alternatives = c("car", "bus"), true_parameter = list( "alpha" = c(-1, 1), "b" = matrix(c(-1, -1, -0.5, -1.5, 0, -1), ncol = 2), "C" = 2 ) ) ### simulate data from an ordered probit model data <- simulate_choices( form = opinion ~ age + gender, N = 10, T = 1:10, J = 5, alternatives = c("very bad", "bad", "indifferent", "good", "very good"), ordered = TRUE, covariates = list( "gender" = rep(sample(c(0, 1), 10, replace = TRUE), times = 1:10) ) ) ### simulate data from a ranked probit model data <- simulate_choices( form = product ~ price, N = 10, T = 1:10, J = 3, alternatives = c("A", "B", "C"), ranked = TRUE )
Data set of 2929 stated choices by 235 Dutch individuals deciding between
two virtual train trip options "A" and "B" based on the price,
the travel time, the number of rail-to-rail transfers (changes), and the
level of comfort.
The data were obtained in 1987 by Hague Consulting Group for the National Dutch Railways. Prices were recorded in Dutch guilder and in this data set transformed to Euro at an exchange rate of 2.20371 guilders = 1 Euro.
train_choicetrain_choice
A data.frame with 2929 rows and 11 columns:
integer identifier for the decider
integer identifier for the choice occasion
character for the chosen alternative (either "A" or "B")
numeric price for alternative "A" in Euro
numeric travel time for alternative "A" in hours
integer number of changes for alternative "A"
integer comfort level (in decreasing comfort order) for alternative "A"
numeric price for alternative "B" in Euro
numeric travel time for alternative "B" in hours
integer number of changes for alternative "B"
integer comfort level (in decreasing comfort order) for alternative "B"
Ben-Akiva M, Bolduc D, Bradley M (1993). “Estimation of travel choice models with randomly distributed values of time.” Transportation Research Record, 1413.
Meijer E, Rouwendal J (2006). “Measuring welfare effects in models with random coefficients.” Journal of Applied Econometrics, 21(2).
This function splits choice data into a train and a test part.
train_test( x, test_proportion = NULL, test_number = NULL, by = "N", random = FALSE )train_test( x, test_proportion = NULL, test_number = NULL, by = "N", random = FALSE )
x |
An object of class |
test_proportion |
[ |
test_number |
[ |
by |
[ |
random |
[ |
A list with two objects of class RprobitB_data, named "train"
and "test".
### simulate choices for demonstration x <- simulate_choices(form = choice ~ covariate, N = 10, T = 10, J = 2) ### 70% of deciders in the train subsample, ### 30% of deciders in the test subsample train_test(x, test_proportion = 0.3, by = "N") ### 2 randomly chosen choice occasions per decider in the test subsample, ### the rest in the train subsample train_test(x, test_number = 2, by = "T", random = TRUE)### simulate choices for demonstration x <- simulate_choices(form = choice ~ covariate, N = 10, T = 10, J = 2) ### 70% of deciders in the train subsample, ### 30% of deciders in the test subsample train_test(x, test_proportion = 0.3, by = "N") ### 2 randomly chosen choice occasions per decider in the test subsample, ### the rest in the train subsample train_test(x, test_number = 2, by = "T", random = TRUE)
Given an object of class RprobitB_fit, this function can:
change the length B of the burn-in period,
change the the thinning factor Q of the Gibbs samples,
change the utility scale.
## S3 method for class 'RprobitB_fit' transform( `_data`, B = NULL, Q = NULL, scale = NULL, check_preference_flip = TRUE, ... )## S3 method for class 'RprobitB_fit' transform( `_data`, B = NULL, Q = NULL, scale = NULL, check_preference_flip = TRUE, ... )
_data |
An object of class |
B |
[ |
Q |
[ |
scale |
[ |
check_preference_flip |
Set to |
... |
Currently not used. |
See the vignette "Model fitting" for more details:
vignette("v03_model_fitting", package = "RprobitB").
The transformed RprobitB_fit object.
Update class means
update_b(beta, Omega, z, m, Sigma_b_0_inv, mu_b_0)update_b(beta, Omega, z, m, Sigma_b_0_inv, mu_b_0)
beta |
[ |
Omega |
[ |
z |
[ |
m |
[ |
Sigma_b_0_inv |
[ |
mu_b_0 |
[ |
A matrix of updated means for each class in columns.
N <- 100 b <- cbind(c(0, 0), c(1, 1)) Omega <- matrix(c(1, 0.3, 0.3, 0.5, 1, -0.3, -0.3, 0.8), ncol = 2) z <- c(rep(1, N / 2), rep(2, N / 2)) m <- as.numeric(table(z)) beta <- sapply( z, function(z) oeli::rmvnorm(n = 1, b[, z], matrix(Omega[, z], 2, 2)) ) update_b( beta = beta, Omega = Omega, z = z, m = m, Sigma_b_0_inv = diag(2), mu_b_0 = c(0, 0) )N <- 100 b <- cbind(c(0, 0), c(1, 1)) Omega <- matrix(c(1, 0.3, 0.3, 0.5, 1, -0.3, -0.3, 0.8), ncol = 2) z <- c(rep(1, N / 2), rep(2, N / 2)) m <- as.numeric(table(z)) beta <- sapply( z, function(z) oeli::rmvnorm(n = 1, b[, z], matrix(Omega[, z], 2, 2)) ) update_b( beta = beta, Omega = Omega, z = z, m = m, Sigma_b_0_inv = diag(2), mu_b_0 = c(0, 0) )
Update mean of a single class
update_b_c(bar_b_c, Omega_c, m_c, Sigma_b_0_inv, mu_b_0)update_b_c(bar_b_c, Omega_c, m_c, Sigma_b_0_inv, mu_b_0)
bar_b_c |
[ |
Omega_c |
[ |
m_c |
[ |
Sigma_b_0_inv |
[ |
mu_b_0 |
[ |
An update for b_c.
update_b_c( bar_b_c = c(0, 0), Omega_c = diag(2), m_c = 10, Sigma_b_0_inv = diag(2), mu_b_0 = c(0, 0) )update_b_c( bar_b_c = c(0, 0), Omega_c = diag(2), m_c = 10, Sigma_b_0_inv = diag(2), mu_b_0 = c(0, 0) )
Dirichlet process class updates
update_classes_dp( beta, z, b, Omega, delta, mu_b_0, Sigma_b_0, n_Omega_0, V_Omega_0, identify_classes = FALSE, Cmax = 10L )update_classes_dp( beta, z, b, Omega, delta, mu_b_0, Sigma_b_0, n_Omega_0, V_Omega_0, identify_classes = FALSE, Cmax = 10L )
beta |
[ |
z |
[ |
b |
[ |
Omega |
[ |
delta |
[ |
mu_b_0 |
[ |
Sigma_b_0 |
[ |
n_Omega_0 |
[ |
V_Omega_0 |
[ |
identify_classes |
[ |
Cmax |
[ |
A list of updated values for z, b, Omega, and C.
set.seed(1) z <- c(rep(1, 10),rep(2, 10)) b <- matrix(c(5, 5, 5, -5), ncol = 2) Omega <- matrix(c(1, 0.3, 0.3, 0.5, 1, -0.3, -0.3, 0.8), ncol = 2) beta <- sapply( z, function(z) oeli::rmvnorm(n = 1, b[, z], matrix(Omega[, z], 2, 2)) ) beta[, 1] <- c(-10, 10) update_classes_dp( beta = beta, z = z, b = b, Omega = Omega, delta = 1, mu_b_0 = numeric(2), Sigma_b_0 = diag(2), n_Omega_0 = 4, V_Omega_0 = diag(2) )set.seed(1) z <- c(rep(1, 10),rep(2, 10)) b <- matrix(c(5, 5, 5, -5), ncol = 2) Omega <- matrix(c(1, 0.3, 0.3, 0.5, 1, -0.3, -0.3, 0.8), ncol = 2) beta <- sapply( z, function(z) oeli::rmvnorm(n = 1, b[, z], matrix(Omega[, z], 2, 2)) ) beta[, 1] <- c(-10, 10) update_classes_dp( beta = beta, z = z, b = b, Omega = Omega, delta = 1, mu_b_0 = numeric(2), Sigma_b_0 = diag(2), n_Omega_0 = 4, V_Omega_0 = diag(2) )
Weight-based class updates
update_classes_wb( s, b, Omega, epsmin = 0.01, epsmax = 0.7, deltamin = 0.1, deltashift = 0.5, identify_classes = FALSE, Cmax = 10L )update_classes_wb( s, b, Omega, epsmin = 0.01, epsmax = 0.7, deltamin = 0.1, deltashift = 0.5, identify_classes = FALSE, Cmax = 10L )
s |
[ |
b |
[ |
Omega |
[ |
epsmin |
[ |
epsmax |
[ |
deltamin |
[ |
deltashift |
[ |
identify_classes |
[ |
Cmax |
[ |
The following updating rules apply:
Class is removed if .
Class is split into two classes, if .
Two classes and are merged to one class, if
.
A list of updated values for s, b, and Omega and
the indicator update_type which signals the type of class update:
0: no update
1: removed class
2: split class
3: merged classes
s <- c(0.7, 0.3) b <- matrix(c(1, 1, 1, -1), ncol = 2) Omega <- matrix(c(0.5, 0.3, 0.3, 0.5, 1, -0.1, -0.1, 0.8), ncol = 2) ### no update update_classes_wb(s = s, b = b, Omega = Omega) ### remove class 2 update_classes_wb(s = s, b = b, Omega = Omega, epsmin = 0.31) ### split class 1 update_classes_wb(s = s, b = b, Omega = Omega, epsmax = 0.69) ### merge classes 1 and 2 update_classes_wb(s = s, b = b, Omega = Omega, deltamin = 3)s <- c(0.7, 0.3) b <- matrix(c(1, 1, 1, -1), ncol = 2) Omega <- matrix(c(0.5, 0.3, 0.3, 0.5, 1, -0.1, -0.1, 0.8), ncol = 2) ### no update update_classes_wb(s = s, b = b, Omega = Omega) ### remove class 2 update_classes_wb(s = s, b = b, Omega = Omega, epsmin = 0.31) ### split class 1 update_classes_wb(s = s, b = b, Omega = Omega, epsmax = 0.69) ### merge classes 1 and 2 update_classes_wb(s = s, b = b, Omega = Omega, deltamin = 3)
Update coefficient vector
update_coefficient(mu_beta_0, Sigma_beta_0_inv, XSigX, XSigU)update_coefficient(mu_beta_0, Sigma_beta_0_inv, XSigX, XSigU)
mu_beta_0 |
[ |
Sigma_beta_0_inv |
[ |
XSigX |
[ |
XSigU |
[ |
An update for the coefficient vector.
beta_true <- matrix(c(-1, 1), ncol = 1) Sigma <- matrix(c(1, 0.5, 0.2, 0.5, 1, 0.2, 0.2, 0.2, 2), ncol = 3) N <- 100 X <- replicate(N, matrix(rnorm(6), ncol = 2), simplify = FALSE) eps <- replicate( N, oeli::rmvnorm(n = 1, mean = c(0, 0, 0), Sigma = Sigma), simplify = FALSE ) U <- mapply( function(X, eps) X %*% beta_true + eps, X, eps, SIMPLIFY = FALSE ) mu_beta_0 <- c(0, 0) Sigma_beta_0_inv <- diag(2) XSigX <- Reduce( `+`, lapply(X, function(X) t(X) %*% solve(Sigma) %*% X) ) XSigU <- Reduce( `+`, mapply(function(X, U) t(X) %*% solve(Sigma) %*% U, X, U, SIMPLIFY = FALSE) ) R <- 10 beta_draws <- replicate( R, update_coefficient(mu_beta_0, Sigma_beta_0_inv, XSigX, XSigU), simplify = TRUE ) rowMeans(beta_draws)beta_true <- matrix(c(-1, 1), ncol = 1) Sigma <- matrix(c(1, 0.5, 0.2, 0.5, 1, 0.2, 0.2, 0.2, 2), ncol = 3) N <- 100 X <- replicate(N, matrix(rnorm(6), ncol = 2), simplify = FALSE) eps <- replicate( N, oeli::rmvnorm(n = 1, mean = c(0, 0, 0), Sigma = Sigma), simplify = FALSE ) U <- mapply( function(X, eps) X %*% beta_true + eps, X, eps, SIMPLIFY = FALSE ) mu_beta_0 <- c(0, 0) Sigma_beta_0_inv <- diag(2) XSigX <- Reduce( `+`, lapply(X, function(X) t(X) %*% solve(Sigma) %*% X) ) XSigU <- Reduce( `+`, mapply(function(X, U) t(X) %*% solve(Sigma) %*% U, X, U, SIMPLIFY = FALSE) ) R <- 10 beta_draws <- replicate( R, update_coefficient(mu_beta_0, Sigma_beta_0_inv, XSigX, XSigU), simplify = TRUE ) rowMeans(beta_draws)
Update utility threshold increments
update_d(d, y, sys, ll, mu_d_0, Sigma_d_0, Tvec, step_scale = 0.1)update_d(d, y, sys, ll, mu_d_0, Sigma_d_0, Tvec, step_scale = 0.1)
d |
[ |
y |
[ |
sys |
[ |
ll |
[ |
mu_d_0 |
[ |
Sigma_d_0 |
[ |
Tvec |
[ |
step_scale |
[ |
An update for d.
set.seed(1) N <- 1000 d_true <- rnorm(2) gamma <- c(-Inf, 0, cumsum(exp(d_true)), Inf) X <- matrix(rnorm(N * 2L), ncol = 2L) beta <- c(0.8, -0.5) mu <- matrix(as.vector(X %*% beta), ncol = 1L) U <- rnorm(N, mean = mu[, 1], sd = 1) yvec <- as.integer(cut(U, breaks = gamma, labels = FALSE)) y <- matrix(yvec, ncol = 1L) Tvec <- rep(1, N) mu_d_0 <- c(0, 0) Sigma_d_0 <- diag(2) * 5 d <- rnorm(2) ll <- -Inf R <- 1000 for (iter in seq_len(R)) { ans <- update_d( d = d, y = y, sys = mu, ll = ll, mu_d_0 = mu_d_0, Sigma_d_0 = Sigma_d_0, Tvec = Tvec ) d <- ans$d ll <- ans$ll } cbind("true" = d_true, "sample" = d) |> round(2)set.seed(1) N <- 1000 d_true <- rnorm(2) gamma <- c(-Inf, 0, cumsum(exp(d_true)), Inf) X <- matrix(rnorm(N * 2L), ncol = 2L) beta <- c(0.8, -0.5) mu <- matrix(as.vector(X %*% beta), ncol = 1L) U <- rnorm(N, mean = mu[, 1], sd = 1) yvec <- as.integer(cut(U, breaks = gamma, labels = FALSE)) y <- matrix(yvec, ncol = 1L) Tvec <- rep(1, N) mu_d_0 <- c(0, 0) Sigma_d_0 <- diag(2) * 5 d <- rnorm(2) ll <- -Inf R <- 1000 for (iter in seq_len(R)) { ans <- update_d( d = d, y = y, sys = mu, ll = ll, mu_d_0 = mu_d_0, Sigma_d_0 = Sigma_d_0, Tvec = Tvec ) d <- ans$d ll <- ans$ll } cbind("true" = d_true, "sample" = d) |> round(2)
Update class sizes
update_m(C, z, non_zero = FALSE)update_m(C, z, non_zero = FALSE)
C |
[ |
z |
[ |
non_zero |
[ |
An update for m.
update_m(C = 4, z = c(1, 1, 1, 2, 2, 3))update_m(C = 4, z = c(1, 1, 1, 2, 2, 3))
Update class covariances
update_Omega(beta, b, z, m, n_Omega_0, V_Omega_0)update_Omega(beta, b, z, m, n_Omega_0, V_Omega_0)
beta |
[ |
b |
[ |
z |
[ |
m |
[ |
n_Omega_0 |
[ |
V_Omega_0 |
[ |
A matrix of updated covariance matrices for each class in columns.
N <- 100 b <- cbind(c(0, 0), c(1, 1)) Omega <- matrix(c(1, 0.3, 0.3, 0.5, 1, -0.3, -0.3, 0.8), ncol = 2) z <- c(rep(1, N / 2), rep(2, N / 2)) m <- as.numeric(table(z)) beta <- sapply( z, function(z) oeli::rmvnorm(n = 1, b[, z], matrix(Omega[, z], 2, 2)) ) update_Omega( beta = beta, b = b, z = z, m = m, n_Omega_0 = 4, V_Omega_0 = diag(2) )N <- 100 b <- cbind(c(0, 0), c(1, 1)) Omega <- matrix(c(1, 0.3, 0.3, 0.5, 1, -0.3, -0.3, 0.8), ncol = 2) z <- c(rep(1, N / 2), rep(2, N / 2)) m <- as.numeric(table(z)) beta <- sapply( z, function(z) oeli::rmvnorm(n = 1, b[, z], matrix(Omega[, z], 2, 2)) ) update_Omega( beta = beta, b = b, z = z, m = m, n_Omega_0 = 4, V_Omega_0 = diag(2) )
Update covariance of a single class
update_Omega_c(S_c, m_c, n_Omega_0, V_Omega_0)update_Omega_c(S_c, m_c, n_Omega_0, V_Omega_0)
S_c |
[ |
m_c |
[ |
n_Omega_0 |
[ |
V_Omega_0 |
[ |
An update for Omega_c.
update_Omega_c(S_c = diag(2), m_c = 10, n_Omega_0 = 4, V_Omega_0 = diag(2))update_Omega_c(S_c = diag(2), m_c = 10, n_Omega_0 = 4, V_Omega_0 = diag(2))
Update class weight vector
update_s(delta, m)update_s(delta, m)
delta |
[ |
m |
[ |
An update for s.
update_s(delta = 1, m = 4:1)update_s(delta = 1, m = 4:1)
Update error covariance matrix
update_Sigma(n_Sigma_0, V_Sigma_0, N, S)update_Sigma(n_Sigma_0, V_Sigma_0, N, S)
n_Sigma_0 |
[ |
V_Sigma_0 |
[ |
N |
[ |
S |
[ |
An update for Sigma.
(Sigma_true <- matrix(c(1, 0.5, 0.2, 0.5, 1, 0.2, 0.2, 0.2, 2), ncol = 3)) beta <- matrix(c(-1, 1), ncol = 1) N <- 100 X <- replicate(N, matrix(rnorm(6), ncol = 2), simplify = FALSE) eps <- replicate( N, oeli::rmvnorm(n = 1, mean = c(0, 0, 0), Sigma = Sigma_true), simplify = FALSE ) U <- mapply(function(X, eps) X %*% beta + eps, X, eps, SIMPLIFY = FALSE) n_Sigma_0 <- 4 V_Sigma_0 <- diag(3) outer_prod <- function(X, U) (U - X %*% beta) %*% t(U - X %*% beta) S <- Reduce(`+`, mapply( function(X, U) (U - X %*% beta) %*% t(U - X %*% beta), X, U, SIMPLIFY = FALSE )) Sigma_draws <- replicate(100, update_Sigma(n_Sigma_0, V_Sigma_0, N, S)) apply(Sigma_draws, 1:2, mean)(Sigma_true <- matrix(c(1, 0.5, 0.2, 0.5, 1, 0.2, 0.2, 0.2, 2), ncol = 3)) beta <- matrix(c(-1, 1), ncol = 1) N <- 100 X <- replicate(N, matrix(rnorm(6), ncol = 2), simplify = FALSE) eps <- replicate( N, oeli::rmvnorm(n = 1, mean = c(0, 0, 0), Sigma = Sigma_true), simplify = FALSE ) U <- mapply(function(X, eps) X %*% beta + eps, X, eps, SIMPLIFY = FALSE) n_Sigma_0 <- 4 V_Sigma_0 <- diag(3) outer_prod <- function(X, U) (U - X %*% beta) %*% t(U - X %*% beta) S <- Reduce(`+`, mapply( function(X, U) (U - X %*% beta) %*% t(U - X %*% beta), X, U, SIMPLIFY = FALSE )) Sigma_draws <- replicate(100, update_Sigma(n_Sigma_0, V_Sigma_0, N, S)) apply(Sigma_draws, 1:2, mean)
Update utility vector
update_U(U, y, sys, Sigma_inv)update_U(U, y, sys, Sigma_inv)
U |
[ |
y |
[ |
sys |
[ |
Sigma_inv |
[ |
An update for (a single) U.
U <- sys <- c(0, 0, 0) Sigma_inv <- diag(3) lapply(1:4, function(y) update_U(U, y, sys, Sigma_inv))U <- sys <- c(0, 0, 0) Sigma_inv <- diag(3) lapply(1:4, function(y) update_U(U, y, sys, Sigma_inv))
Update ranked utility vector
update_U_ranked(U, sys, Sigma_inv)update_U_ranked(U, sys, Sigma_inv)
U |
[ |
sys |
[ |
Sigma_inv |
[ |
An update for (a single) ranked U.
U <- sys <- c(0, 0) Sigma_inv <- diag(2) update_U_ranked(U, sys, Sigma_inv)U <- sys <- c(0, 0) Sigma_inv <- diag(2) update_U_ranked(U, sys, Sigma_inv)
Update class allocation vector
update_z(s, beta, b, Omega)update_z(s, beta, b, Omega)
s |
[ |
beta |
[ |
b |
[ |
Omega |
[ |
An update for z.
update_z( s = c(0.6, 0.4), beta = matrix(c(-2, 0, 2), ncol = 3), b = cbind(0, 1), Omega = cbind(1, 1) )update_z( s = c(0.6, 0.4), beta = matrix(c(-2, 0, 2), ncol = 3), b = cbind(0, 1), Omega = cbind(1, 1) )
This function estimates a nested probit model based on a given
RprobitB_fit object.
## S3 method for class 'RprobitB_fit' update( object, form, re, alternatives, id, idc, standardize, impute, scale, R, B, Q, print_progress, prior, latent_classes, ... )## S3 method for class 'RprobitB_fit' update( object, form, re, alternatives, id, idc, standardize, impute, scale, R, B, Q, print_progress, prior, latent_classes, ... )
object |
An object of class |
form |
[
Multiple covariates (of one type) are separated by a In the ordered probit model ( |
re |
[ |
alternatives |
[ If |
id |
[ |
idc |
[ |
standardize |
[ Covariates of type 1 or 3 have to be addressed by
If |
impute |
A character that specifies how to handle missing covariate entries in
|
scale |
[ |
R |
[ |
B |
[ |
Q |
[ |
print_progress |
[ |
prior |
[ |
latent_classes |
[
The following specifications are used for the weight-based updating scheme:
|
... |
Currently not used. |
All parameters (except for object) are optional and if not specified
retrieved from the specification for object.
An object of class RprobitB_fit.