Page 1 of 1

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

Posted: 14 Aug 2023, 10:58
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".

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

Posted: 14 Aug 2023, 16:47
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

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

Posted: 14 Aug 2023, 17:09
by Bob123
Hi David,

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

Thanks again,

Rob

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

Posted: 17 Aug 2023, 18:00
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

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

Posted: 17 Aug 2023, 19:17
by stephanehess
Alice

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

Thanks

Stephane