Page 1 of 1

MDCEV model estimation - Budget not as a vector the same size as observation error

Posted: 05 May 2022, 21:15
by billyuoft
Hi,

I am getting an error saying that the budget in my MDCEV model specification should be a scalar or a vector the same size as the observations.
"Error in apollo_preprocess(mdcev_settings, modelType, functionality, apollo_inputs) :
"budget" for model component "MDCEV" should be a scalar or a vector with as many elements as observations."

I checked that there are 826 obs. in my data and the length of the budget vector is also 826. Could anyone help me out to see where the problem is? Much appreciated!

Here is my code:
### the code would be: database = read.csv("data.csv",header=TRUE)
database = read.csv("Project_MDCEV.csv",header=TRUE)
alt = read.csv("alternatives.csv",header=TRUE)
attach(database)
View(database)
### for data dictionary, use ?apollo_timeUseData

# ################################################################# #
#### DEFINE MODEL PARAMETERS ####
# ################################################################# #

### Vector of parameters, including any that are kept fixed in estimation
apollo_beta = c(alpha_base = 0,
gamma_gen = 1,
delta_acar = 0,
sig = 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("sig")

# ################################################################# #
#### 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 = as.character(alt$DAUID)

### Define availabilities
avail = list()
for(i in alt$DAUID){
avail[paste0(i)] = 1
}

### Define continuous consumption for individual alternatives
continuousChoice = list()
for (i in alt$DAUID){
continuousChoice[paste0(i)] = get(paste0("X",i))
}

### Define utilities for individual alternatives
V = list()
for (i in alt$DAUID){
V[[paste0(i)]] = delta_acar *alt$ACAR[which(alt$DAUID==paste0(i))]
}


### Define alpha parameters
alpha = list()
for (i in alt$DAUID){
alpha[paste0(i)]=1/(1+exp(-alpha_base))
}


### Define gamma parameters
gamma =list()
for (i in alt$DAUID){
gamma[paste0(i)]=gamma_gen
}

### Define costs for individual alternatives
cost = list()
for(i in alt$DAUID){
cost[paste0(i)] = 1
}

budget <- budget_cal
### Define settings for MDCEV model
mdcev_settings <- list(alternatives = alternatives,
avail = avail,
continuousChoice = continuousChoice,
utilities = V,
alpha = alpha,
gamma = gamma,
sigma = sig,
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)
}

# ################################################################# #
#### MODEL ESTIMATION ####
# ################################################################# #

model = apollo_estimate(apollo_beta, apollo_fixed, apollo_probabilities, apollo_inputs)

Re: MDCEV model estimation - Budget not as a vector the same size as observation error

Posted: 06 May 2022, 19:53
by stephanehess
Hi

can you please first confirm what version of Apollo you are using as this could relate to an old bug

Thanks