I am estimating a simple MNL with two interaction terms (code below).I have no problems running the code, but when I ask Apollo to save it (apollo_saveOutput(model)), I get the following error:
Error in paste0(rep(" ", max(nchar(m)) - nchar(m)), m, collapse = "") : result would exceed 2^31-1 bytes
I would appreciate your support very much.
Best wishes,
Pamela.
Code: Select all
### Initialise code
apollo_initialise()
### Set core controls
apollo_control = list(
modelName = "MNL_data_Design1_asc_interactionsF",
modelDescr = "MNL model with data from actual study.Data from Design 1 and asc to capture any left-right bias.Interaction Cost & Exp",
indivID = "id", # Name of column in the database with each individual's ID
outputDirectory = "output"
)
setwd("J:/Oxford 2020-2023/Research Pamela/Criteria & DCE/DCE_InegratedCare_Analysis")
##OR: set working directory: Session >> set working directory >>To source file location
# ################################################################# #
#### LOAD DATA AND APPLY ANY TRANSFORMATIONS ####
# ################################################################# #
database <- read.csv('J:/Oxford 2020-2023/Research Pamela/Criteria & DCE/DCE_InegratedCare_Analysis/data_r/DCE_Data_Design1_R.csv')
### Use actual data (i.e. no pilot data).
database = subset(database,database$study_type=="Main")
# ################################################################# #
#### DEFINE MODEL PARAMETERS ####
# ################################################################# #
### Vector of parameters, including any that are kept fixed in estimation
apollo_beta=c(asc = 0,
byol = 0,
bqol = 0,
bexp_fair = 0,
bexp_good = 0,
bsize = 0,
bequ = 0,
bcost = 0,
bexpf_cost = 0,
bexpg_cost = 0
)
apollo_fixed = c()
# ################################################################# #
#### GROUP AND VALIDATE INPUTS ####
# ################################################################# #
apollo_inputs = apollo_validateInputs()
# ################################################################# #
#### DEFINE MODEL AND LIKELIHOOD FUNCTION ####
# ################################################################# #
apollo_probabilities=function(apollo_beta, apollo_inputs, functionality="estimate"){
### Function initialisation: do not change the following three commands
### 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[["Alt1"]] = asc + byol*yol1 + bqol*qol1 + bexp_fair*(exp1==1) + bexp_good*(exp1==2) + bsize*size1 + bequ*equ1 + bcost*cost1 + bexpf_cost*((exp1=1)*cost1) + bexpg_cost*((exp1=2)*cost1)
V[["Alt2"]] = byol*yol2 + bqol*qol2 + bexp_fair*(exp2==1) + bexp_good*(exp2==2) + bsize*size2 + bequ*equ2 + bcost*cost2 + bexpf_cost*((exp2=1)*cost2) + bexpg_cost*((exp2=2)*cost2)
### Define settings for MNL model component
mnl_settings = list(
alternatives = c(Alt1=1, Alt2=2),
avail = list(Alt1=1, Alt2=1),
choiceVar = chosen_option,
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 ESTIMATION ####
# ################################################################# #
model = apollo_estimate(apollo_beta, apollo_fixed, apollo_probabilities, apollo_inputs)
# ################################################################# #
#### MODEL OUTPUTS ####
# ################################################################# #
# ----------------------------------------------------------------- #
#---- FORMATTED OUTPUT (TO SCREEN) ----
# ----------------------------------------------------------------- #
apollo_modelOutput(model, modelOutput_settings=list(printPVal = TRUE, printOutliers= TRUE))