Page 1 of 1

error upon running apollo_estimate

Posted: 14 Sep 2020, 19:15
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)

Re: error upon running apollo_estimate

Posted: 15 Sep 2020, 08:49
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