Learn R Programming

rmdcev (version 1.3.3)

simulation_functions: Low-level MDCEV simulation functions

Description

Compiled C++ routines that underlie mdcev.sim and GenerateMDCEVData. These functions are exported for advanced users and test code; most users should call the higher-level wrappers instead.

DrawError_rng

Draw preference error terms for one individual using the MLHS or independent draw approach.

MarshallianDemand

Compute Marshallian (uncompensated) demand for one individual given marginal utilities at zero.

HicksianDemand

Compute Hicksian (compensated) demand for one individual given a reference utility level.

ComputeUtilJ

Evaluate the KT utility function for one individual.

CalcWTP_rng

Simulate welfare (WTP) across nerrs error draws for one individual under a price policy.

CalcMarshallianDemand_rng

Simulate Marshallian demand across nerrs error draws for one individual under a price policy.

Usage

DrawError_rng(quant_num, quant_j, price_j, psi_j, phi_j, gamma_j,
              alpha, scale, model_num, nalts, nerrs, cond_error,
              draw_mlhs, base_rng__, pstream__)

MarshallianDemand(income, price, MUzero, phi, gamma, alpha, nalts, algo_gen, model_num, tol_e, max_loop, pstream__)

HicksianDemand(util, price, MUzero, phi, gamma, alpha, nalts, algo_gen, model_num, tol_l, max_loop, pstream__)

ComputeUtilJ(income, quant_j, price_j, psi, phi_j, gamma_j, alpha, nalts, model_num, pstream__)

CalcWTP_rng(income, quant_j, price, price_p_policy, psi_p_sims, phi_p_sims, psi_sims, phi_sims, gamma_sims, alpha_sims, scale_sims, nerrs, cond_error, draw_mlhs, algo_gen, model_num, price_change_only, tol, max_loop, base_rng__, pstream__)

CalcMarshallianDemand_rng(income, quant_j, price, price_p_policy, psi_p_sims, phi_p_sims, psi_sims, phi_sims, gamma_sims, alpha_sims, scale_sims, nerrs, cond_error, draw_mlhs, algo_gen, model_num, price_change_only, tol, max_loop, base_rng__, pstream__)

Value

DrawError_rng returns a matrix of error draws with nerrs

rows and nalts + 1 columns.

MarshallianDemand and HicksianDemand return a numeric vector of length nalts + 1 holding the numeraire quantity followed by the non-numeraire quantities.

ComputeUtilJ returns a scalar utility value.

CalcWTP_rng and CalcMarshallianDemand_rng return a list with one element per policy scenario, each holding the simulated welfare measure or demand averaged over the nerrs error draws.

Arguments

base_rng__

External pointer to the Boost RNG created by rmdcev_get_rng.

pstream__

External pointer to the output stream created by rmdcev_get_stream.

model_num

Integer model type: 1 = gamma, 2 = alpha, 3 = hybrid, 4 = hybrid0, 5 = kt_ee, 6 = gamma1.

income

Individual income (scalar).

quant_j

Vector of non-numeraire quantities.

quant_num

Numeraire quantity consumed.

price_j

Vector of non-numeraire prices.

price

Full price vector (numeraire first).

price_p_policy

Matrix of counterfactual prices, one row per policy scenario.

psi_j, psi

Psi utility parameters.

phi_j, phi

Phi parameters (kt_ee model).

gamma_j, gamma

Gamma satiation parameters.

alpha

Alpha parameters.

scale

Scale parameter.

psi_sims, phi_sims, gamma_sims, alpha_sims, scale_sims

Lists of parameter draws, one element per simulation, for the baseline scenario.

psi_p_sims, phi_p_sims

Lists of psi and phi parameter draws for the policy scenarios.

nalts

Number of non-numeraire alternatives.

nerrs

Number of error draws.

cond_error

1 = conditional error draws; 0 = unconditional.

draw_mlhs

1 = Modified Latin Hypercube Sampling; 0 = iid.

algo_gen

Algorithm: 0 = hybrid (fast, requires alpha = 0); 1 = general bisection.

price_change_only

1 = only prices change across policies, so the baseline psi and phi draws are reused; 0 = psi and phi also change across policies.

MUzero

Vector of marginal utilities at zero consumption.

util

Reference utility level (Hicksian demand).

tol, tol_e, tol_l

Convergence tolerance for bisection.

max_loop

Maximum bisection iterations.

See Also

mdcev.sim, PrepareSimulationData, rmdcev_get_rng, rmdcev_get_stream