I would like to run a mixed logit model in a remote server, since the dataset is quite large. When I run this model with small test sample in my own PC (like 1% of the total sample), it works well. However, after updating to the latest version, if I run the mixed logit model in a remote server and then save the model as RData file for further analysis, an error will pop up in the 'Apollo_modelOutput' function, it writes:
Code: Select all
Model run by Finley using Apollo 0.2.8 on R 4.2.0 for Windows.
www.ApolloChoiceModelling.com
Model name : Mixed logit model: Preference sapce
Model description : Mixed logit model to determine Adults' preferences for a vaccine product
Model run at : 2022-07-18 20:48:21
Estimation method : bfgs
Model diagnosis : successful convergence
Number of individuals : 12000
Number of rows in database : 144000
Number of modelled outcomes : 144000
Number of cores used : 6
Number of inter-individual draws : 500 (mlhs)
LL(start) : -158200.2
LL at equal shares, LL(0) : -158200.2
LL at observed shares, LL(C) : -129597.2
LL(final) : -101452
Error in round(model$rho2_0, 4) :
non-numeric argument to mathematical function
![Image](https://i.328888.xyz/2022/12/06/V9G3F.png)
It really confuses me since this way worked well before I update the apollo package. I am wondering if there is something wrong with the updating or the remote server.
The original model (run in the remote server) is present below:
Code: Select all
# use apollo package to analyze
# ####################################################### #
#### 1. Definition of core settings
# ####################################################### #
### Clear memory
rm(list = ls())
### Load library
library(apollo)
### Initialise code
apollo_initialise()
### Set core controls
apollo_control <- list(
modelName = "Mixed logit model",
modelDescr = "Mixed logit model to determine Adults' preferences for a vaccine product",
indivID = "ID",
mixing = TRUE, # mixed logit model for random coefficients, FALSE for MNL model
nCores = 6
#,weights = "weight"
)
# ####################################################### #
#### 2. Data loading
# ####################################################### #
database <- read.csv(file = "Data/database.csv")
database <- database[1:1440, ]
database <- subset(database, select = c("ID","price.1","risk2.1","risk3.1","duration2.1",
"duration3.1","efficacy2.1","efficacy3.1",
"admin.1","doses2.1","doses3.1","origin.1",
"price.2","risk2.2","risk3.2",
"duration2.2","duration3.2","efficacy2.2",
"efficacy3.2","admin.2","doses2.2",
"doses3.2","origin.2","choice","weight"))
database <- as.data.frame(database)
# ####################################################### #
#### 3. Parameter definition
# ####################################################### #
### Vector of parameters, including any that are kept fixed
### during estimation
apollo_beta <- c(
asc = 0,
b_price_mu = 0,
b_risk2_mu = 0,
b_risk3_mu = 0,
b_duration2_mu = 0,
b_duration3_mu = 0,
b_efficacy2_mu = 0,
b_efficacy3_mu = 0,
b_oral_mu = 0,
b_dose2_mu = 0,
b_dose3_mu = 0,
b_imported_mu = 0,
b_price_sigma = 0,
b_risk2_sigma = 0,
b_risk3_sigma = 0,
b_duration2_sigma = 0,
b_duration3_sigma = 0,
b_efficacy2_sigma = 0,
b_efficacy3_sigma = 0,
b_oral_sigma = 0,
b_dose2_sigma = 0,
b_dose3_sigma = 0,
b_imported_sigma = 0
)
### Vector with names (in quotes) of parameters to be kept fixed at their starting value in apollo_beta, use apollo_beta_fixed = c() if none
apollo_fixed <- c()
# ################################################################# #
#### 4. Define Random Components
# ################################################################# #
### Set parameters for generating draws
apollo_draws <- list(
interDrawsType = "mlhs",
interNDraws = 500,
interUnifDraws = c(),
interNormDraws = paste0("draws_", c(
"price", "risk2",
"risk3", "duration2",
"duration3", "efficacy2",
"efficacy3", "oral",
"dose2", "dose3",
"imported"
)),
intraDrawsType = "",
intraNDraws = 0,
intraUnifDraws = c(),
intraNormDraws = c()
)
### Create random parameters
apollo_randCoeff <- function(apollo_beta, apollo_inputs) {
randcoeff <- list()
randcoeff[["b_price"]] <- b_price_mu + b_price_sigma * draws_price
randcoeff[["b_risk2"]] <- b_risk2_mu + b_risk2_sigma * draws_risk2
randcoeff[["b_risk3"]] <- b_risk3_mu + b_risk3_sigma * draws_risk3
randcoeff[["b_duration2"]] <- b_duration2_mu + b_duration2_sigma * draws_duration2
randcoeff[["b_duration3"]] <- b_duration3_mu + b_duration3_sigma * draws_duration3
randcoeff[["b_efficacy2"]] <- b_efficacy2_mu + b_efficacy2_sigma * draws_efficacy2
randcoeff[["b_efficacy3"]] <- b_efficacy3_mu + b_efficacy3_sigma * draws_efficacy3
randcoeff[["b_oral"]] <- b_oral_mu + b_oral_sigma * draws_oral
randcoeff[["b_dose2"]] <- b_dose2_mu + b_dose2_sigma * draws_dose2
randcoeff[["b_dose3"]] <- b_dose3_mu + b_dose3_sigma * draws_dose3
randcoeff[["b_imported"]] <- b_imported_mu + b_imported_sigma * draws_imported
return(randcoeff)
}
# ####################################################### #
#### 5. Input validation
# ####################################################### #
apollo_inputs <- apollo_validateInputs()
# ####################################################### #
#### 6. Likelihood definition
# ####################################################### #
apollo_probabilities <- function(apollo_beta, apollo_inputs, functionality = "estimate") {
### 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()
V <- list()
### List of utilities: these must use the same names as
### in mnl_settings, order is irrelevant.
V[["alt1"]] <- asc + b_price * price.1 + b_risk2 * risk2.1 + b_risk3 * risk3.1 +
b_duration2 * duration2.1 + b_duration3 * duration3.1 + b_efficacy2 * efficacy2.1 +
b_efficacy3 * efficacy3.1 + b_oral * admin.1 + b_dose2 * doses2.1 +
b_dose3 * doses3.1 + b_imported * origin.1
V[["alt2"]] <- asc + b_price * price.2 + b_risk2 * risk2.2 + b_risk3 * risk3.2 +
b_duration2 * duration2.2 + b_duration3 * duration3.2 + b_efficacy2 * efficacy2.2 +
b_efficacy3 * efficacy3.2 + b_oral * admin.2 + b_dose2 * doses2.2 +
b_dose3 * doses3.2 + b_imported * origin.2
V[["alt3"]] <- 0
### 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,
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)
### Average across inter-individual draws
P = apollo_avgInterDraws(P, apollo_inputs, functionality)
### Prepare and return outputs of function
P = apollo_prepareProb(P, apollo_inputs, functionality)
### Using sampling weights in estimation and prediction
# P = apollo_weighting(P, apollo_inputs, functionality)
return(P)
}
# ####################################################### #
#### 7. Model estimation
# ####################################################### #
fit <- apollo_estimate(
apollo_beta, apollo_fixed,
apollo_probabilities, apollo_inputs
)
save(fit, file = paste0(getwd(), "/Model/ML_preference_space_test.RData"))
Code: Select all
> sessionInfo()
R version 4.2.0 (2022-04-22 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19045)
Matrix products: default
locale:
[1] LC_COLLATE=Chinese (Simplified)_China.utf8 LC_CTYPE=Chinese (Simplified)_China.utf8
[3] LC_MONETARY=Chinese (Simplified)_China.utf8 LC_NUMERIC=C
[5] LC_TIME=Chinese (Simplified)_China.utf8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] xfun_0.30 apollo_0.2.8 zoo_1.8-10 tidyselect_1.2.0
[5] lattice_0.20-45 generics_0.1.2 vctrs_0.4.1 htmltools_0.5.2
[9] yaml_2.3.5 MCMCpack_1.6-3 utf8_1.2.2 rlang_1.0.6
[13] pillar_1.7.0 glue_1.6.2 DBI_1.1.2 matrixStats_0.62.0
[17] lifecycle_1.0.3 stringr_1.4.0 MatrixModels_0.5-0 mvtnorm_1.1-3
[21] coda_0.19-4 evaluate_0.15 knitr_1.38 miscTools_0.6-26
[25] fastmap_1.1.0 SparseM_1.81 RSGHB_1.2.2 quantreg_5.88
[29] parallel_4.2.0 fansi_1.0.3 Rcpp_1.0.8.3 tmvnsim_1.0-2
[33] mcmc_0.9-7 maxLik_1.5-2 mnormt_2.0.2 digest_0.6.29
[37] stringi_1.7.6 dplyr_1.0.8 numDeriv_2016.8-1.1 grid_4.2.0
[41] cli_3.3.0 tools_4.2.0 sandwich_3.0-1 magrittr_2.0.3
[45] tibble_3.1.6 pacman_0.5.1 crayon_1.5.1 pkgconfig_2.0.3
[49] MASS_7.3-56 ellipsis_0.3.2 Matrix_1.4-1 randtoolbox_1.31.1
[53] assertthat_0.2.1 rmarkdown_2.13 rstudioapi_0.13 R6_2.5.1
[57] rngWELL_0.10-7 compiler_4.2.0