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.

error upon running apollo_estimate

Ask questions about errors you encouunter. Please make sure to include full details about your model specifications, and ideally your model file.
Post Reply
Salma
Posts: 1
Joined: 14 Sep 2020, 15:27

error upon running apollo_estimate

Post by Salma »

Hello,

#My estimate doesn't work when i run the following command:

model = apollo_estimate(apollo_beta, apollo_fixed, apollo_probabilities, apollo_inputs)

#It gives me the following error:

Error in rowsum.default(log(P), group = indivID) :
incorrect length for 'group'

#Thank you for your help in advance.

#For reference, here is my entire code:
library (apollo)
apollo_initialise()

library (haven)

##Reading excel sheet
database <- read_excel("database.xls")

# ################################################################# #


apollo_control = list (
modelName ="DK_ce",
modelDescr = "The updated data specific to Denmark",
indivID = "id"
)


###Defining the model parameters
apollo_beta= c(asc_status_quo=0,
asc_program_A=0,
asc_program_B=0,
b_cost_a=0,
b_quality_a=0,
b_plastic_a=0,
b_location_a=0,
b_measure_a=0,
b_certainty_a=0,
b_cost_b=0,
b_quality_b=0,
b_plastic_b=0,
b_location_b=0,
b_measure_b=0,
b_certainty_b=0,
b_cost_c=0,
b_quality_c=0,
b_plastic_c=0,
b_location_c=0,
b_measure_c=0,
b_certainty_c=0
)

apollo_fixed= c("asc_status_quo")
#Group and validate inputs
apollo_inputs = apollo_validateInputs()

###Define model and liklihood function

apollo_probabilities=function(apollo_beta, apollo_inputs, functionality="estimate"){

# Attach inputs and detach after function exit (allows to call variables without referring to dataset)
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[['status_quo']] = asc_status_quo + b_cost_c * cost_c + b_quality_c * quality_c + b_plastic_c * plastic_c + b_location_c * location_c + b_measure_c * measure_c + b_certainty_c * certainty_c
V[['program_A']] = asc_program_A + b_cost_a * cost_a + b_quality_a *quality_a + b_plastic_a * plastic_a + b_location_a * location_a + b_measure_a * measure_a + b_certainty_a * certainty_a
V[['program_B']] = asc_program_B + b_cost_b * cost_b + b_quality_b *quality_b + b_plastic_b * plastic_b + b_location_b * location_b + b_measure_b * measure_b + b_certainty_b * certainty_b

# Define settings for MNL model component
mnl_settings = list (
alternatives = c(status_quo = 0, program_A = 1, program_B = 2),
avail = 1 ,
choiceVar = choice ,
V = V
)
##Estimating the multinomial logit

# 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 ESTIMATION

model = apollo_estimate(apollo_beta, apollo_fixed, apollo_probabilities, apollo_inputs)
stephanehess
Site Admin
Posts: 1042
Joined: 24 Apr 2020, 16:29

Re: error upon running apollo_estimate

Post by stephanehess »

Hi

this error seems to happen in your case as the data is an Excel file. If you save the Excel file as csv and read that in, it works fine. I would always recommend working with csv instead of Excel for your data files

Stephane
--------------------------------
Stephane Hess
www.stephanehess.me.uk
Post Reply