Page 1 of 1

Estimates not appearing

Posted: 18 Feb 2021, 11:29
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

Re: Estimates not appearing

Posted: 19 Feb 2021, 14:00
by dpalma
Hi,

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

Cheers
David

Re: Estimates not appearing

Posted: 19 Feb 2021, 15:51
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.

Re: Estimates not appearing

Posted: 24 Feb 2021, 17:05
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

Re: Estimates not appearing

Posted: 24 Feb 2021, 17:19
by jbas
Sure, will do.