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.

Aapollo_saveOutput: Error in paste0(rep(...

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

Aapollo_saveOutput: Error in paste0(rep(...

Post by psalazar »

Dear all,

I am estimating a simple MNL with two interaction terms (code below).I have no problems running the code, but when I ask Apollo to save it (apollo_saveOutput(model)), I get the following error:

Error in paste0(rep(" ", max(nchar(m)) - nchar(m)), m, collapse = "") : result would exceed 2^31-1 bytes


I would appreciate your support very much.

Best wishes,

Pamela.

Code: Select all

### Initialise code
apollo_initialise()

### Set core controls
apollo_control = list(
  modelName       = "MNL_data_Design1_asc_interactionsF",
  modelDescr      = "MNL model with data from actual study.Data from Design 1 and asc to capture any left-right bias.Interaction Cost & Exp",
  indivID         = "id",  # Name of column in the database with each individual's ID
  outputDirectory = "output"
)


setwd("J:/Oxford 2020-2023/Research Pamela/Criteria & DCE/DCE_InegratedCare_Analysis")
##OR: set working directory: Session >> set working directory >>To source file location 

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

database <- read.csv('J:/Oxford 2020-2023/Research Pamela/Criteria & DCE/DCE_InegratedCare_Analysis/data_r/DCE_Data_Design1_R.csv') 

### Use actual data (i.e. no pilot data). 
database = subset(database,database$study_type=="Main")  

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

### 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,
              bexpf_cost = 0,
              bexpg_cost = 0
)

apollo_fixed = c()

# ################################################################# #
#### 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 +  bexpf_cost*((exp1=1)*cost1) + bexpg_cost*((exp1=2)*cost1) 
  V[["Alt2"]]  =         byol*yol2  +  bqol*qol2 + bexp_fair*(exp2==1) + bexp_good*(exp2==2) + bsize*size2 + bequ*equ2 + bcost*cost2 +  bexpf_cost*((exp2=1)*cost2) + bexpg_cost*((exp2=2)*cost2)
  
  
  ### Define settings for MNL model component
  mnl_settings   = list(
    alternatives = c(Alt1=1, Alt2=2), 
    avail        = list(Alt1=1, Alt2=1),
    choiceVar    = chosen_option,
    V            = V
  )
  
  ### Compute probabilities using MNL model
  P[["model"]] = apollo_mnl(mnl_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)
}

# ################################################################# #
#### MODEL ESTIMATION                                            ####
# ################################################################# #

model = apollo_estimate(apollo_beta, apollo_fixed, apollo_probabilities, apollo_inputs)

# ################################################################# #
#### MODEL OUTPUTS                                               ####
# ################################################################# #

# ----------------------------------------------------------------- #
#---- FORMATTED OUTPUT (TO SCREEN)                               ----
# ----------------------------------------------------------------- #

apollo_modelOutput(model, modelOutput_settings=list(printPVal = TRUE, printOutliers= TRUE))
stephanehess
Site Admin
Posts: 974
Joined: 24 Apr 2020, 16:29

Re: Aapollo_saveOutput: Error in paste0(rep(...

Post by stephanehess »

Pamela

sorry about the slow reply. Do you get the error also with the on screen output, i.e. using apollo_modelOutput?

Thanks

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

Re: Aapollo_saveOutput: Error in paste0(rep(...

Post by psalazar »

Hi Stephane,

Many thanks! I found the solution. I was getting the error also with the on-screen output, and solved it by treating all variables as categorical. Checking for potential correlation between attributes has been challenging as my experimental design did not fully account for it (ended up using a model averaging approach (Rose et al, 2009)).

Best wishes,

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

Re: Aapollo_saveOutput: Error in paste0(rep(...

Post by stephanehess »

Pamela

it shouldn't be related to that. Could you share the code and data that lead to the error with me and I'll have a look

Stephane
--------------------------------
Stephane Hess
www.stephanehess.me.uk
Post Reply