I encountered an error from Apollo when using MDCEV model when Testing likelihood function.
The error goes like this:
"Error in apollo_validate(mdcev_settings, modelType, functionality, apollo_inputs) :
Expenditure for some observations for model component "model" is either less or more than budget!"
The budget in my data is set as "salary", where salary = saving + inv + expenditure, such that there is no outside good and expenditure is set as "other" that will always be chosen.
The dataset is based on household finance data and there is no real data of salary, "expenditure" is also calculated via total annual household expenditure: expenditure = total_expenditure/12.
I was wondering is it possible that the issue is actually caused by my "fake data"? Or is there any other reason that might lead to this error?
Thank you for your time in advance!
The original code is as follows:
Code: Select all
### Vector of parameters, including any that are kept fixed in estimation
apollo_beta = c(alpha_base = 0,
gamma_saving = 1,
gamma_investment = 1,
gamma_other = 1,
delta_saving = 0,
delta_investment = 0,
delta_other = 0,
sigma = 1)
### Vector with names (in quotes) of parameters to be kept fixed at their starting value in apollo_beta, use apollo_beta_fixed = c() if none
apollo_fixed = c("delta_saving", "sigma")
# ################################################################# #
#### GROUP AND VALIDATE INPUTS ####
# ################################################################# #
apollo_inputs = apollo_validateInputs()
# ################################################################# #
#### DEFINE MODEL AND LIKELIHOOD FUNCTION ####
# ################################################################# #
apollo_probabilities=function(apollo_beta, apollo_inputs, functionality="estimate"){
### Attach inputs and detach after function exit
apollo_attach(apollo_beta, apollo_inputs)
on.exit(apollo_detach(apollo_beta, apollo_inputs))
### Create list of probabilities P
P = list()
### Define individual alternatives
alternatives = c("saving",
"investment",
"other")
### Define availabilities
avail = list(saving = 1,
investment = 1,
other = 1)
### Define continuous consumption for individual alternatives
continuousChoice = list(saving = saving,
investment = inv,
other = expenditure)
### Define utilities for individual alternatives
V = list()
V[["saving" ]] = delta_saving
V[["investment"]] = delta_investment
V[["other"]] = delta_other
### Define alpha parameters
alpha = list(saving = 1 /(1 + exp(-alpha_base)),
investment = 1 /(1 + exp(-alpha_base)),
other = 1 /(1 + exp(-alpha_base)))
### Define gamma parameters
gamma = list(saving = gamma_saving,
investment = gamma_investment,
other = gamma_other)
### Define costs for individual alternatives
cost = list(saving = 1,
investment = 1,
other = 1)
### Define budget
budget = salary
### Define settings for MDCEV model
mdcev_settings <- list(alternatives = alternatives,
avail = avail,
continuousChoice = continuousChoice,
V = V,
alpha = alpha,
gamma = gamma,
sigma = sigma,
cost = cost,
budget = budget)
### Compute probabilities using MDCEV model
P[["model"]] = apollo_mdcev(mdcev_settings, functionality)
### Take product across observation for same individual
P = apollo_panelProd(P, apollo_inputs, functionality)
### Prepare and return outputs of function
P = apollo_prepareProb(P, apollo_inputs, functionality)
return(P)
}