Important: Read this before posting to this forum

  1. This forum is for questions related to the use of Apollo. We will answer some general choice modelling questions too, where appropriate, and time permitting. We cannot answer questions about how to estimate choice models with other software packages.
  2. There is a very detailed manual for Apollo available at http://www.ApolloChoiceModelling.com/manual.html. This contains detailed descriptions of the various Apollo functions, and numerous examples are available at http://www.ApolloChoiceModelling.com/examples.html. In addition, help files are available for all functions, using e.g. ?apollo_mnl
  3. Before asking a question on the forum, users are kindly requested to follow these steps:
    1. Check that the same issue has not already been addressed in the forum - there is a search tool.
    2. Ensure that the correct syntax has been used. For any function, detailed instructions are available directly in Apollo, e.g. by using ?apollo_mnl for apollo_mnl
    3. Check the frequently asked questions section on the Apollo website, which discusses some common issues/failures. Please see http://www.apollochoicemodelling.com/faq.html
    4. Make sure that R is using the latest official release of Apollo.
  4. If the above steps do not resolve the issue, then users should follow these steps when posting a question:
    1. provide full details on the issue, including the entire code and output, including any error messages
    2. posts will not immediately appear on the forum, but will be checked by a moderator first. This may take a day or two at busy times. There is no need to submit the post multiple times.

MMNL model with panel data

Ask questions about the results reported after estimation. If the output includes errors, please include your model code if possible.
Post Reply
sethyash52
Posts: 11
Joined: 09 Sep 2022, 06:38

MMNL model with panel data

Post by sethyash52 »

Why I am getting mean and standard deviation of some parameters as statistically insignificant? I have included code and results below please take a look on it. I am working on panel data where there are 4 observations per individual.

******************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************

# ################################################################# #
#### LOAD LIBRARY AND DEFINE CORE SETTINGS ####
# ################################################################# #

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

### Load Apollo library
library(apollo)

### Initialise code
apollo_initialise()

### Set core controls
apollo_control = list(
modelName = "ECL_preference_space_panel_effect",
modelDescr = "Error components logit model on Swiss route choice data, uncorrelated Lognormals in preference space, with panel effect term",
indivID = "Person_ID",
mixing = TRUE,
nCores = 4,
outputDirectory = "output"
)

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

setwd("")

getwd()

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

database = read.csv("",header=TRUE)
# ################################################################# #
#### DEFINE MODEL PARAMETERS ####
# ################################################################# #

### Vector of parameters, including any that are kept fixed in estimation
apollo_beta = c(mu_log_b_pp = -3,
sigma_log_b_pp = -0.01,
mu_log_b_oc = -3,
sigma_log_b_oc = -0.01,
mu_log_b_ct = -3,
sigma_log_b_ct = -0.01,
mu_log_b_r = -3,
sigma_log_b_r = -0.01,
b_e = 0,
sigma_panel = 0)

### 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()

# ################################################################# #
#### DEFINE RANDOM COMPONENTS ####
# ################################################################# #

### Set parameters for generating draws
apollo_draws = list(
interDrawsType = "mlhs",
interNDraws = 500,
interUnifDraws = c(),
interNormDraws = c("draws_pp","draws_oc","draws_ct","draws_r","draws_alt1","draws_alt2"),
intraDrawsType = "halton",
intraNDraws = 0,
intraUnifDraws = c(),
intraNormDraws = c()
)

### Create random parameters
apollo_randCoeff = function(apollo_beta, apollo_inputs){
randcoeff = list()

randcoeff[["b_pp"]] = -exp( mu_log_b_pp + sigma_log_b_pp * draws_pp )
randcoeff[["b_oc"]] = -exp( mu_log_b_oc + sigma_log_b_oc * draws_oc )
randcoeff[["b_ct"]] = -exp( mu_log_b_ct + sigma_log_b_ct * draws_ct )
randcoeff[["b_r"]] = -exp( mu_log_b_r + sigma_log_b_r * draws_r )
randcoeff[["ec_alt1"]] = sigma_panel * draws_alt1
randcoeff[["ec_alt2"]] = sigma_panel * draws_alt2

return(randcoeff)
}

# ################################################################# #
#### GROUP AND VALIDATE INPUTS ####
# ################################################################# #

apollo_inputs = apollo_validateInputs()

# ################################################################# #
#### DEFINE MODEL AND LIKELIHOOD FUNCTION ####
# ################################################################# #

apollo_probabilities=function(apollo_beta, apollo_inputs, functionality="estimate"){

### Function initialisation: do not change the following three commands
### 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()

### List of utilities: these must use the same names as in mnl_settings, order is irrelevant
V = list()
V[["alt1"]] = b_pp*ppEV + b_oc*ocEV + b_ct*ctEV + b_r*rEV + b_e*eEV + ec_alt1
V[["alt2"]] = b_pp*ppCV + b_oc*ocCV + b_ct*ctCV + b_r*rCV + b_e*eCV + ec_alt2

### Define settings for MNL model component
mnl_settings = list(
alternatives = c(alt1=1, alt2=2),
avail = list(alt1=1, alt2=1),
choiceVar = CHALT,
utilities = V
)

### Compute probabilities using MNL model
P[["model"]] = apollo_mnl(mnl_settings, functionality)

### Take product across observation for same individual
P = apollo_panelProd(P, apollo_inputs, functionality)

### Average across inter-individual draws
P = apollo_avgInterDraws(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)

******************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************

Estimates:
Estimate s.e. t.rat.(0) Rob.s.e. Rob.t.rat.(0)
mu_log_b_pp -1.50557 1.07720 -1.397669 0.85757 -1.75563
sigma_log_b_pp -1.01690 1.02521 -0.991900 0.73934 -1.37543
mu_log_b_oc -5.89415 0.63766 -9.243339 0.40335 -14.61288
sigma_log_b_oc -3.80494 0.44928 -8.468923 0.22814 -16.67813
mu_log_b_ct -8.32174 0.82787 -10.052048 0.31731 -26.22584
sigma_log_b_ct -13.15450 1.00469 -13.093100 0.32429 -40.56397
mu_log_b_r -28.62923 6.181e+05 -4.632e-05 0.66774 -42.87467
sigma_log_b_r -0.66243 6.128e+05 -1.081e-06 0.86745 -0.76365
b_e -0.04314 0.07606 -0.567181 0.07485 -0.57634
sigma_panel 9.1747e-04 0.14410 0.006367 0.02576 0.03562
stephanehess
Site Admin
Posts: 998
Joined: 24 Apr 2020, 16:29

Re: MMNL model with panel data

Post by stephanehess »

This is an empirical finding telling you that these parameters are not different from zero with your data
--------------------------------
Stephane Hess
www.stephanehess.me.uk
Post Reply