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.

Joint estimation on two SP datasets. Error: Duplicated componentName found

Ask questions about errors you encouunter. Please make sure to include full details about your model specifications, and ideally your model file.
Post Reply
psalazar
Posts: 13
Joined: 22 Sep 2022, 13:56

Joint estimation on two SP datasets. Error: Duplicated componentName found

Post by psalazar »

Hi Stephane,

I am pooling data from two designs:
-Design 1 has 6 attributes
-Design 2 has the same attributes as Design 1, except for the last one "cost" (i.e. using only 5 attributes)

In my dataset, I have two binary variables to indicate Apollo which dataset I'm using: "Done" for data from Design 1, and "Dtwo" for data from design 2.

To estimate joint coefficients, I'm following this example: http://www.apollochoicemodelling.com/fi ... NL_RP_SP.r
Here is the code:

Code: Select all

### Vector of parameters, including any that are kept fixed in estimation
apollo_beta=c(asc        = 0,
              byol       = 0,
              bqol       = 0,
              bexp_fair  = 0,
              bexp_good  = 0,
              bsize      = 0,
              bequ       = 0,
              bcost      = 0,
              mu_Done    = 1,
              mu_Dtwo    = 1
              )

### 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
##If we want to keep parameters fixed to their starting values during the estimation (eg. asc), we include their names in the character vector apollo_fixed. 
## this vector is kept empty (apollo_fixed = c()) if all parameters are to be estimated. Parameters included in apollo_fixed are kept at the value used in apollo_beta, which may not be zero

apollo_fixed = c("mu_Done")

# ################################################################# #
#### 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"]]  =  asc +  byol*yol1  +  bqol*qol1 + bexp_fair*(exp1==1) + bexp_good*(exp1==2) + bsize*size1 + bequ*equ1 + bcost*cost1   
  V[["Alt2"]]  =         byol*yol2  +  bqol*qol2 + bexp_fair*(exp2==1) + bexp_good*(exp2==2) + bsize*size2 + bequ*equ2 + bcost*cost2 

  
  ### Compute probabilities for 'Design 1' of the data using MNL model
    ## Define settings for MNL model component
  mnl_settings_Done  = list(
            alternatives = c(Alt1=1, Alt2=2), 
            avail        = list(Alt1=1, Alt2=1),                      ##A list containing one element per alternative, using the same names as in alternatives (scalar of 1 because the alternative is always available) alternative is always available.)
            choiceVar    = chosen_option,
             utilities   = list(Alt1 = mu_Done*V[["Alt1"]],
                                Alt2 = mu_Done*V[["Alt2"]]),
            rows         = (Done==1)
  )
  
    ## Compute Design 1 probabilities using MNL model
  P[["Done"]] = apollo_mnl(mnl_settings_Done, functionality)
  
  
  
  
  ### Compute probabilities for 'Design 2' of the data using MNL model
    ### Define settings for MNL model component
  mnl_settings_Dtwo  = list(
           alternatives = c(Alt1=1, Alt2=2), 
           avail        = list(Alt1=1, Alt2=1),
           choiceVar    = chosen_option,
           utilities    = list(Alt1 = mu_Dtwo*V[["Alt1"]],
                               Alt2 = mu_Dtwo*V[["Alt2"]]),
           rows         = (Dtwo==1)
  )
  
    ### Compute Design 2 probabilities using MNL model
  P[["Dtwo"]] = apollo_mnl(mnl_settings_Dtwo, functionality)  
  
 
   ### Combined model
  P = apollo_combineModels(P, apollo_inputs, 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)
}
I'm getting the following error when I run the model: "Error in apollo_mnl(mnl_settings_Dtwo, functionality) :
Duplicated componentName found (MNL). Names must be different for each component." I checked the code and compared it with the example from the link, and can't see what's wrong with my code.

I also checked Chapt7 from the Apollo manual, and tried using the lapply function, but got the following error: "Error in get(as.character(FUN), mode = "function", envir = envir) :
object '∗' of mode 'function' was not found"


I also have one question about scaling: Both datasets are SP data and the choice tasks were practically the same (i.e same levels, same framing). The only difference lies in one attribute (i.e. Design 1 has six and Design 2 has five). Should I still expect scale differences between the two data sources?

I'd appreciate very much your help with this. Thanks!

Best wishes,

Pamela.
stephanehess
Site Admin
Posts: 998
Joined: 24 Apr 2020, 16:29

Re: Joint estimation on two SP datasets. Error: Duplicated componentName found

Post by stephanehess »

Hi

could you share your data with me and I'll look into the issue?

Stephane
--------------------------------
Stephane Hess
www.stephanehess.me.uk
stephanehess
Site Admin
Posts: 998
Joined: 24 Apr 2020, 16:29

Re: Joint estimation on two SP datasets. Error: Duplicated componentName found

Post by stephanehess »

Pamela

please download the development version (0.2.9) from http://apollochoicemodelling.com/code.html. This shoudl fix the issue with the wrong error message, and tells you what is really going wrong with your model

Best wishes

Stephane
--------------------------------
Stephane Hess
www.stephanehess.me.uk
psalazar
Posts: 13
Joined: 22 Sep 2022, 13:56

Re: Joint estimation on two SP datasets. Error: Duplicated componentName found

Post by psalazar »

Thank you, Stephane!

Best wishes,

Pamela.
Post Reply