initialize_market_model | R Documentation |
Model initialization
## S4 method for signature 'diseq_basic' initialize( .Object, quantity, price, demand, supply, subject, time, data, correlated_shocks = TRUE, verbose = 0 ) ## S4 method for signature 'diseq_deterministic_adjustment' initialize( .Object, quantity, price, demand, supply, subject, time, data, correlated_shocks = TRUE, verbose = 0 ) ## S4 method for signature 'diseq_directional' initialize( .Object, quantity, price, demand, supply, subject, time, data, correlated_shocks = TRUE, verbose = 0 ) ## S4 method for signature 'diseq_stochastic_adjustment' initialize( .Object, quantity, price, demand, supply, price_dynamics, subject, time, data, correlated_shocks = TRUE, verbose = 0 ) ## S4 method for signature 'equilibrium_model' initialize( .Object, quantity, price, demand, supply, subject, time, data, correlated_shocks = TRUE, verbose = 0 )
.Object |
The object to be Constructed. |
quantity |
The quantity variable of the system. |
price |
The price variable of the system. |
demand |
A formula representation of the right hand side of the demand equation. |
supply |
A formula representation of the right hand side of the supply equation. |
subject |
The subject identifier of the data set. |
time |
The time identifier of the data set. |
data |
The data set. |
correlated_shocks |
Should the model be estimated using correlated shocks? |
verbose |
Verbosity level. |
price_dynamics |
A formula representation of the price equation. |
The following two subsections describe the common initialization steps of all market model classes.
The constructor prepares the model's variables using the passed
specifications. The specification variables are expected to be of type
language
. The right hand side specifications of the system are
expected to follow the syntax of formula
. The
construction of the model's data uses the variables extracted by these
specification. The demand variables are extracted by a
formula that uses the quantity
on the left hand side and the
demand
on the right hand side of the formula. The supply
variables are constructed by the quantity
and the
supply
inputs. In the case of the
diseq_stochastic_adjustment
model, the price dynamics'
variables are extracted using the price dynamics
input.
The price dynamics
for the diseq_stochastic_adjustment
should contain only terms other than that of excess demand. The excess demand term of
the price equation is automatically generated by the constructor.
1. If the passed data set contains rows with NA values, they are dropped. If the verbosity level allows warnings, a warning is emitted reporting how many rows were dropped.
2. After dropping the rows, factor levels may be invalidated. If needed, the constructor readjusts the factor variables by removing the unobserved levels. Factor indicators and interaction terms are automatically created.
3. The primary key column is constructed by pasting the values of the columns of the subject and time variables.
4. In the cases of the diseq_directional
,
diseq_deterministic_adjustment
, and
the diseq_stochastic_adjustment
models, a column with lagged
prices is constructed. Since lagged prices are unavailable for the observations of
the first time point, these observations are dropped. If the verbosity level allows
the emission of information messages, the constructor prints the number of dropped
observations.
5. In the cases of the diseq_directional
and the diseq_stochastic_adjustment
models, a column with price
differences is created.
The initialized model.
initialize,diseq_basic-method
: Basic disequilibrium model base
constructor
initialize,diseq_deterministic_adjustment-method
: Disequilibrium model with deterministic price
adjustment constructor
initialize,diseq_directional-method
: Directional disequilibrium model base constructor
initialize,diseq_stochastic_adjustment-method
: Disequilibrium model with stochastic price
adjustment constructor
initialize,equilibrium_model-method
: Equilibrium model constructor
simulated_data <- simulate_data( "diseq_basic", 500, 3, # model type, observed entities, observed time points -0.9, 8.9, c(0.3, -0.2), c(-0.03, -0.01), # demand coefficients 0.9, 6.2, c(0.03), c(-0.05, 0.02) # supply coefficients ) # initialize the model model <- new( "diseq_basic", # model type subject = id, time = date, quantity = Q, price = P, demand = P + Xd1 + Xd2 + X1 + X2, supply = P + Xs1 + X1 + X2, simulated_data, # data correlated_shocks = FALSE # use independent shocks ) show(model) simulated_data <- simulate_data( # model type, observed entities and time points "diseq_deterministic_adjustment", 500, 3, # demand coefficients -0.9, 8.9, c(0.03, -0.02), c(-0.03, -0.01), # supply coefficients 0.9, 4.2, c(0.03), c(0.05, 0.02), # price adjustment coefficient 1.4 ) # initialize the model model <- new( "diseq_deterministic_adjustment", # model type subject = id, time = date, quantity = Q, price = P, demand = P + Xd1 + Xd2 + X1 + X2, supply = P + Xs1 + X1 + X2, simulated_data, # data correlated_shocks = TRUE # allow shocks to be correlated ) show(model) simulated_data <- simulate_data( "diseq_directional", 500, 3, # model type, observed entities, observed time points -0.2, 4.3, c(0.03, 0.02), c(0.03, 0.01), # demand coefficients 0.0, 4.0, c(0.03), c(0.05, 0.02) # supply coefficients ) # in the directional model prices cannot be included in both demand and supply model <- new( "diseq_directional", # model type subject = id, time = date, quantity = Q, price = P, demand = P + Xd1 + Xd2 + X1 + X2, supply = Xs1 + X1 + X2, simulated_data, # data correlated_shocks = TRUE # allow shocks to be correlated ) show(model) simulated_data <- simulate_data( # model type, observed entities and time points "diseq_stochastic_adjustment", 500, 3, # demand coefficients -0.1, 9.8, c(0.3, -0.2), c(0.6, 0.1), # supply coefficients 0.1, 7.1, c(0.9), c(-0.5, 0.2), # price adjustment coefficient 1.4, 3.1, c(0.8) ) # initialize the model model <- new( "diseq_stochastic_adjustment", # model type subject = id, time = date, quantity = Q, price = P, demand = P + Xd1 + Xd2 + X1 + X2, supply = P + Xs1 + X1 + X2, price_dynamics = Xp1, simulated_data, # data correlated_shocks = TRUE # allow shocks to be correlated ) show(model) simulated_data <- simulate_data( "equilibrium_model", 500, 3, # model type, observed entities and time points -0.9, 14.9, c(0.3, -0.2), c(-0.03, -0.01), # demand coefficients 0.9, 3.2, c(0.3), c(0.5, 0.02) # supply coefficients ) # initialize the model model <- new( "equilibrium_model", # model type subject = id, time = date, quantity = Q, price = P, demand = P + Xd1 + Xd2 + X1 + X2, supply = P + Xs1 + X1 + X2, simulated_data, # data correlated_shocks = TRUE # allow shocks to be correlated ) show(model)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.