Page 1 of 1

MDCEV RP_SP: identification problem

Posted: 01 Sep 2024, 16:58
by Julián
Hi Professors,

I have a mode choice experiment data with two alternatives. I like to make a joint estimation of RP and SP data in MDCEV. I have followed the code example MNL_RP_SP and I have tried to adapt it for the MDCEV, but I am not sure if it is ok. I got the following message:

Error en apollo_estimate(apollo_beta, apollo_fixed, apollo_probabilities, :
SPECIFICATION ISSUE - Parameter delta_road does not influence the log-likelihood of your model!

When I estimate the model using only SP data, there is no identification problem. So, maybe I am doing something wrong when trying the joint RP_SP estimation.

I share the code with you:
# ################################################################# #

### Clear memory
rm(list = ls())

### Load Apollo library
library(apollo)

### Initialise code
apollo_initialise()

### Set core controls
apollo_control = list(
modelName = "MDCEV_ETS",
modelDescr = "MDCEV model, alpha-gamma profile, no outside good and constants only in utilities",
indivID = "ID",
outputDirectory = "output"
)

# ################################################################# #
#### LOAD DATA AND APPLY ANY TRANSFORMATIONS ####
# ################################################################# #

### Loading data from package
### if data is to be loaded from a file (e.g. called data.csv),
### the code would be: database = read.csv("data.csv",header=TRUE)
database = read.csv("datafinv8cmrp.csv",header=TRUE, sep=";")
### 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_road3 = 1,
gamma_sss3 = 1,
delta_road = 0,
b_cost = 0,
b_cost_sss = 0,
b_cost_sss_fs = 0,
b_frequency = 0,
b_frequency_sss = 0,
b_frequency_sss_fs = 0,
b_delays = 0,
b_delays_sss = 0,
b_delays_sss_fs = 0,
mu_RP = 1,
mu_SP = 1,
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", "alpha_base", "mu_RP")

# ################################################################# #
#### 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("road3",
"sss3")

### Define availabilities
avail = list(road3 = 1,
sss3 = 1)

### Define continuous consumption for individual alternatives
continuousChoice = list(road3 = road3,
sss3 = sss3)

### Define utilities for individual alternatives
V = list()
V[["road3" ]] = delta_road + b_cost * CCAR + b_cost_sss * CCAR * SPTMCD2 + b_cost_sss_fs * CCAR * SPTMCD * fullstrategy + b_delays * RET_CAR + b_delays_sss * RET_CAR * SPTMCD2 + b_delays_sss_fs * RET_CAR * SPTMCD * fullstrategy
V[["sss3" ]] = b_cost * CTMCD + b_cost_sss * CTMCD * SPTMCD2 + b_cost_sss_fs * CTMCD * SPTMCD * fullstrategy + b_frequency * FREC + b_frequency_sss * FREC * SPTMCD2 + b_frequency_sss_fs * FREC * SPTMCD * fullstrategy + b_delays_sss * RET_TMCD * SPTMCD2 + b_delays_sss_fs * RET_TMCD * SPTMCD * fullstrategy + b_delays * RET_TMCD


### Define alpha parameters
alpha = list(road3 = 1 /(1 + exp(-alpha_base)),
sss3 = 1 /(1 + exp(-alpha_base)))

### Define gamma parameters
gamma = list(road3 = gamma_road3,
sss3 = gamma_sss3)

### Define costs for individual alternatives
cost = list(road3 = 1,
sss3 = 1)

### Define settings for MDCEV model RP
mdcev_settings_RP <- list(alternatives = alternatives,
avail = avail,
continuousChoice = continuousChoice,
utilities = V,
alpha = alpha,
gamma = gamma,
sigma = sig,
cost = cost,
budget = 100,
utilities = list(road3 = mu_RP*V[["road3"]],
sss3 = mu_RP*V[["sss3"]]),
rows = (RP==1)
)

### Compute probabilities using MDCEV model RP
P[["RP"]] = apollo_mdcev(mdcev_settings_RP, functionality)

### Define settings for MDCEV model SP
mdcev_settings_SP <- list(alternatives = alternatives,
avail = avail,
continuousChoice = continuousChoice,
utilities = V,
alpha = alpha,
gamma = gamma,
sigma = sig,
cost = cost,
budget = 100,
utilities = list(road3 = mu_SP*V[["road3"]],
sss3 = mu_SP*V[["sss3"]]),
rows = (SP==1)
)

### Compute probabilities using MDCEV model SP
P[["SP"]] = apollo_mdcev(mdcev_settings_SP, functionality)

### Combined model
P = apollo_combineModels(P, apollo_inputs, 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)

# ################################################################# #
#### MODEL OUTPUTS ####
# ################################################################# #

# ----------------------------------------------------------------- #
#---- FORMATTED OUTPUT (TO SCREEN) ----
# ----------------------------------------------------------------- #

apollo_modelOutput(model)

# ----------------------------------------------------------------- #
#---- FORMATTED OUTPUT (TO FILE, using model name) ----
# ----------------------------------------------------------------- #

apollo_saveOutput(model)

# ################################################################# #
##### POST-PROCESSING ####
# ################################################################# #

### Print outputs of additional diagnostics to new output file (remember to close file writing when complete)
apollo_sink()


I also share the error:
> ### Initialise code
> apollo_initialise()
Apollo ignition sequence completed
>
> ### Set core controls
> apollo_control = list(
+ modelName = "MDCEV_ETS",
+ modelDescr = "MDCEV model, alpha-gamma profile, no outside good and constants only in utilities",
+ indivID = "ID",
+ outputDirectory = "output"
+ )
>
> # ################################################################# #
> #### LOAD DATA AND APPLY ANY TRANSFORMATIONS ####
> # ################################################################# #
>
> ### Loading data from package
> ### if data is to be loaded from a file (e.g. called data.csv),
> ### the code would be: database = read.csv("data.csv",header=TRUE)
> database = read.csv("datafinv8cmrp.csv",header=TRUE, sep=";")
> ### 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_road3 = 1,
+ gamma_sss3 = 1,
+ delta_road = 0,
+ b_cost = 0,
+ b_cost_sss = 0,
+ b_cost_sss_fs = 0,
+ b_frequency = 0,
+ b_frequency_sss = 0,
+ b_frequency_sss_fs = 0,
+ b_delays = 0,
+ b_delays_sss = 0,
+ b_delays_sss_fs = 0,
+ mu_RP = 1,
+ mu_SP = 1,
+ 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", "alpha_base", "mu_RP")
>
> # ################################################################# #
> #### GROUP AND VALIDATE INPUTS ####
> # ################################################################# #
>
> apollo_inputs = apollo_validateInputs()
Several observations per individual detected based on the value of ID.
Setting panelData in apollo_control set to TRUE.
All checks on apollo_control completed.
WARNING: Your database contains some entries that are NA. This may well be
intentional, but be advised that if these entries are used in your model,
the behaviour may be unexpected.
All checks on database completed.
>
> # ################################################################# #
> #### 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("road3",
+ "sss3")
+
+ ### Define availabilities
+ avail = list(road3 = 1,
+ sss3 = 1)
+
+ ### Define continuous consumption for individual alternatives
+ continuousChoice = list(road3 = road3,
+ sss3 = sss3)
+
+ ### Define utilities for individual alternatives
+ V = list()
+ V[["road3" ]] = delta_road + b_cost * CCAR + b_cost_sss * CCAR * SPTMCD2 + b_cost_sss_fs * CCAR * SPTMCD * fullstrategy + b_delays * RET_CAR + b_delays_sss * RET_CAR * SPTMCD2 + b_delays_sss_fs * RET_CAR * SPTMCD * fullstrategy
+ V[["sss3" ]] = b_cost * CTMCD + b_cost_sss * CTMCD * SPTMCD2 + b_cost_sss_fs * CTMCD * SPTMCD * fullstrategy + b_frequency * FREC + b_frequency_sss * FREC * SPTMCD2 + b_frequency_sss_fs * FREC * SPTMCD * fullstrategy + b_delays_sss * RET_TMCD * SPTMCD2 + b_delays_sss_fs * RET_TMCD * SPTMCD * fullstrategy + b_delays * RET_TMCD
+
+
+ ### Define alpha parameters
+ alpha = list(road3 = 1 /(1 + exp(-alpha_base)),
+ sss3 = 1 /(1 + exp(-alpha_base)))
+
+ ### Define gamma parameters
+ gamma = list(road3 = gamma_road3,
+ sss3 = gamma_sss3)
+
+ ### Define costs for individual alternatives
+ cost = list(road3 = 1,
+ sss3 = 1)
+
+ ### Define settings for MDCEV model RP
+ mdcev_settings_RP <- list(alternatives = alternatives,
+ avail = avail,
+ continuousChoice = continuousChoice,
+ utilities = V,
+ alpha = alpha,
+ gamma = gamma,
+ sigma = sig,
+ cost = cost,
+ budget = 100,
+ utilities = list(road3 = mu_RP*V[["road3"]],
+ sss3 = mu_RP*V[["sss3"]]),
+ rows = (RP==1)
+ )
+
+ ### Compute probabilities using MDCEV model RP
+ P[["RP"]] = apollo_mdcev(mdcev_settings_RP, functionality)
+
+ ### Define settings for MDCEV model SP
+ mdcev_settings_SP <- list(alternatives = alternatives,
+ avail = avail,
+ continuousChoice = continuousChoice,
+ utilities = V,
+ alpha = alpha,
+ gamma = gamma,
+ sigma = sig,
+ cost = cost,
+ budget = 100,
+ utilities = list(road3 = mu_SP*V[["road3"]],
+ sss3 = mu_SP*V[["sss3"]]),
+ rows = (SP==1)
+ )
+
+ ### Compute probabilities using MDCEV model SP
+ P[["SP"]] = apollo_mdcev(mdcev_settings_SP, functionality)
+
+ ### Combined model
+ P = apollo_combineModels(P, apollo_inputs, 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)
Preparing user-defined functions.

Testing likelihood function...
Apollo found a model component of type MDCEV without a componentName. The
name was set to "RP" by default.

Overview of choices for model component RP:
road3 sss3
Times available 40.00 40.0
Observations in which chosen 34.00 14.0
Average consumption when available 75.50 24.5
Average consumption when chosen 88.82 70.0
Apollo found a model component of type MDCEV without a componentName. The
name was set to "SP" by default.

Overview of choices for model component SP:
road3 sss3
Times available 405.00 405.00
Observations in which chosen 377.00 190.00
Average consumption when available 77.01 22.99
Average consumption when chosen 82.73 49.00

Pre-processing likelihood function...
Analytical gradients could not be calculated for all components, numerical
gradients will be used.

Testing influence of parameters..Error en apollo_estimate(apollo_beta, apollo_fixed, apollo_probabilities, :
SPECIFICATION ISSUE - Parameter delta_road does not influence the log-likelihood of your model!


Please, how can I solve this problem?

Thank you in advance.

Julian

Re: MDCEV RP_SP: identification problem

Posted: 07 Sep 2024, 17:16
by stephanehess
Hi

if you can share your data and code with me outside the forum, then I can check this for you. It's not immediately clear what's wrong

Stephane

Re: MDCEV RP_SP: identification problem

Posted: 09 Sep 2024, 12:16
by Julián
Hi Stephane,

Thank you very much! I have already shared the code and data with you.

Regards,

Stephane

Re: MDCEV RP_SP: identification problem

Posted: 09 Sep 2024, 20:48
by stephanehess
It looks like in your case, the issue is not caused by joint RP-SP estimation, but by the RP data. So you'll first have to get a model working on the RP data.

Also, no need to constrain alpha_base to 0, as that would imply constraining alpha to 0.5