From c8d3d26f0808ba98ef1c48f1801ebadf81d042f0 Mon Sep 17 00:00:00 2001
From: samuelsmock <smock.samuel@gmail.com>
Date: Thu, 25 Jan 2024 14:51:59 +0100
Subject: [PATCH] bcoefficients unpacked generically

---
 R/simulate_choices.R          |  13 ++++---------
 tests/manual-tests/SE_Drive.R |  16 ++++++----------
 tests/testthat/Rplots.pdf     | Bin 188068 -> 188068 bytes
 tests/testthat/test-sim_all.R |   8 --------
 4 files changed, 10 insertions(+), 27 deletions(-)

diff --git a/R/simulate_choices.R b/R/simulate_choices.R
index 92cb295..d4a9fcb 100644
--- a/R/simulate_choices.R
+++ b/R/simulate_choices.R
@@ -9,15 +9,10 @@
 #'
 #' @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
-  ### 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]])
+  }
 
 
 
diff --git a/tests/manual-tests/SE_Drive.R b/tests/manual-tests/SE_Drive.R
index 33c5a07..e5d644d 100644
--- a/tests/manual-tests/SE_Drive.R
+++ b/tests/manual-tests/SE_Drive.R
@@ -11,11 +11,6 @@ designpath<- system.file("extdata","SE_DRIVE" ,package = "simulateDCE")
 resps =120  # number of respondents
 nosim= 2 # number of simulations to run (about 500 is minimum)
 
-
-
-
-
-
 # bpreis = -0.036
 # blade  = -0.034
 # bwarte = -0.049
@@ -25,10 +20,11 @@ decisiongroups=c(0,0.7,1)
 
 # wrong parameters
 
-#
-bpreis = -0.01
-blade = -0.07
-bwarte = 0.02
+# pass beta coefficients as a list
+  bcoeff <- list(
+    bpreis = -0.01,
+    blade = -0.07,
+    bwarte = 0.02)
 
 manipulations = list(alt1.x2=     expr(alt1.x2/10),
                      alt1.x3=     expr(alt1.x3/10),
@@ -55,4 +51,4 @@ ul<-list( u1 =
 destype="ngene"
 
 sedrive <- sim_all(nosim = nosim, resps=resps, destype = destype,
-                   designpath = designpath, u=ul)
+                   designpath = designpath, u=ul, bcoeff = bcoeff)
diff --git a/tests/testthat/Rplots.pdf b/tests/testthat/Rplots.pdf
index 9003f1bdf3d2ade490ac90fe7301a5db6f49d843..808a8ac27e818a18df9efda098e22658c88f2c2f 100644
GIT binary patch
delta 37
mcmZ3omwU-x?g<v`riLaa7AEEs?L}eC#^}~)#;wszp7#LUh6`)}

delta 37
mcmZ3omwU-x?g<v`CWc0ahDIh6?L}eC#^}~)#;wszp7#LR<_kyw

diff --git a/tests/testthat/test-sim_all.R b/tests/testthat/test-sim_all.R
index 283ef56..c1dc19e 100644
--- a/tests/testthat/test-sim_all.R
+++ b/tests/testthat/test-sim_all.R
@@ -10,14 +10,6 @@ resps =40  # number of respondents
 nosim=2 # number of simulations to run (about 500 is minimum)
 
 #betacoefficients should not include "-"
-bsq=0.00
-bredkite=-0.05
-bdistance=0.50
-bcost=-0.05
-bfarm2=0.25
-bfarm3=0.50
-bheight2=0.25
-bheight3=0.50
 
 bcoeff <-list(bsq=0.00,
               bredkite=-0.05,
-- 
GitLab