Skip to content
Snippets Groups Projects
Commit 53268a0c authored by Julian Rainer's avatar Julian Rainer
Browse files

change in name to argument to make function run again

parent 11d76832
Branches
No related tags found
No related merge requests found
...@@ -8,7 +8,7 @@ Description: A package that supports simulating choice experiment data for given ...@@ -8,7 +8,7 @@ Description: A package that supports simulating choice experiment data for given
License: MIT + file LICENSE License: MIT + file LICENSE
Encoding: UTF-8 Encoding: UTF-8
Roxygen: list(markdown = TRUE) Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.2 RoxygenNote: 7.3.0
Imports: Imports:
dplyr (>= 1.1.4), dplyr (>= 1.1.4),
evd, evd,
......
...@@ -41,7 +41,7 @@ sim_all <- function(nosim=2, resps, destype="ngene", designpath, u){ ...@@ -41,7 +41,7 @@ sim_all <- function(nosim=2, resps, destype="ngene", designpath, u){
tictoc::tic() tictoc::tic()
all_designs<- purrr::map(designfile, sim_choice, 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) stats::setNames(designname)
......
...@@ -11,22 +11,23 @@ ...@@ -11,22 +11,23 @@
#' @param designfile path to a file containing a design. #' @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 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 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 #' @param destype Specify which type of design you use. Either ngene or spdesign
#' #'
#' @return a list with all information on the run #' @return a list with all information on the run
#' @export #' @export
#' #'
#' @examples \dontrun{ simchoice(designfile="somefile", no_sim=10, respondents=330, #' @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. #### Function that transforms user written utility for simulation into utility function for mixl.
transform_util <- function() { 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")) 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 ...@@ -37,7 +38,7 @@ sim_choice <- function(designfile, no_sim=10, respondents=330,utils ,destype=des
cat("This is Run number ", run) 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) cat("This is the utility functions \n" , mnl_U)
...@@ -59,7 +60,7 @@ designs_all <- list() ...@@ -59,7 +60,7 @@ designs_all <- list()
cat("Utility function used in simulation, ie the true utility: \n\n") 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") cat("Utility function used for Logit estimation with mixl: \n\n")
...@@ -91,7 +92,7 @@ designs_all <- list() ...@@ -91,7 +92,7 @@ designs_all <- list()
dplyr::relocate(ID,`Choice.situation`) %>% dplyr::relocate(ID,`Choice.situation`) %>%
as.data.frame() 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 # specify model for mixl estimation
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#' @return a dataframe that includes simulated choices and a design #' @return a dataframe that includes simulated choices and a design
#' @export #' @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 simulate_choices <- function(data, utility, setspp, destype) { #the part in dataset that needs to be repeated in each run
......
...@@ -4,13 +4,7 @@ ...@@ -4,13 +4,7 @@
\alias{sim_choice} \alias{sim_choice}
\title{Title} \title{Title}
\usage{ \usage{
sim_choice( sim_choice(designfile, no_sim = 10, respondents = 330, ut, destype = destype)
designfile,
no_sim = 10,
respondents = 330,
utils,
destype = destype
)
} }
\arguments{ \arguments{
\item{designfile}{path to a file containing a design.} \item{designfile}{path to a file containing a design.}
...@@ -19,7 +13,7 @@ sim_choice( ...@@ -19,7 +13,7 @@ sim_choice(
\item{respondents}{Number of respondents. How many respondents do you want to simulate in each run.} \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} \item{destype}{Specify which type of design you use. Either ngene or spdesign}
} }
...@@ -31,6 +25,6 @@ Title ...@@ -31,6 +25,6 @@ Title
} }
\examples{ \examples{
\dontrun{ simchoice(designfile="somefile", no_sim=10, respondents=330, \dontrun{ simchoice(designfile="somefile", no_sim=10, respondents=330,
mnl_U,utils=u[[1]] ,destype="ngene")} mnl_U,ut=u[[1]] ,destype="ngene")}
} }
...@@ -22,5 +22,5 @@ a dataframe that includes simulated choices and a design ...@@ -22,5 +22,5 @@ a dataframe that includes simulated choices and a design
Simulate choices based on a dataframe with a design Simulate choices based on a dataframe with a design
} }
\examples{ \examples{
\dontrun{simulate_choices(datadet, utils,setspp)} \dontrun{simulate_choices(datadet, ut,setspp)}
} }
...@@ -6,7 +6,6 @@ devtools::load_all() ...@@ -6,7 +6,6 @@ devtools::load_all()
set.seed(3393) set.seed(3393)
designpath<- system.file("extdata","Rbook" ,package = "simulateDCE") 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 <- "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" notes <- "No Heuristics"
...@@ -38,7 +37,7 @@ ul<- list(u1= list( ...@@ -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) designpath = designpath, u= ul)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment