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.

Estimates not appearing

Report bugs or highlight issues with Apollo functions. At a minimum, please include the part of the output where you believe the bug is manifested. Ideally, please share your model file.
Post Reply
jbas
Posts: 6
Joined: 18 Feb 2021, 10:57

Estimates not appearing

Post by jbas »

Hi,

I'm not sure whether this is a bug but or I'm doing something wrong, my apologies in advance if the latter.

When running

Code: Select all

apollo_modelOutput(model)
the output in the console does not show anything below Estimates:. Please, see this example, for instance:

Code: Select all

Model run using Apollo for R, version 0.2.3 on Windows by javierbas 
www.ApolloChoiceModelling.com

Model name                       : NL_1
Model description                : Preliminary two-level Nested Logit
Model run at                     : 2021-02-18 12:25:42
Estimation method                : bfgs
Model diagnosis                  : successful convergence 
Number of individuals            : 153
Number of rows in database       : 918
Number of modelled outcomes      : 918

Number of cores used             :  1 
Model without mixing

LL(start)                        : -1257.912
LL(0)                            : -1272.618
LL(final)                        : -963.9705
Rho-square (0)                   :  0.2425 
Adj.Rho-square (0)               :  0.237 
AIC                              :  1941.94 
BIC                              :  1975.7 


Estimated parameters             :  7
Time taken (hh:mm:ss)            :  00:00:15.6 
     pre-estimation              :  00:00:0.72 
     estimation                  :  00:00:9.8 
     post-estimation             :  00:00:5.08 
Iterations                       :  32  
Min abs eigenvalue of Hessian    :  0.147767 

Estimates:

Nesting structure for NL model component :
Nest: root (1)
|----Alternative: car
'-Nest: NM (1.6199)
   |-Alternative: bike
   |-Alternative: walk
   '-Alternative: other
dpalma
Posts: 190
Joined: 24 Apr 2020, 17:54

Re: Estimates not appearing

Post by dpalma »

Hi,

Could you share your code? That should give us more information to diagnose the problem.

Cheers
David
jbas
Posts: 6
Joined: 18 Feb 2021, 10:57

Re: Estimates not appearing

Post by jbas »

Thanks for your reply.
Sure, here it is.

Code: Select all

```{r Init, include=FALSE}
print("To strive, to seek, to find, and not to yield.")
```


```{r Libraries, include=FALSE}
suppressWarnings(suppressMessages(library(apollo)))
suppressWarnings(suppressMessages(library(dplyr)))
```


```{r, include=FALSE}

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

### Initialise code
apollo_initialise()

### Set core controls
apollo_control = list(
  modelName  ="NL_1",
  modelDescr ="Preliminary two-level Nested Logit",
  indivID    ="ID"
)
```


```{r}
database <- read.csv("./data_reshaped.csv")

# Data treatment

database$av_car <- 1
database$av_bike <- 1
database$av_walk <- 1
database$av_other <- 1

```

```{r}
# ################################################################# #
#### DEFINE MODEL PARAMETERS                                     ####
# ################################################################# #

### Vector of parameters, including any that are kept fixed in estimation
apollo_beta=c(asc_car      = 0,
              asc_bike      = 0,
              asc_walk      = 0,
              asc_other     = 0,
              #b_travel_time = 0,
              b_travel_time_nm = 0,
              b_travel_time_car = 0,
              #b_travel_time_bike = 0,
              #b_travel_time_walk = 0,
              b_travel_cost_car = 0,
              #b_parking_cost_car = 0,
              b_LTS_bike = 0,
              b_LTS_walk = 0,
              # #b_purpose_ws     = 0,
              #b_purpose_sh     = 0,
              #b_purpose_so     = 0,
              #b_purpose_o     = 0,
              #b_homebased   = 0,
              #b_length      = 0
              lambda_nomotor = 0.95 # One lambda for each nest (and subnest) that contains more than one alternatives
              )

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

### Read in starting values for at least some parameters from existing model output file
#apollo_beta=apollo_readBeta(apollo_beta,apollo_fixed,"Apollo_example_3",overwriteFixed=FALSE)

```

```{r}
# ################################################################# #
#### GROUP AND VALIDATE INPUTS                                   ####
# ################################################################# #

apollo_inputs = apollo_validateInputs()
```

```{r}
# ################################################################# #
#### 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()
  
  ### List of utilities: these must use the same names as in mnl_settings, order is irrelevant
  V = list()
  
  V[['car']]  = asc_car  + 
    #b_travel_time  * CARTT +
    b_travel_time_car * CARTT +
    b_travel_cost_car * CARCOST +
    b_travel_cost_car * CARPCOST
  
  V[['bike']]  = asc_bike  + 
    #b_travel_time  * BIKETT +
    b_travel_time_nm * BIKETT +
    #b_travel_time_bike  * BIKETT +
    b_LTS_bike * BIKELTS
  
  V[['walk']]  = asc_walk +
    #b_travel_time  * WALKTT +
    b_travel_time_nm * WALKTT +
    #b_travel_time_walk  * WALKTT +
    b_LTS_walk * WALKLTS
  
  V[['other']] = asc_other 
  
  ### Specify nests for NL model
  nlNests      = list(root=1, NM=lambda_nomotor)
  
  ### Specify tree structure for NL model
  nlStructure = list()
  nlStructure[["root"]]   = c("car","NM")
  nlStructure[["NM"]]     = c("bike","walk","other")
  
  ### Define settings for NL model
  nl_settings <- list(
    alternatives = c(car=1, bike=2, walk=3, other=4),
    avail        = list(car=av_car, bike=av_bike, walk=av_walk, other=av_other),
    choiceVar    = CHOICE,
    V            = V,
    nlNests      = nlNests,
    nlStructure  = nlStructure
  )
  
  ### Compute probabilities using MNL model
  P[['model']] = apollo_nl(nl_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)
}

```


```{r}
# ################################################################# #
#### MODEL ESTIMATION                                            ####
# ################################################################# #

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


```{r}
# ################################################################# #
#### MODEL OUTPUTS                                               ####
# ################################################################# #

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

apollo_modelOutput(model)

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

apollo_saveOutput(model)

```

Thanks.
stephanehess
Site Admin
Posts: 974
Joined: 24 Apr 2020, 16:29

Re: Estimates not appearing

Post by stephanehess »

Hi

at face value, nothing seems wrong with the code. Could you share your data with us by e-mail and we'll look into it

Thanks

Stephane
--------------------------------
Stephane Hess
www.stephanehess.me.uk
jbas
Posts: 6
Joined: 18 Feb 2021, 10:57

Re: Estimates not appearing

Post by jbas »

Sure, will do.
Post Reply