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.

Loading tab delimited data

Ask questions about data format and processing of data, including the use of pre-estimation functions in Apollo. If your question relates to a specific error you are getting, please provide some of the output.
Post Reply
svenne
Posts: 27
Joined: 26 Apr 2020, 16:20
Contact:

Loading tab delimited data

Post by svenne »

Dear all,

I run a post-estimation analysis on market share prediction for segments (subgroups) of my sample. My sample is cross-sectional and has 434 observations.

I estimated a simple MNL named MyModel. The database contains a characteristic (categorical) inc with 5 outcomes.

When I run

Code: Select all

sharesTest_settings=list()
sharesTest_settings[["alternatives"]] = c(A=1,B=2,C=3,D=4,E=5)
sharesTest_settings[["choiceVar"]]    = database$choice
sharesTest_settings[["subsamples"]]   = list(
                                             inc10k = (database$inc == 1),
                                             inc20k = (database$inc == 2),
                                             inc30k = (database$inc == 3),
                                             inc40k = (database$inc == 4),
                                             inc50k = (database$inc == 5)
                                           )
apollo_inputs = apollo_validateInputs()
apollo_sharesTest(MyModel,apollo_probabilities,apollo_inputs,sharesTest_settings)
I get

Code: Select all

Error in data.frame(..., check.names = FALSE) : 
  arguments imply differing number of rows: 0, 434
In addition: Warning message:
In split.default(x = seq_len(nrow(x)), f = f, drop = drop, ...) :
  data length is not a multiple of split variable
Google tells me that this may have something to do with the row ID. However, I am stuck here. Any help would be greatly appreciated.

Best
Sven
stephanehess
Site Admin
Posts: 974
Joined: 24 Apr 2020, 16:29

Re: Error for market share recovery for subgroups of data (Sec. 9.6)

Post by stephanehess »

Hi Sven

this is not an error message we've ever come across.

Can you confirm which version of Apollo you're using? Also, are you making any changes to the data between estimation and calling apollo_sharesTest?

Stephane
--------------------------------
Stephane Hess
www.stephanehess.me.uk
svenne
Posts: 27
Joined: 26 Apr 2020, 16:20
Contact:

Re: Error for market share recovery for subgroups of data (Sec. 9.6)

Post by svenne »

Hi Stephane,

Thanks for the prompt reply. I use Apollo 0.2.2. I do not modify the data from estimation to prediction.

However, I think I could narrow down the error to some extent: In estimation the number of individuals is wrong. See the following excerpt.

Model run using Apollo for R, version 0.2.2 on Darwin by svenmueller
www.ApolloChoiceModelling.com

Model name : Base
Model description : Basline model: challenge question 1
Model run at : 2021-02-03 12:13:37
Estimation method : bfgs
Model diagnosis : successful convergence
Number of individuals : 1
Number of rows in database : 434
Number of modelled outcomes : 434

However, I point in apollo_control to the ID column:

Code: Select all

apollo_initialise()
apollo_control=list(modelName="Base",
                    modelDescr="Basline model",
                    indivID="ID",
                    panelData = FALSE
)
My database looks like

Code: Select all

> head(database[,22:26])
# A tibble: 6 x 5
  avail3 avail4 avail5  ones    ID
   <dbl>  <dbl>  <dbl> <dbl> <int>
1      1      0      1     1     1
2      1      0      1     1     2
3      1      0      1     1     3
4      1      0      1     1     4
5      1      0      1     1     5
6      1      0      1     1     6
When I apply out of sample validation I get

Code: Select all

> ## cross Validation / Out of Sample Test
> apollo_outOfSample(apollo_beta, apollo_fixed,
+                    apollo_probabilities, apollo_inputs)
10 separate runs will be conducted, each using a random subset of 90% for estimation and
  the remainder for validation.
Error in apollo_outOfSample(apollo_beta, apollo_fixed, apollo_probabilities,  : 
  validationSize must be between 1 and (nIndivs-1).
I strongly think that the two errors (out of sample validation and market shares of subsamples) are both due to the problem with the number of individuals.

Unfortunately, I do not see how to correct for this.

Best
Sven
stephanehess
Site Admin
Posts: 974
Joined: 24 Apr 2020, 16:29

Re: Error for market share recovery for subgroups of data (Sec. 9.6)

Post by stephanehess »

Sven

very strange, you may have found a bug. Could you drop the line panelData = FALSE as you don't need, and let's see if this changes things.

Thanks

Stephane
--------------------------------
Stephane Hess
www.stephanehess.me.uk
svenne
Posts: 27
Joined: 26 Apr 2020, 16:20
Contact:

Re: Error for market share recovery for subgroups of data (Sec. 9.6)

Post by svenne »

Stephane,

If I drop panelData then I get by

Code: Select all

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.
All checks on database completed.
Should I send you my .R script and the data?

Best
Sven
stephanehess
Site Admin
Posts: 974
Joined: 24 Apr 2020, 16:29

Re: Error for market share recovery for subgroups of data (Sec. 9.6)

Post by stephanehess »

Sven

thanks. So does the data in fact contain multiple rows for some people?

Stephane
--------------------------------
Stephane Hess
www.stephanehess.me.uk
svenne
Posts: 27
Joined: 26 Apr 2020, 16:20
Contact:

Re: Error for market share recovery for subgroups of data (Sec. 9.6)

Post by svenne »

Stephane,

actually no. I use an excerpt of the residential telephone service data (Train et al. 1987). As far as I know this is cross sectional RP.

Best
Sven
svenne
Posts: 27
Joined: 26 Apr 2020, 16:20
Contact:

Re: Error for market share recovery for subgroups of data (Sec. 9.6)

Post by svenne »

Thanks to Stephane the issue could be resolved. I loaded the data as

Code: Select all

database <- read_delim("mydata.txt", 
                       "\t", escape_double = FALSE, 
                       trim_ws = TRUE)
However,

Code: Select all

database <- read.delim("mydata.txt")
does the job.

Best
Sven
Post Reply