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.

Error: Non-valid user-provided bgw_setting setting name detected: "writeIterMode"."

Ask questions about the results reported after estimation. If the output includes errors, please include your model code if possible.
Post Reply
Bob123
Posts: 9
Joined: 20 Jun 2023, 13:39

Error: Non-valid user-provided bgw_setting setting name detected: "writeIterMode"."

Post by Bob123 »

Dear Prof. Hess,

I have previously ran successfully, an MNL model on Apollo version v0.2.9 (about 6 weeks ago) which I used to obtain priors. I have now come back with full data and run the same model again (albeit different data).During this, I was prompted to update to Apollo v0.3.0 but since updating, during model estimation, I receive the following error:

Error in bgw::bgw_mle(calcR = f, betaStart = beta_var_val, calcJ = grad, :
Non-valid user-provided bgw_setting setting name detected: "writeIterMode"."

I cannot find anything related to bgw_setting in the R script or manual. The only thing I can see is that it writes the estimated parameter values in each iteration to a file in the working/output directory so the problem might be associated with this?

Any help would be very much appreciated.

Script below:

Code: Select all

# ### ############################################################# #
#### LOAD LIBRARY AND DEFINE CORE SETTINGS                       ####
# ################################################################# #

### Clear memory
rm(list = ls())

### Load libraries
library(apollo)

### Initialise code
apollo_initialise()

### Set core controls
apollo_control = list(
  modelName       = "MNL_Nonspeeders_all_data_BASE",
  modelDescr      = "First MNL model using Nonspeeders_all_data",
  indivID         = "RID", 
  outputDirectory = "MNL_Nonspeeders_all_data_BASE_OUTPUT"
)

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

database = read.csv("Nonspeeders_all_data.csv",header=TRUE)

### Run function to analyse choice data
#apollo_choiceAnalysis(choiceAnalysis_settings, apollo_control, database)

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

### Vector of parameters, including any that are kept fixed in estimation
apollo_beta=c(
 #asc:             
            asc_DrugA                 = 0,
  
 #main effects:             
            b_CERT_very_low           = 0,
            b_CERT_low                = 0,
            b_CERT_moderate           = 0,
            b_CERT_high               = 0, 
            b_WAIT                    = 0,
            
  #interaction effects (with WAIT) for scenario variables:              
            b_LIFExWAIT               = 0,
            b_QOL_light_workxWAIT     = 0, 
 # b_QOL_no_workxWAIT        = 0,
 # b_QOL_bed_50xWAIT         = 0,
            b_QOL_comp_disabledxWAIT  = 0,
            b_BENEFIT_smallxWAIT      = 0,
 # b_BENEFIT_moderatexWAIT   = 0,
            b_BENEFIT_substantialxWAIT= 0,
  #interaction effects
  #(with CERT) for 
  #scenario variables:              
 # b_LIFExCERT_very_low                 = 0,
 # b_LIFExCERT_low                      = 0,
 # b_LIFExCERT_moderate                 = 0,
 # b_LIFExCERT_high                     = 0,
 
           b_QOL_light_workxCERT_very_low       = 0,
 # b_QOL_no_workxCERT_very_low          = 0,
 # b_QOL_bed_50xCERT_very_low           = 0,
           b_QOL_comp_disabledxCERT_very_low    = 0,
 # b_QOL_light_workxCERT_low            = 0,
 # b_QOL_no_workxCERT_low               = 0,
 # b_QOL_bed_50xCERT_low                = 0,
 # b_QOL_comp_disabledxCERT_low         = 0,
 # b_QOL_light_workxCERT_moderate       = 0,
 # b_QOL_no_workxCERT_moderate          = 0,
 # b_QOL_bed_50xCERT_moderate           = 0,
 # b_QOL_comp_disabledxCERT_moderate    = 0,
           b_QOL_light_workxCERT_high           = 0,
 # b_QOL_no_workxCERT_high              = 0,
 # b_QOL_bed_50xCERT_high               = 0,
           b_QOL_comp_disabledxCERT_high        = 0,
           
           b_BENEFIT_smallxCERT_very_low        = 0,
 # b_BENEFIT_moderatexCERT_very_low    = 0,
           b_BENEFIT_substantialxCERT_very_low  = 0,
 # b_BENEFIT_smallxCERT_low             = 0,
 # b_BENEFIT_moderatexCERT_low         = 0,
 # b_BENEFIT_substantialxCERT_low       = 0,
 # b_BENEFIT_smallxCERT_moderate        = 0,
 # b_BENEFIT_moderatexCERT_moderate    = 0,
 # b_BENEFIT_substantialxCERT_moderate  = 0,
           b_BENEFIT_smallxCERT_high            = 0,
 # b_BENEFIT_moderatexCERT_high        = 0,
           b_BENEFIT_substantialxCERT_high      = 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_DrugA",
  
  "b_CERT_very_low")

#                 "b_QOL_light_workxWAIT",
#                 "b_BENEFIT_smallxWAIT",

#                 "b_LIFExCERT_very_low",
#                 "b_QOL_light_workxCERT_very_low",
#                 "b_QOL_no_workxCERT_very_low",
#                 "b_QOL_bed_50xCERT_very_low",
#                 "b_QOL_comp_disabledxCERT_very_low",
#                 "b_BENEFIT_smallxCERT_very_low",
#                 "b_BENEFIT_moderatexCERT_very_low",
#                 "b_BENEFIT_substantialxCERT_very_low")


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

apollo_inputs = apollo_validateInputs()

# ################################################################# #
#### DEFINE MODEL AND LIKELIHOOD FUNCTION                        ####
# ################################################################# #

apollo_probabilities=function(apollo_beta, apollo_inputs, functionality="estimate"){
  
  ### 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[["DrugA"]]  = 
    asc_DrugA                                                                    +
    b_CERT_very_low                    *  (DrugA_CERT == 1)                      + 
    b_CERT_low                         *  (DrugA_CERT == 2)                      +
    b_CERT_moderate                    *  (DrugA_CERT == 3)                      + 
    b_CERT_high                        *  (DrugA_CERT == 4)                      + 
    b_WAIT                             *   DrugA_WAIT                            +
    
    #Interactions with WAIT:
    b_LIFExWAIT                        *   DrugA_WAIT  *  LIFE                 +
    b_QOL_light_workxWAIT              * ( DrugA_WAIT  *  (QOL     == 1))      +
    #   b_QOL_no_workxWAIT                 * ( DrugA_WAIT  *  (QOL     == 2))      +
    #   b_QOL_bed_50xWAIT                  * ( DrugA_WAIT  *  (QOL     == 3))      +
    b_QOL_comp_disabledxWAIT           * ( DrugA_WAIT  *  (QOL     == 4))      +
    b_BENEFIT_smallxWAIT               * ( DrugA_WAIT  *  (BENEFIT == 1))      + 
    #   b_BENEFIT_moderatexWAIT            * ( DrugA_WAIT  *  (BENEFIT == 2))      +
    b_BENEFIT_substantialxWAIT         * ( DrugA_WAIT  *  (BENEFIT == 3))      +      
    
    #Interactions with CERT (all categorical levels):
    #   b_LIFExCERT_very_low              *   (  DrugA_CERT == 1)  * LIFE          +
    #  b_LIFExCERT_low                   *   (  DrugA_CERT == 2)  * LIFE          +
    #   b_LIFExCERT_moderate              *   (  DrugA_CERT == 3)  * LIFE          +
    #  b_LIFExCERT_high                  *   (  DrugA_CERT == 4)  * LIFE          +
    b_QOL_light_workxCERT_very_low      * ( (DrugA_CERT == 1)  * (QOL == 1))   +
    #  b_QOL_light_workxCERT_low           * ( (DrugA_CERT == 2)  * (QOL == 1))   +
    #   b_QOL_light_workxCERT_moderate      * ( (DrugA_CERT == 3)  * (QOL == 1))   +
    b_QOL_light_workxCERT_high          * ( (DrugA_CERT == 4)  * (QOL == 1))   +
    #   b_QOL_no_workxCERT_very_low         * ( (DrugA_CERT == 1)  * (QOL == 2))   +   
    #   b_QOL_no_workxCERT_low              * ( (DrugA_CERT == 2)  * (QOL == 2))   +
    #   b_QOL_no_workxCERT_moderate         * ( (DrugA_CERT == 3)  * (QOL == 2))   +
    #   b_QOL_no_workxCERT_high             * ( (DrugA_CERT == 4)  * (QOL == 2))   +
    #  b_QOL_bed_50xCERT_very_low          * ( (DrugA_CERT == 1)  * (QOL == 3))   +  
    # b_QOL_bed_50xCERT_low               * ( (DrugA_CERT == 2)  * (QOL == 3))   +
    #   b_QOL_bed_50xCERT_moderate          * ( (DrugA_CERT == 3)  * (QOL == 3))   +
    # b_QOL_bed_50xCERT_high              * ( (DrugA_CERT == 4)  * (QOL == 3))   +
    b_QOL_comp_disabledxCERT_very_low   * ( (DrugA_CERT == 1)  * (QOL == 4))   + 
    #     b_QOL_comp_disabledxCERT_low        * ( (DrugA_CERT == 2)  * (QOL == 4))   +
    #   b_QOL_comp_disabledxCERT_moderate   * ( (DrugA_CERT == 3)  * (QOL == 4))   +
    b_QOL_comp_disabledxCERT_high       * ( (DrugA_CERT == 4)  * (QOL == 4))   +
    b_BENEFIT_smallxCERT_very_low       * ( (DrugA_CERT == 1)  * (BENEFIT == 1)) +
    #  b_BENEFIT_smallxCERT_low            * ( (DrugA_CERT == 2)  * (BENEFIT == 1)) +
    #   b_BENEFIT_smallxCERT_moderate       * ( (DrugA_CERT == 3)  * (BENEFIT == 1)) +
    b_BENEFIT_smallxCERT_high           * ( (DrugA_CERT == 4)  * (BENEFIT == 1)) +
    #   b_BENEFIT_moderatexCERT_very_low    * ( (DrugA_CERT == 1)  * (BENEFIT == 2)) +
    #   b_BENEFIT_moderatexCERT_low         * ( (DrugA_CERT == 2)  * (BENEFIT == 2)) +
    #   b_BENEFIT_moderatexCERT_moderate    * ( (DrugA_CERT == 3)  * (BENEFIT == 2)) +
    #   b_BENEFIT_moderatexCERT_high        * ( (DrugA_CERT == 4)  * (BENEFIT == 2)) +
    b_BENEFIT_substantialxCERT_very_low * ( (DrugA_CERT == 1)  * (BENEFIT == 3)) +
    #  b_BENEFIT_substantialxCERT_low      * ( (DrugA_CERT == 2)  * (BENEFIT == 3)) +
    #  b_BENEFIT_substantialxCERT_moderate * ( (DrugA_CERT == 3)  * (BENEFIT == 3)) +
    b_BENEFIT_substantialxCERT_high     * ( (DrugA_CERT == 4)  * (BENEFIT == 3)) 
  
  
  V[["DrugB"]]  = 
    b_CERT_very_low            *  (DrugB_CERT    == 1)                   + 
    b_CERT_low                 *  (DrugB_CERT    == 2)                   +
    b_CERT_moderate            *  (DrugB_CERT    == 3)                   + 
    b_CERT_high                *  (DrugB_CERT    == 4)                   + 
    b_WAIT                     *   DrugB_WAIT                            +
    
    #Interactions with WAIT:
    b_LIFExWAIT                *   DrugB_WAIT  *   LIFE                   +   
    b_QOL_light_workxWAIT      * ( DrugB_WAIT  *  (QOL     == 1))         +
    #   b_QOL_no_workxWAIT         * ( DrugB_WAIT  *  (QOL     == 2))         +
    #   b_QOL_bed_50xWAIT          * ( DrugB_WAIT  *  (QOL     == 3))         +
    b_QOL_comp_disabledxWAIT   * ( DrugB_WAIT  *  (QOL     == 4))         +
    b_BENEFIT_smallxWAIT       * ( DrugB_WAIT  *  (BENEFIT == 1))         + 
    #  b_BENEFIT_moderatexWAIT    * ( DrugB_WAIT  *  (BENEFIT == 2))         +
    b_BENEFIT_substantialxWAIT * ( DrugB_WAIT  *  (BENEFIT == 3))         +    
    
    #Interactions with CERT (all categorical levels):
    # b_LIFExCERT_very_low              *   (DrugB_CERT == 1)    * LIFE        +
    # b_LIFExCERT_low                   *   (DrugB_CERT == 2)    * LIFE        +
    #  b_LIFExCERT_moderate              *   (DrugB_CERT == 3)    * LIFE        +
    # b_LIFExCERT_high                  *   (DrugB_CERT == 4)    * LIFE        
    b_QOL_light_workxCERT_very_low      * ( (DrugB_CERT == 1)  * (QOL == 1)) +
    #  b_QOL_light_workxCERT_low           * ( (DrugB_CERT == 2)  * (QOL == 1)) +
    #  b_QOL_light_workxCERT_moderate      * ( (DrugB_CERT == 3)  * (QOL == 1)) +
    b_QOL_light_workxCERT_high          * ( (DrugB_CERT == 4)  * (QOL == 1)) +
    #  b_QOL_no_workxCERT_very_low         * ( (DrugB_CERT == 1)  * (QOL == 2)) +   
    #  b_QOL_no_workxCERT_low              * ( (DrugB_CERT == 2)  * (QOL == 2)) +
    #  b_QOL_no_workxCERT_moderate         * ( (DrugB_CERT == 3)  * (QOL == 2)) +
    #  b_QOL_no_workxCERT_high             * ( (DrugB_CERT == 4)  * (QOL == 2)) +
    #  b_QOL_bed_50xCERT_very_low          * ( (DrugB_CERT == 1)  * (QOL == 3)) +  
    #  b_QOL_bed_50xCERT_low               * ( (DrugB_CERT == 2)  * (QOL == 3)) +
    #  b_QOL_bed_50xCERT_moderate          * ( (DrugB_CERT == 3)  * (QOL == 3)) +
    #  b_QOL_bed_50xCERT_high              * ( (DrugB_CERT == 4)  * (QOL == 3)) +
    b_QOL_comp_disabledxCERT_very_low   * ( (DrugB_CERT == 1)  * (QOL == 4)) + 
    #  b_QOL_comp_disabledxCERT_low        * ( (DrugB_CERT == 2)  * (QOL == 4)) +
    # b_QOL_comp_disabledxCERT_moderate   * ( (DrugB_CERT == 3)  * (QOL == 4)) +
    b_QOL_comp_disabledxCERT_high       * ( (DrugB_CERT == 4)  * (QOL == 4)) +
    b_BENEFIT_smallxCERT_very_low       * ( (DrugB_CERT == 1)  * (BENEFIT == 1)) +
    #  b_BENEFIT_smallxCERT_low            * ( (DrugB_CERT == 2)  * (BENEFIT == 1)) +
    # b_BENEFIT_smallxCERT_moderate       * ( (DrugB_CERT == 3)  * (BENEFIT == 1)) +
    b_BENEFIT_smallxCERT_high           * ( (DrugB_CERT == 4)  * (BENEFIT == 1)) +
    #  b_BENEFIT_moderatexCERT_very_low    * ( (DrugB_CERT == 1)  * (BENEFIT == 2)) +
    #  b_BENEFIT_moderatexCERT_low         * ( (DrugB_CERT == 2)  * (BENEFIT == 2)) +
    #  b_BENEFIT_moderatexCERT_moderate    * ( (DrugB_CERT == 3)  * (BENEFIT == 2)) +
    #  b_BENEFIT_moderatexCERT_high        * ( (DrugB_CERT == 4)  * (BENEFIT == 2)) +
    b_BENEFIT_substantialxCERT_very_low * ( (DrugB_CERT == 1)  * (BENEFIT == 3)) +
    # b_BENEFIT_substantialxCERT_low      * ( (DrugB_CERT == 2)  * (BENEFIT == 3)) +
    # b_BENEFIT_substantialxCERT_moderate * ( (DrugB_CERT == 3)  * (BENEFIT == 3)) +
    b_BENEFIT_substantialxCERT_high     * ( (DrugB_CERT == 4)  * (BENEFIT == 3))   
 
   ### Define settings for MNL model component
  mnl_settings = list(
    alternatives  = c(DrugA=1, DrugB=2), 
    choiceVar     = CHOICE,
    utilities     = 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)
}

apollo_probabilities(apollo_beta, apollo_inputs, functionality="estimate")

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

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

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

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

apollo_modelOutput(model)

Output below:

Code: Select all

> # ################################################################# #
> #### MODEL ESTIMATION                                            ####
> # ################################################################# #
> 
> model = apollo_estimate(apollo_beta, apollo_fixed, apollo_probabilities, apollo_inputs)
Preparing user-defined functions.

Testing likelihood function...
Setting "avail" is missing, so full availability is assumed.

Overview of choices for MNL model component :
                                    DrugA    DrugB
Times available                  10440.00 10440.00
Times chosen                      5621.00  4819.00
Percentage chosen overall           53.84    46.16
Percentage chosen when available    53.84    46.16


Pre-processing likelihood function...

Testing influence of parameters
Starting main estimation

BGW using analytic model derivatives supplied by caller...

Error in bgw::bgw_mle(calcR = f, betaStart = beta_var_val, calcJ = grad,  : 
  
Non-valid user-provided bgw_setting setting name detected: "writeIterMode".
dpalma
Posts: 190
Joined: 24 Apr 2020, 17:54

Re: Error: Non-valid user-provided bgw_setting setting name detected: "writeIterMode"."

Post by dpalma »

Hi,

Please try updating the bgw package and running your model again. More specifically:
  • Run the following line of code:

    Code: Select all

    install.packages("bgw")
  • Then run your model again
Please let us know if this fixes the issue or not.

Best wishes
David
Bob123
Posts: 9
Joined: 20 Jun 2023, 13:39

Re: Error: Non-valid user-provided bgw_setting setting name detected: "writeIterMode"."

Post by Bob123 »

Hi David,

Thanks for your quick reply. This seems to have fixed it - the model now runs!

Thanks again,

Rob
alicelm
Posts: 1
Joined: 10 Jun 2023, 12:10

Re: Error: Non-valid user-provided bgw_setting setting name detected: "writeIterMode"."

Post by alicelm »

Hi David,

I'm getting the same error for all of my models:

Code: Select all

BGW using analytic model derivatives supplied by caller...

Error in bgw::bgw_mle(calcR = f, betaStart = beta_var_val, calcJ = grad,  : 
  
Non-valid user-provided bgw_setting setting name detected: "writeIterMode".
They were running before and suddenly this error started appearing, so it doesn't seem to be related to the model structure.

I've tried re-installing the bgw package as you mentioned, but didn't get successful results, the same error keeps showing.

Is there any other thing you suggest I could try?

I'm using R 4.2.2 and Apollo 0.3.0.

Best wishes,

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

Re: Error: Non-valid user-provided bgw_setting setting name detected: "writeIterMode"."

Post by stephanehess »

Alice

can you check what version of the BGW package you have?

Thanks

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