diff --git a/DESCRIPTION b/DESCRIPTION index 6dc188af169c8da311e7c69d72a2ed72c6ee72a5..260f9bd8ac5636c1efd615a0a68f76af05fca3db 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -8,7 +8,7 @@ Description: A package that supports simulating choice experiment data for given License: MIT + file LICENSE Encoding: UTF-8 Roxygen: list(markdown = TRUE) -RoxygenNote: 7.2.2 +RoxygenNote: 7.3.0 Imports: dplyr (>= 1.1.4), evd, diff --git a/R/sim_all.R b/R/sim_all.R index 469c9b27eab74db5452b770cf5a218f2864ba8d9..ebb7d06d80faeb51d86ef5e41c2046b0096abd0a 100644 --- a/R/sim_all.R +++ b/R/sim_all.R @@ -41,7 +41,7 @@ sim_all <- function(nosim=2, resps, destype="ngene", designpath, u){ tictoc::tic() all_designs<- purrr::map(designfile, sim_choice, - no_sim= nosim,respondents = resps, destype=destype, utils=u) %>% ## iterate simulation over all designs + no_sim= nosim,respondents = resps, destype=destype, ut=u) %>% ## iterate simulation over all designs stats::setNames(designname) diff --git a/R/sim_choice.R b/R/sim_choice.R index 63ee8072926af38973d7ec0d276f8ae59097c7a0..fed4fec773f91886f833acaf261518a56c70fe2d 100644 --- a/R/sim_choice.R +++ b/R/sim_choice.R @@ -11,22 +11,23 @@ #' @param designfile path to a file containing a design. #' @param no_sim Number of runs i.e. how often do you want the simulation to be repeated #' @param respondents Number of respondents. How many respondents do you want to simulate in each run. -#' @param utils The first element of the utility function list +#' @param ut The first element of the utility function list #' @param destype Specify which type of design you use. Either ngene or spdesign #' #' @return a list with all information on the run #' @export #' #' @examples \dontrun{ simchoice(designfile="somefile", no_sim=10, respondents=330, -#' mnl_U,utils=u[[1]] ,destype="ngene")} +#' mnl_U,ut=u[[1]] ,destype="ngene")} #' -sim_choice <- function(designfile, no_sim=10, respondents=330,utils ,destype=destype) { +sim_choice <- function(designfile, no_sim=10, respondents=330,ut ,destype=destype) { #### Function that transforms user written utility for simulation into utility function for mixl. transform_util <- function() { - mnl_U <-paste(purrr::map_chr(utils[[1]],as.character,keep.source.attr = TRUE),collapse = "",";") %>% + + mnl_U <-paste(purrr::map_chr(ut[[1]],as.character,keep.source.attr = TRUE),collapse = "",";") %>% stringr::str_replace_all( c( "priors\\[\"" = "" , "\"\\]" = "" , "~" = "=", "\\." = "_" , " b" = " @b" , "V_"="U_", " alt"="$alt")) } @@ -37,7 +38,7 @@ sim_choice <- function(designfile, no_sim=10, respondents=330,utils ,destype=des cat("This is Run number ", run) - database <- simulate_choices(datadet, utility = utils, setspp=setpp ) + database <- simulate_choices(datadet, utility = ut, setspp=setpp ) cat("This is the utility functions \n" , mnl_U) @@ -59,7 +60,7 @@ designs_all <- list() cat("Utility function used in simulation, ie the true utility: \n\n") - print(utils) + print(ut) cat("Utility function used for Logit estimation with mixl: \n\n") @@ -91,7 +92,7 @@ designs_all <- list() dplyr::relocate(ID,`Choice.situation`) %>% as.data.frame() - database <- simulate_choices(data=datadet, utility = utils, setspp = setpp) + database <- simulate_choices(data=datadet, utility = ut, setspp = setpp) # specify model for mixl estimation diff --git a/R/simulate_choices.R b/R/simulate_choices.R index b1fbfad0c36a3d8b53e5c8f613367805614cd56d..5a0d322145f85f82b00841e3c7aaf8f0be7f25c6 100644 --- a/R/simulate_choices.R +++ b/R/simulate_choices.R @@ -7,7 +7,7 @@ #' @return a dataframe that includes simulated choices and a design #' @export #' -#' @examples \dontrun{simulate_choices(datadet, utils,setspp)} +#' @examples \dontrun{simulate_choices(datadet, ut,setspp)} simulate_choices <- function(data, utility, setspp, destype) { #the part in dataset that needs to be repeated in each run diff --git a/man/sim_choice.Rd b/man/sim_choice.Rd index 42e6f038eb61c6f09f54921facc46da4b91c3d7c..8f40c9644dbb09820fdbd4a9bd7ec525d612dc08 100644 --- a/man/sim_choice.Rd +++ b/man/sim_choice.Rd @@ -4,13 +4,7 @@ \alias{sim_choice} \title{Title} \usage{ -sim_choice( - designfile, - no_sim = 10, - respondents = 330, - utils, - destype = destype -) +sim_choice(designfile, no_sim = 10, respondents = 330, ut, destype = destype) } \arguments{ \item{designfile}{path to a file containing a design.} @@ -19,7 +13,7 @@ sim_choice( \item{respondents}{Number of respondents. How many respondents do you want to simulate in each run.} -\item{utils}{The first element of the utility function list} +\item{ut}{The first element of the utility function list} \item{destype}{Specify which type of design you use. Either ngene or spdesign} } @@ -31,6 +25,6 @@ Title } \examples{ \dontrun{ simchoice(designfile="somefile", no_sim=10, respondents=330, - mnl_U,utils=u[[1]] ,destype="ngene")} + mnl_U,ut=u[[1]] ,destype="ngene")} } diff --git a/man/simulate_choices.Rd b/man/simulate_choices.Rd index b9cb87d2184e3be878e8eaa36ce1c4541d7e7a98..3a3f85f27f0504e0742ee6c439ceb1d6f6071fc5 100644 --- a/man/simulate_choices.Rd +++ b/man/simulate_choices.Rd @@ -22,5 +22,5 @@ a dataframe that includes simulated choices and a design Simulate choices based on a dataframe with a design } \examples{ -\dontrun{simulate_choices(datadet, utils,setspp)} +\dontrun{simulate_choices(datadet, ut,setspp)} } diff --git a/tests/manual-tests/Rbookfull.R b/tests/manual-tests/Rbookfull.R index 34bd8ace893bb8e88cfce873ab83cf5452f5fd9a..4596edf730d4f9c1a205d95c28e012ecb89e9e0d 100644 --- a/tests/manual-tests/Rbookfull.R +++ b/tests/manual-tests/Rbookfull.R @@ -6,7 +6,6 @@ devtools::load_all() set.seed(3393) designpath<- system.file("extdata","Rbook" ,package = "simulateDCE") - #notes <- "This design consists of different heuristics. One group did not attend the methan attribute, another group only decided based on the payment" notes <- "No Heuristics" @@ -38,7 +37,7 @@ ul<- list(u1= list( -rbook <- sim_all(nosim = nosim, resps=resps, destype = destype, +rbook <- simulateDCE::sim_all(nosim = nosim, resps=resps, destype = destype, designpath = designpath, u= ul)