Page 1 of 1

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

Posted: 08 Oct 2022, 12:18
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.

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

Posted: 10 Oct 2022, 16:57
by stephanehess
Hi

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

Stephane

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

Posted: 12 Oct 2022, 07:21
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

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

Posted: 12 Oct 2022, 07:25
by psalazar
Thank you, Stephane!

Best wishes,

Pamela.