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))