Page 1 of 1

Parameter does not influence the log-likelihood of your model!

Posted: 05 Jul 2023, 04:49
by Dian3426
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

Re: Parameter does not influence the log-likelihood of your model!

Posted: 05 Jul 2023, 14:05
by stephanehess
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