From c024a3e7f3b5e2f352691868c339b93e155dbff2 Mon Sep 17 00:00:00 2001 From: dj44vuri <julian.sagebiel@idiv.de> Date: Tue, 13 Feb 2024 13:04:18 +0100 Subject: [PATCH] new example csa and small fix in block, solved merge errors --- R/readdesign.R | 5 ++++- R/simulate_choices.R | 17 ++++------------ tests/manual-tests/csa.R | 43 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 14 deletions(-) create mode 100644 tests/manual-tests/csa.R diff --git a/R/readdesign.R b/R/readdesign.R index 8890948..781b964 100644 --- a/R/readdesign.R +++ b/R/readdesign.R @@ -33,7 +33,10 @@ readdesign <- function(design = designfile, designtype = destype) { "spdesign" = as.data.frame(readRDS(design)) %>% dplyr::mutate(Choice.situation = 1:dplyr::n()) %>% dplyr::rename_with(~ stringr::str_replace(., pattern = "_", "\\."), tidyr::everything()) %>% - dplyr::rename(Block=block), + dplyr::rename_with(~ dplyr::case_when( + . == "block" ~ "Block", + TRUE ~ . + ), tidyr::everything()), stop("Invalid value for design. Please provide either 'ngene' or 'spdesign'.") ) } diff --git a/R/simulate_choices.R b/R/simulate_choices.R index 4066d35..5cb9a34 100644 --- a/R/simulate_choices.R +++ b/R/simulate_choices.R @@ -9,23 +9,14 @@ #' #' @examples \dontrun{simulate_choices(datadet, ut,setspp)} simulate_choices <- function(data, utility, setspp, destype, bcoefficients) { #the part in dataset that needs to be repeated in each run -<<<<<<< HEAD - -### unpack the bcoeff list - bsq <- bcoefficients$bsq - bredkite <- bcoefficients$bredkite - bdistance <- bcoefficients$bdistance - bcost <- bcoefficients$bcost - bfarm2 <- bcoefficients$bfarm2 - bfarm3 <- bcoefficients$bfarm3 - bheight2 <- bcoefficients$bheight2 - bheight3 <- bcoefficients$bheight3 -======= + + + ### unpack the bcoeff list so variables are accessible for (key in names(bcoefficients)) { assign(key, bcoefficients[[key]]) } ->>>>>>> 0c1de67f1d4f2236d97e706a4b99a89bdba8a0b3 + diff --git a/tests/manual-tests/csa.R b/tests/manual-tests/csa.R new file mode 100644 index 0000000..0a7b250 --- /dev/null +++ b/tests/manual-tests/csa.R @@ -0,0 +1,43 @@ + +rm(list=ls()) +devtools::load_all() + +#place your utility functions here + + + +set.seed(3393) + +designpath<- system.file("extdata","CSA" ,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" + +resps =240 # number of respondents +nosim=2 # number of simulations to run (about 500 is minimum) + + +bcoeff<-list( + bx1 =0.1, + bx2 =0.3, + bx3 =0.1, + bx4 =-0.2) + + +destype <- "spdesign" + + +#place your utility functions here +ul<- list(u1= list( + v1 =V.1 ~ bx1 * alt1.x1 + bx2 * alt1.x2 + bx3 * alt1.x3 + bx4 * alt1.x4, + v2 =V.2 ~ bx1 * alt2.x1 + bx2 * alt2.x2 + bx3 * alt2.x3 + bx4 * alt2.x4 +) +) + + + +csa <- simulateDCE::sim_all(nosim = nosim, resps=resps, destype = destype, + designpath = designpath, u= ul, bcoeff = bcoeff) + + + -- GitLab