diff --git a/R/simulate_choices.R b/R/simulate_choices.R index 92cb295a8cd4a440ee7c3e93902daa4de4f06b54..d4a9fcb271f5d484b67cdb82530ab2fa6252240a 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 33c5a0791c435c62147f1cb49b5348e0d22376d9..e5d644deea9838a0f7cd0cb9aa96fa70df0a13cb 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 Binary files a/tests/testthat/Rplots.pdf and b/tests/testthat/Rplots.pdf differ diff --git a/tests/testthat/test-sim_all.R b/tests/testthat/test-sim_all.R index 283ef565a904e164fc3f2ca40b657de0b77e45b5..c1dc19e401a53d4a8af6a30300db957de841f49f 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,