Hi Stephane and David,
Hope you are doing great!
I am trying to use the Apollo package (0.2.9) to run the MNL_RP model.
Here is the error message I got from R (version 4.2.0; RStudio2022.02.1):
"Error in apollo_estimateHB(apollo_beta, apollo_fixed, apollo_probabilities, :
SPECIFICATION ISSUE - Parameter b_disc.d2 does not influence the log-likelihood of your model!"
Below is the code I used to run the analysis.
# Import
dce = read.csv(file=paste0(PATHDAT,'dce_wide.csv'), header = T, stringsAsFactors = F)
load(paste0(PATHOBJ,'List of model specifications.RData')) # l.spe
load(paste0(PATHOBJ,'List of attributes.RData')) # l.att
# Manage --------------------------------------------------
###
MODL = 'RPL_effect'
OBJT = 'RPL_effect - Model estimates_child'
SAMP = 'Overall'
### META Variables
N = 'record'
Ta = 'SP_task'
Y = "choice"
nJ = 2
###
nfac = 1000
nBURN = 300*nfac
nCONV = 30*nfac
nSKIP = 10
SEED = 12345
# Specification -----------------------------------------------------------
lD = as.list(NULL)
for (i in 1) {
###
D = dce
###
lA = l.att
S0 = l.spe[['eff0']]
S1 = l.spe[['eff1']]
### Model specification
lX = paste0("b_",S1)
lparam = rep(0,length(lX))
names(lparam) = lX
###
hbd = NULL
hbd = rep('N',length(lX))
names(hbd) = lX
###
l.uti = as.list(NULL)
l.uti = lapply(1:nJ, function(x){
a = paste0(lX,"*alt",x,'_',sub('b\\_','',lX),collapse=" +")
return(a)})
###
nN = length(unique(D[,N]))
nY = nrow(D)
nP = 2*length(hbd)
LL0 = nY*log(1/nJ)
nD = nrow(D)
###
mID = D[!duplicated(D[,'ID']),c('ID',N)]
###
lk = as.list(NULL)
lk[['lA']] = lA
lk[['S0']] = S0
lk[['S1']] = S1
lk[['D']] = D
lk[['nN']] = nN
lk[['nY']] = nY
lk[['nP']] = nP
lk[['LL0']] = LL0
lk[['hbd']] = hbd
lk[['lparam']] = lparam
lk[['l.uti']] = l.uti
lk[['mID']] = mID
lk[['nD']] = nD
lD[] = lk}
# Estimation ------------------------------------------------------------------------
###
l.res = as.list(NULL)
IDXTOT = length(lD)
for (i in IDXTOT){
###
lparam = lD[][['lparam']]
l.uti = lD[][['l.uti']]
hbd = lD[][['hbd']]
database = lD[][['D']]
nD = lD[][['nD']]
nY = lD[][['nY']]
nN = lD[][['nN']]
nP = lD[][['nP']]
LL0 = lD[][['LL0']]
mID = lD[[i]][['mID']]
S0 = lD[[i]][['S0']]
S1 = lD[[i]][['S1']]
lA = lD[[i]][['lA']]
### Initialise code
apollo_initialise()
### Set core controls
apollo_control = list(
modelName =MODL,
modelDescr =MODL,
indivID ='ID',
HB =T)
### Declare parameters
apollo_beta = lparam
apollo_fixed = c()
###
apollo_HB = list(
hbDist =hbd,
gINFOSKIP =nSKIP,
gNCREP =nBURN,
gNEREP =nCONV,
gSeed =SEED,
verbose =F,
nodiagnostics=T,
gFULLCV =F)
### VALIDATE INPUTS
apollo_inputs = apollo_validateInputs()
### DEFINE MODEL
apollo_probabilities = function(apollo_beta, apollo_inputs, functionality="estimate"){
###
apollo_attach(apollo_beta, apollo_inputs)
on.exit(apollo_detach(apollo_beta, apollo_inputs))
### Create list of probabilities P
P = list()
### Likelihood of choices
V = list()
V[['alt1']] = (b_adpro.d2 * alt1_adpro.d2 +
b_inj.d2 * alt1_inj.d2 + b_inj.d3 * alt1_inj.d3 +
b_disc.d2 * alt1_disc.d2 + b_disc.d3 * alt1_disc.d3 +
b_dos.d2 * alt1_dos.d2 + b_dos.d3 * alt1_dos.d3 +
b_visits.d2 * alt1_visits.d2 + b_visits.d3 * alt1_visits.d3)
V[['alt2']] = (b_adpro.d2 * alt2_adpro.d2 +
b_inj.d2 * alt2_inj.d2 + b_inj.d3 * alt2_inj.d3 +
b_disc.d2 * alt2_disc.d2 + b_disc.d3 * alt2_disc.d3 +
b_dos.d2 * alt2_dos.d2 + b_dos.d3 * alt2_dos.d3 +
b_visits.d2 * alt2_visits.d2 + b_visits.d3 * alt2_visits.d3)
### Define MNL settings
mnl_settings = list(
alternatives=c(alt1=1, alt2=2),
avail = list(alt1=1, alt2=1),
choiceVar = choice,
V = V)
### Compute probabilities using MNL model
P[['model']] = apollo_mnl(mnl_settings, functionality)
### Prepare and return outputs of function
P = apollo_prepareProb(P, apollo_inputs, functionality)
return(P)}
### Estimate model
fit = NULL
fit = apollo_estimate(apollo_beta, apollo_fixed, apollo_probabilities, apollo_inputs)
.......
Do you have any suggestions to solve this error? Thank you very much in advance for your help
Best regards,
Dian
Important: Read this before posting to this forum
- 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.
- 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
- Before asking a question on the forum, users are kindly requested to follow these steps:
- Check that the same issue has not already been addressed in the forum - there is a search tool.
- 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
- Check the frequently asked questions section on the Apollo website, which discusses some common issues/failures. Please see http://www.apollochoicemodelling.com/faq.html
- Make sure that R is using the latest official release of Apollo.
- Users can check which version they are running by entering packageVersion("apollo").
- Then check what is the latest full release (not development version) at http://www.ApolloChoiceModelling.com/code.html.
- To update to the latest official version, just enter install.packages("apollo"). To update to a development version, download the appropriate binary file from http://www.ApolloChoiceModelling.com/code.html, and install the package from file
- If the above steps do not resolve the issue, then users should follow these steps when posting a question:
- provide full details on the issue, including the entire code and output, including any error messages
- 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.
Parameter does not influence the log-likelihood of your model!
-
- Site Admin
- Posts: 1050
- Joined: 24 Apr 2020, 16:29
Re: Parameter does not influence the log-likelihood of your model!
Hi
this would happen if there are no differences between the alternatives in the associated attribute, i.e. alt1_disc.d2 and alt2_disc.d2
Can you confirm that in your data, these do differ?
Stephane
this would happen if there are no differences between the alternatives in the associated attribute, i.e. alt1_disc.d2 and alt2_disc.d2
Can you confirm that in your data, these do differ?
Stephane