Page 2 of 2

Re: "Paramter does not influence the log-likelihood of your model" after included LV

Posted: 28 Aug 2023, 12:36
by DavideContu
Yes, that does it. Thanks a ton, David!

Re: "Paramter does not influence the log-likelihood of your model" after included LV

Posted: 22 Apr 2024, 13:27
by youssef31
Hello

can you please help me with this?

I am getting a specification issue when I try to run my mnl model

this is my code

### Step 1: Clear memory
> rm(list = ls())
>
> ### Step 2: Set working directory for R initialization
> setwd(dirname(rstudioapi::getActiveDocumentContext()$path))
>
> ### Step 3: Load Apollo library
> library(apollo)
>
> ### Step 4: Initialise Apollo code
> apollo_initialise()

INFORMATION: Your version of Apollo is more than six months old. Using the latest version will ensure you have all current functionality and bug
fixes. You can update to the latest version by typing: install.packages("apollo")

Current process will resume in 5 seconds unless interrupted by the user.....

Apollo ignition sequence completed
>
> ### Step 5: Set core controls
> ### ATTENTION: Your inputs must be enclosed in quotes like "this"
> apollo_control = list(
+ # USER ACTION: Specify model name
+ ## Note: Change the model name for every model that you run
+ modelName = "mentalhealth_MNL_Model",
+ # USER ACTION: Provide model description
+ ## Note: Change the model description to reflect the current model
+ modelDescr = "mentalhealth code for estimating the MNL model",
+ # USER ACTION: Specify the column with the respondent id
+ indivID = "peep_ID",
+ # USER ACTION: Set path to the folder on your PC where the model results will be stored
+ ## Note: Use the "outputs" folder that was created by the pre-processing syntax
+ outputDirectory = paste(getwd(), 'outputs', 'mentalheal_mnl_basic', sep=.Platform$file.sep)
+ )
>
> ### Step 6: Load data
> # Set path to the folder on your PC where the dataset is stored
> path_data = paste(getwd(),'data',"dataset.csv",sep=.Platform$file.sep)
> # Load dataset into global environment
> database = read.csv(path_data, header=TRUE)
>
> ### Step 7: Initialise all parameters that needs to be estimated in your MNL model
> # USER ACTION: The parameters for the attribute "Effectiveness" are defined. Please,
> # complete the list with parameters that need to be estimated. Provide
> # names for each parameter following by assigning a starting value.
> apollo_beta=c( asc_out = 0,
+ b_Waitingtimem = 0,
+ b_Waitingtimeh = 0,
+ b_effm= 0,
+ b_effh = 0,
+ b_peer_support_Yes = 0,
+ b_working_hours_extra = 0,
+ b_Costl = 0,
+ b_Costm = 0,
+ b_Costh = 0)
>
>
> ### Step 8: Define which parameters (as initialised above) should kept fixed during estimation (in quotes); if none, keep empty
> apollo_fixed = c()
>
> ### Step 9: Checkpoint for model inputs
> apollo_inputs = apollo_validateInputs()
Several observations per individual detected based on the value of peep_ID. Setting panelData in apollo_control set to TRUE.
All checks on apollo_control completed.
WARNING: Your database contains some entries that are NA. This may well be intentional, but be advised that if these entries are used in your
model, the behaviour may be unexpected. You can stop the process by pressing the "Escape" key.
All checks on database completed.
>
> ### Step 10: Define model and likelihood function
> apollo_probabilities=function(apollo_beta, apollo_inputs, functionality="estimate"){
+
+ ### Attach dataset inputs and detach after function exit
+ apollo_attach(apollo_beta, apollo_inputs)
+ on.exit(apollo_detach(apollo_beta, apollo_inputs))
+
+ ### Create list of choice probabilities P
+ P = list()
+
+ ### List of utility functions: these must use the same names as in mnl_settings (see below), order is irrelevant
+ V = list()
+ # USER ACTION: Define utility function for alternative 1
+ V[["ALT1"]] = b_Waitingtimem * Waitingtimem1 + b_Waitingtimeh * Waitingtimeh1
+ + b_effm * effm1 + b_effh * effh1 + b_peer_support_Yes * peer_support_Yes1
+ + b_working_hours_extra * working_hours_extra1 + b_Costl * costl1 + b_Costm * costm1
+ + b_Costh * costh1
+
+ # USER ACTION: Define utility function for alternative 2
+ V[["ALT2"]] = b_Waitingtimem * Waitingtimem2 + b_Waitingtimeh * Waitingtimeh2
+ + b_effm * effm2 + b_effh * effh2 + b_peer_support_Yes * peer_support_Yes1
+ + b_working_hours_extra * working_hours_extra2 + b_Costl * costl2 + b_Costm * costm2
+ + b_Costh * costh2
+
+ # Utility function for alternative 3 (i.e., opt-out)
+ V[["ALT3"]] = asc_out
+
+ ### Define settings for MNL model component
+ mnl_settings = list(
+ # USER ACTION: Attach utility functions to the alternatives in your dataset
+ alternatives = c(ALT1=1, ALT2=2, ALT3=3),
+ # USER ACTION: Define which alternatives are "available" in each choice task; in our study, all alternatives are "available"
+ avail = list(ALT1=1, ALT2=1, ALT3=1),
+ # USER ACTION: Specify the column containing the chosen alternative; beware, no dummies are used (!)
+ choiceVar = choice,
+ # USER ACTION: Attach list of utility functions
+ utilities =V
+ )
+
+ ### Compute choice probabilities using MNL model
+ P[["model"]] = apollo_mnl(mnl_settings, functionality) # functionality="estimate" as the parameters will be updated for estimating the MNL model
+
+ ### Take product across observations for same individual (i.e., considering the panel structure of the data)
+ P = apollo_panelProd(P, apollo_inputs, functionality)
+
+ ### Prepare and return outputs of function
+ P = apollo_prepareProb(P, apollo_inputs, functionality)
+ return(P)
+ }
>
> ### Step 11: Model estimation
> model = apollo_estimate(apollo_beta, apollo_fixed, apollo_probabilities, apollo_inputs)
Preparing user-defined functions.

Testing likelihood function...

Overview of choices for MNL model component :
ALT1 ALT2 ALT3
Times available 516.00 516.00 516.00
Times chosen 228.00 218.00 70.00
Percentage chosen overall 44.19 42.25 13.57
Percentage chosen when available 44.19 42.25 13.57


Pre-processing likelihood function...

Testing influence of parametersError in apollo_estimate(apollo_beta, apollo_fixed, apollo_probabilities, :
SPECIFICATION ISSUE - Parameters b_effm, b_effh, b_peer_support_Yes, b_working_hours_extra, b_Costl, b_Costm, b_Costh do not influence the log-likelihood of your model!

Re: "Paramter does not influence the log-likelihood of your model" after included LV

Posted: 22 Apr 2024, 13:31
by stephanehess
Hi

you could have easily resolved this issue by looking at other posts and the manual.

You have:

V[["ALT1"]] = b_Waitingtimem * Waitingtimem1 + b_Waitingtimeh * Waitingtimeh1
+ b_effm * effm1 + b_effh * effh1 + b_peer_support_Yes * peer_support_Yes1
+ b_working_hours_extra * working_hours_extra1 + b_Costl * costl1 + b_Costm * costm1
+ b_Costh * costh1

this means that only the first line is used as R stops reading the input for V at that point. You either need to put a bracket around the entire utility (after =), or put the + at the end of each line instead of the beginning of the next line

Stephane