Error: the variable does not influence the log-likelihood of your model
Posted: 15 May 2021, 12:41
Hello professor,
We have been using your package in our classes (University of Warsaw) for micromodelling. We were modelling society choice (1 - society1, 2-society2, 3- opt-out of the survey). I have run into an issue where the function would not recognize any of my variables inside a utility (Error in apollo_estimate(apollo_beta, apollo_fixed, apollo_probabilities, : Parameter asc_opt1 does not influence the log-likelihood of your model!).
I am including both data and my code.
### Load data
setwd("")
database <- read_xlsx('Data_relative.xlsx')
database <- transmute(database, #modify this if want logs / not logs
ID = ID,
income1 = log(income1),
income2 = log(income2),
choice = choice,
choice1 = choice1,
choice2 = choice2,
choice3 = choice3,
centile1 = log(centile1),
centile2 = log(centile2),
trend1 = trend1,
trend2 = trend2
)
database <- as.data.frame(database) #apollo does not work with tibbles
### Initialize code
apollo_initialise()
### Set core controls
apollo_control = list(
modelName ="Society_base",
modelDescr ="Simple MNL model on society choice data",
indivID ="ID"
)
# ################################################################# #
#### ANALYSIS OF CHOICES ####
# ################################################################# #
database$low_income1=database$income1<quantile(database$income1,0.25)
database$low_income2=database$income2<quantile(database$income2,0.25)
df <- database %>% select(income1:income2) #modify if want different explanators
choiceAnalysis_settings <- list(
alternatives = c(opt1 = 1, opt2 = 2, out = 3),
avail = with(database, list(
opt1 = choice1, opt2 = choice2, out = choice3
)),
choiceVar = database$choice,
explanators = database
)
apollo_choiceAnalysis(choiceAnalysis_settings, apollo_control, database) #this does not work, Error in if (x[1] == x[2]) { : missing value where TRUE/FALSE needed
# ################################################################# #
#### DEFINE MODEL PARAMETERS ####
# ################################################################# #
### Vector of parameters, including any that are kept fixed in estimation
apollo_beta = c(
asc_opt1 = 0,
asc_opt2 = 0,
asc_out =0,
b_income = 0,
b_trend = 0,
b_centile = 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_out')
# ################################################################# #
#### 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[['out']] = asc_out
V[['opt1']] = asc_opt1 + b_income * income1 + b_trend * trend1 + b_centile * centile1
V[['opt2']] = asc_opt2 + b_income * income2 + b_trend * trend2 + b_centile * centile2
### Define settings for MNL model component
mnl_settings = list(
alternatives = c(opt1=1, opt2=2, out=3),
avail = list(opt1=choice1, opt2 = choice2, out=choice3),
choiceVar = choice,
V = 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)
}
model = apollo_estimate(apollo_beta, apollo_fixed, apollo_probabilities, apollo_inputs)
We have been using your package in our classes (University of Warsaw) for micromodelling. We were modelling society choice (1 - society1, 2-society2, 3- opt-out of the survey). I have run into an issue where the function would not recognize any of my variables inside a utility (Error in apollo_estimate(apollo_beta, apollo_fixed, apollo_probabilities, : Parameter asc_opt1 does not influence the log-likelihood of your model!).
I am including both data and my code.
### Load data
setwd("")
database <- read_xlsx('Data_relative.xlsx')
database <- transmute(database, #modify this if want logs / not logs
ID = ID,
income1 = log(income1),
income2 = log(income2),
choice = choice,
choice1 = choice1,
choice2 = choice2,
choice3 = choice3,
centile1 = log(centile1),
centile2 = log(centile2),
trend1 = trend1,
trend2 = trend2
)
database <- as.data.frame(database) #apollo does not work with tibbles
### Initialize code
apollo_initialise()
### Set core controls
apollo_control = list(
modelName ="Society_base",
modelDescr ="Simple MNL model on society choice data",
indivID ="ID"
)
# ################################################################# #
#### ANALYSIS OF CHOICES ####
# ################################################################# #
database$low_income1=database$income1<quantile(database$income1,0.25)
database$low_income2=database$income2<quantile(database$income2,0.25)
df <- database %>% select(income1:income2) #modify if want different explanators
choiceAnalysis_settings <- list(
alternatives = c(opt1 = 1, opt2 = 2, out = 3),
avail = with(database, list(
opt1 = choice1, opt2 = choice2, out = choice3
)),
choiceVar = database$choice,
explanators = database
)
apollo_choiceAnalysis(choiceAnalysis_settings, apollo_control, database) #this does not work, Error in if (x[1] == x[2]) { : missing value where TRUE/FALSE needed
# ################################################################# #
#### DEFINE MODEL PARAMETERS ####
# ################################################################# #
### Vector of parameters, including any that are kept fixed in estimation
apollo_beta = c(
asc_opt1 = 0,
asc_opt2 = 0,
asc_out =0,
b_income = 0,
b_trend = 0,
b_centile = 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_out')
# ################################################################# #
#### 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[['out']] = asc_out
V[['opt1']] = asc_opt1 + b_income * income1 + b_trend * trend1 + b_centile * centile1
V[['opt2']] = asc_opt2 + b_income * income2 + b_trend * trend2 + b_centile * centile2
### Define settings for MNL model component
mnl_settings = list(
alternatives = c(opt1=1, opt2=2, out=3),
avail = list(opt1=choice1, opt2 = choice2, out=choice3),
choiceVar = choice,
V = 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)
}
model = apollo_estimate(apollo_beta, apollo_fixed, apollo_probabilities, apollo_inputs)