Important: Read this before posting to this forum

  1. 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.
  2. 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
  3. Before asking a question on the forum, users are kindly requested to follow these steps:
    1. Check that the same issue has not already been addressed in the forum - there is a search tool.
    2. 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
    3. Check the frequently asked questions section on the Apollo website, which discusses some common issues/failures. Please see http://www.apollochoicemodelling.com/faq.html
    4. Make sure that R is using the latest official release of Apollo.
  4. If the above steps do not resolve the issue, then users should follow these steps when posting a question:
    1. provide full details on the issue, including the entire code and output, including any error messages
    2. 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.

Constraints do not work

Ask questions about how to estimate models and how to change your settings for estimation.
Post Reply
intllawKuma
Posts: 6
Joined: 29 Apr 2022, 08:06

Constraints do not work

Post by intllawKuma »

Hi,

I ran the following code using my own survey data.
I got the negative alpha -0.355207 even though I set the constraints c("alpha >= 0","alpha < 1").
It would be appreciated if you could tell me how to limit the sign of alpha to positive.

Code: Select all


library(apollo)
apollo_initialise()
apollo_control <- list(
  modelName       = "MNL",
  modelDescr      = "MNL model",
  indivID         = "ID",
  outputDirectory = "output"
)
database <- read.csv("dataNest/dataset1r1.csv")

apollo_beta <- c(asc = 0,
                 b_1 = 0,
                 b_2 = 0,
                 alpha = 0)
apollo_fixed <- c()

apollo_inputs <- apollo_validateInputs()
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()
  
  # List of utilities
  V <- list()
  V[["alt1"]] = b_1 * (Chaku.1)^(1-alpha)/(1-alpha) + b_2 * (500-Seiko.1)^(1-alpha)/(1-alpha) * Prob.1/100
  V[["alt2"]] = b_1 * (Chaku.2)^(1-alpha)/(1-alpha) + b_2 * (500-Seiko.2)^(1-alpha)/(1-alpha) * Prob.2/100
  V[["alt3"]] = asc + b_1 * (Chaku.3)^(1-alpha)/(1-alpha) + b_2 * (500-Seiko.3)^(1-alpha)/(1-alpha) * Prob.3/100
  
  # Define settings for MNL model component
  mnl_settings <- list(
     alternatives = c(alt1 = 1, alt2 = 2, alt3 = 3),
     avail        = list(alt1 = 1, alt2 = 1, alt3 = 1),
     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)
}

model_non <- apollo_estimate(apollo_beta,apollo_fixed,apollo_probabilities,apollo_inputs,estimate_settings=list(contraints=c("alpha > 0","alpha < 1")))
apollo_modelOutput(model_non, list(printPVal=2))

dpalma
Posts: 190
Joined: 24 Apr 2020, 17:54

Re: Constraints do not work

Post by dpalma »

Hi,

There seems to be typo in your code, an "s" missing in constraints. The call to apollo_estimate should look as follows:

Code: Select all

model_non <- apollo_estimate(apollo_beta,apollo_fixed,apollo_probabilities, apollo_inputs,
                             estimate_settings=list(constraints=c("alpha > 0","alpha < 1")))
Please try again with that call, and don't forget to update Apollo to the latest available version. You can do this simply by typing install.packages("apollo") in the console.

Cheers
David
intllawKuma
Posts: 6
Joined: 29 Apr 2022, 08:06

Re: Constraints do not work

Post by intllawKuma »

Dear Dr. Palma,

I did not notice the spelling mistake.
It worked well after I corrected the spelling mistake.
Thank you.
Post Reply