Page 1 of 1

Error in apollo_validateData when running Apollo_example_3.r code

Posted: 05 May 2021, 18:21
by theycallmemylinh
Hello,

I ran into the following error when I was running code that modelled that of the Apollo_example_3.r

"Error in apollo_validateData(database, apollo_control, silent = silent) :
All rows for the same individual should be next to each other in the data!"

I reviewed my dataset to make sure that it was in the right format (My dataset can be viewed from the Open Science Framework: https://osf.io/jfz5h and I've attached an image below as well, just in case there is an error on my part in creating the dataset)

I decided to run through the exact example as written in "Apollo_example_3.r" (http://www.apollochoicemodelling.com/fi ... xample_3.r) using the provided dataset "apollo_modeChoiceData.csv"
Description: MNL model with socio-demographics on mode choice SP data

Code: Select all

# ################################################################# #
#### 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  ="Apollo_example_3",
  modelDescr ="MNL model with socio-demographics on mode choice SP data",
  indivID    ="ID"
)

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

database <- read.csv("C:/Users/My-Linh/Dropbox/University of Melbourne/Research Toolbox/R vignettes/Apollo choice models/apollo_modeChoiceData.csv")

### Use only SP data
database = subset(database,database$SP==1)

### Create new variable with average income
database$mean_income = mean(database$income)

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

### Vector of parameters, including any that are kept fixed in estimation
apollo_beta=c(asc_car               = 0,
              asc_bus               = 0,
              asc_air               = 0,
              asc_rail              = 0,
              asc_bus_shift_female  = 0,
              asc_air_shift_female  = 0,
              asc_rail_shift_female = 0,
              b_tt_car              = 0,
              b_tt_bus              = 0,
              b_tt_air              = 0,
              b_tt_rail             = 0,
              b_tt_shift_business   = 0,
              b_access              = 0,
              b_cost                = 0,
              b_cost_shift_business = 0,
              cost_income_elast     = 0,
              b_no_frills           = 0,
              b_wifi                = 0,
              b_food                = 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("asc_car","b_no_frills")


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

apollo_inputs = apollo_validateInputs()

And ran into the same output error

"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.
Error in apollo_validateData(database, apollo_control, silent = silent) :
All rows for the same individual should be next to each other in the data!"

Any idea what might be going on? Thanks in advance for your help!

Re: Error in apollo_validateData when running Apollo_example_3.r code

Posted: 05 May 2021, 20:04
by dpalma
Hi,

I just ran the code you posted on my PC and it worked fine. So my first advise would be to make sure you are using the latest version of Apollo (v0.2.4). To do this, you simply need to run:

Code: Select all

install.packages("apollo")
Concerning your data, if you still face the same issue after updating Apollo, I would recommend changing the IDs to numerical values. For example, instead of the first ID being ff8644... you make it 1. The second fe27ec0c... becomes simply 2, and so on.

If that still doesn't solve the problem, it might be that R is reading the data wrongly. Issues can arise for many reasons. One of the most common issues is saving the data with commas (as opposed to dots) as decimal separators.

Let us know if after trying these tweaks you still have problems.

Best
David