From 32b3d35c4ad3539b66655f6692c0f7912d2efa78 Mon Sep 17 00:00:00 2001
From: Julian Sagebiel <julian.sagebiel@idiv.de>
Date: Mon, 16 Dec 2024 10:24:14 +0100
Subject: [PATCH] new implementation of arguement utility_transform_type.

---
 R/sim_all.R    |  4 ++--
 R/sim_choice.R | 12 ++++++++++++
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/R/sim_all.R b/R/sim_all.R
index 671e767..e61449c 100644
--- a/R/sim_all.R
+++ b/R/sim_all.R
@@ -27,7 +27,7 @@
 #'      bheight2=0.25,
 #'      bheight3=0.50)
 #'
-sim_all <- function(nosim=2, resps, destype=NULL, designpath, u, bcoeff, decisiongroups = c(0,1), manipulations = list(), estimate = TRUE, chunks=1){
+sim_all <- function(nosim=2, resps, destype=NULL, designpath, u, bcoeff, decisiongroups = c(0,1), manipulations = list(), estimate = TRUE, chunks=1, utility_transform_type = "simple"){
 
   #################################################
   ########## Input Validation Test ###############
@@ -116,7 +116,7 @@ sim_all <- function(nosim=2, resps, destype=NULL, designpath, u, bcoeff, decisio
   tictoc::tic()
 
   all_designs<- purrr::map(designfile, sim_choice,
-                           no_sim= nosim,respondents = resps,  destype=destype, ut=u, bcoefficients = bcoeff, decisiongroups = decisiongroups, manipulations = manipulations, estimate = estimate, chunks =chunks) %>%  ## iterate simulation over all designs
+                           no_sim= nosim,respondents = resps,  destype=destype, ut=u, bcoefficients = bcoeff, decisiongroups = decisiongroups, manipulations = manipulations, estimate = estimate, chunks =chunks, utility_transform_type = utility_transform_type) %>%  ## iterate simulation over all designs
     stats::setNames(designname)
 
 
diff --git a/R/sim_choice.R b/R/sim_choice.R
index a131f85..84db8cd 100644
--- a/R/sim_choice.R
+++ b/R/sim_choice.R
@@ -34,6 +34,18 @@ sim_choice <- function(designfile, no_sim=10, respondents=330,ut ,destype=destyp
 
   }
 
+
+  mnl_U <- switch(
+    utility_transform_type,
+    "simple" = transform_util(),
+    "exact" = transform_util2(),
+    stop("Invalid utility_transform_type. Use 'simple' or 'exact'.")
+  )
+
+  ####  Print selected utility function
+  cat("Transformed utility function (type:", utility_transform_type, "):\n")
+  print(mnl_U)
+
 #### Function to simulate and estimate ####
 
   estimate_sim <- function(run=1) {         #start loop
-- 
GitLab