From bbcbeae95f7908608a5a82428d23d02d4841025e Mon Sep 17 00:00:00 2001
From: Julian Sagebiel <julian.sagebiel@idiv.de>
Date: Thu, 17 Aug 2023 23:37:10 +0200
Subject: [PATCH] new file to run the script and more designs for drive

---
 SE_DRIVE/Designs/bayeffdesignconstr.ngd | 150 ++++++++++++++++++++++++
 SE_DRIVE/Designs/effconstrsmall.ngd     |  85 ++++++++++++++
 generatemd.R                            |   2 +
 parameters_SE Design-Agri.R             |  73 ++++++------
 parameters_SE_DRIVE.R                   |  24 ++--
 simulationcore_purrr.R                  |   5 +-
 6 files changed, 292 insertions(+), 47 deletions(-)
 create mode 100644 SE_DRIVE/Designs/bayeffdesignconstr.ngd
 create mode 100644 SE_DRIVE/Designs/effconstrsmall.ngd
 create mode 100644 generatemd.R

diff --git a/SE_DRIVE/Designs/bayeffdesignconstr.ngd b/SE_DRIVE/Designs/bayeffdesignconstr.ngd
new file mode 100644
index 0000000..f862f4f
--- /dev/null
+++ b/SE_DRIVE/Designs/bayeffdesignconstr.ngd
@@ -0,0 +1,150 @@
+Design	Choice situation	alt1.x1	alt1.x2	alt1.x3	alt2.x1	alt2.x2	alt2.x3	Block	
+1	1	20	200	0	40	25	0	7	
+1	2	40	100	0	80	50	25	7	
+1	3	80	100	50	40	100	100	10	
+1	4	20	25	50	40	50	25	6	
+1	5	60	50	50	20	100	50	8	
+1	6	60	25	25	40	200	0	7	
+1	7	80	25	100	60	200	100	1	
+1	8	80	50	0	20	25	100	3	
+1	9	60	100	0	80	25	50	5	
+1	10	60	100	50	20	50	100	9	
+1	11	60	200	50	80	50	25	3	
+1	12	80	50	25	20	50	50	2	
+1	13	20	200	25	60	25	0	8	
+1	14	20	100	50	80	25	100	10	
+1	15	40	25	100	60	100	0	3	
+1	16	80	25	25	40	25	50	2	
+1	17	20	100	50	40	25	0	4	
+1	18	20	100	100	60	50	25	4	
+1	19	20	25	50	60	25	0	1	
+1	20	80	50	50	80	100	0	4	
+1	21	80	25	0	40	200	100	8	
+1	22	40	200	0	20	100	100	7	
+1	23	40	100	50	20	50	100	2	
+1	24	20	200	50	80	50	25	7	
+1	25	80	100	0	40	200	100	7	
+1	26	20	50	25	40	50	0	6	
+1	27	40	50	50	20	100	25	4	
+1	28	40	50	25	60	25	0	5	
+1	29	80	50	0	20	200	0	10	
+1	30	20	100	50	80	50	100	1	
+1	31	60	25	50	20	200	50	8	
+1	32	40	200	25	80	25	0	1	
+1	33	40	200	0	60	100	0	5	
+1	34	80	50	0	60	25	100	8	
+1	35	60	25	0	20	100	25	3	
+1	36	20	100	100	40	25	25	6	
+1	37	60	200	100	80	25	100	3	
+1	38	40	25	25	20	100	25	2	
+1	39	40	200	0	80	100	100	1	
+1	40	20	100	50	80	25	50	2	
+1	41	40	100	25	80	25	50	10	
+1	42	60	100	0	20	200	50	10	
+1	43	60	200	0	80	100	25	9	
+1	44	80	50	0	40	25	25	8	
+1	45	20	100	100	80	100	50	4	
+1	46	60	200	50	80	50	100	5	
+1	47	60	50	0	60	25	25	5	
+1	48	60	50	25	20	50	100	1	
+1	49	60	100	50	20	200	25	8	
+1	50	60	200	100	80	200	25	4	
+1	51	40	50	0	20	200	100	2	
+1	52	60	25	100	80	50	0	3	
+1	53	40	25	50	60	50	25	9	
+1	54	40	200	50	60	25	0	10	
+1	55	40	50	100	80	25	100	5	
+1	56	40	100	50	60	25	50	9	
+1	57	80	50	25	40	50	50	2	
+1	58	80	200	0	60	200	100	5	
+1	59	80	50	0	20	100	50	1	
+1	60	20	100	100	60	25	100	10	
+1	61	60	25	25	20	100	0	2	
+1	62	80	25	0	20	25	25	6	
+1	63	60	50	100	20	200	0	2	
+1	64	20	200	0	60	25	50	7	
+1	65	20	200	50	80	100	100	5	
+1	66	80	25	25	60	25	100	9	
+1	67	60	50	25	20	200	50	8	
+1	68	20	100	100	40	25	0	7	
+1	69	40	25	100	80	100	0	9	
+1	70	20	25	100	40	25	25	6	
+1	71	80	25	50	40	200	25	6	
+1	72	40	50	50	20	100	50	1	
+1	73	80	50	0	40	200	50	5	
+1	74	20	100	25	40	50	0	6	
+1	75	80	25	25	40	200	50	9	
+1	76	80	50	25	20	200	25	10	
+1	77	40	200	0	60	50	100	4	
+1	78	80	25	25	20	100	0	10	
+1	79	20	200	100	80	200	50	7	
+1	80	60	50	100	40	200	0	1	
+1	81	40	100	50	80	50	25	9	
+1	82	40	100	50	60	50	50	9	
+1	83	20	100	50	80	50	25	4	
+1	84	60	25	0	20	200	100	3	
+1	85	20	25	100	80	25	0	4	
+1	86	60	200	25	80	100	100	3	
+1	87	60	100	50	80	25	100	7	
+1	88	60	25	100	40	200	100	8	
+1	89	60	200	100	80	200	50	6	
+1	90	40	50	25	20	100	50	1	
+1	91	80	200	0	60	100	100	6	
+1	92	80	50	50	40	100	25	6	
+1	93	80	25	25	60	200	25	4	
+1	94	60	200	0	80	50	50	6	
+1	95	20	50	25	60	50	0	3	
+1	96	40	25	25	80	25	0	10	
+1	97	40	100	0	20	100	25	10	
+1	98	80	100	0	40	200	25	1	
+1	99	60	100	100	80	25	25	5	
+1	100	40	25	100	20	200	50	3	
+1	101	20	200	50	60	50	50	8	
+1	102	40	200	100	60	50	0	3	
+1	103	40	50	25	20	100	0	2	
+1	104	20	200	25	40	50	0	7	
+1	105	80	25	25	60	100	0	2	
+1	106	40	50	100	40	100	50	9	
+1	107	20	200	50	60	50	0	4	
+1	108	40	100	25	20	200	100	7	
+1	109	80	25	0	60	200	50	6	
+1	110	20	200	0	80	25	0	3	
+1	111	80	50	0	60	50	25	8	
+1	112	60	100	25	40	200	0	4	
+1	113	80	25	100	20	50	100	5	
+1	114	40	200	0	60	50	50	5	
+1	115	40	200	100	80	100	25	2	
+1	116	20	50	100	40	100	25	8	
+1	117	60	100	25	20	200	50	1	
+1	118	20	100	100	40	100	0	9	
+1	119	40	200	100	60	100	50	9	
+1	120	80	25	100	40	200	0	10	
+||||||||||
+design
+;alts = alt1, alt2
+;block = 10
+
+;eff = (mnl,d,mean)
+;rep = 1000
+;bdraws = halton(1000)
+;bseed = 2333344
+;rseed = 2333344
+;alg = swap
+;rows = 120
+
+
+
+;cond:
+if(alt1.x2+alt1.x3 >alt2.x2+alt2.x3   , alt1.x1<alt2.x1),
+if(alt1.x2+alt1.x3 <alt2.x2+alt2.x3   , alt1.x1>alt2.x1),
+if(alt1.x2=alt2.x2  , alt1.x3<>alt2.x3 )
+
+;model:
+U(alt1) = b1[(n,-0.036,0.02)]   * x1[20,40,60,80]
+        + b2[(n,-0.0034,0.002)] * x2[25,50,100,200]
+        + b3[(n,-0.0049,0.003)] * x3[0,25,50,100]
+/
+U(alt2) = b1 * x1
+        + b2 * x2
+        + b3 * x3
+$
\ No newline at end of file
diff --git a/SE_DRIVE/Designs/effconstrsmall.ngd b/SE_DRIVE/Designs/effconstrsmall.ngd
new file mode 100644
index 0000000..bea6f37
--- /dev/null
+++ b/SE_DRIVE/Designs/effconstrsmall.ngd
@@ -0,0 +1,85 @@
+Design	Choice situation	alt1.x1	alt1.x2	alt1.x3	alt2.x1	alt2.x2	alt2.x3	Block	
+1	1	20	100	25	60	100	0	3	
+1	2	80	25	25	40	200	100	5	
+1	3	60	200	50	80	50	25	2	
+1	4	60	25	25	40	50	50	3	
+1	5	20	25	25	40	25	0	2	
+1	6	40	100	100	80	100	25	5	
+1	7	40	200	50	80	200	25	3	
+1	8	60	25	50	20	200	50	3	
+1	9	80	25	100	40	200	50	3	
+1	10	20	50	50	80	50	0	5	
+1	11	60	50	0	20	200	100	2	
+1	12	60	25	0	20	200	100	1	
+1	13	80	100	50	60	200	0	5	
+1	14	40	50	100	60	100	0	3	
+1	15	80	100	100	60	200	0	5	
+1	16	20	100	50	40	50	0	1	
+1	17	20	200	0	80	100	100	1	
+1	18	60	200	25	80	25	50	5	
+1	19	20	200	50	80	50	100	3	
+1	20	40	100	0	20	100	50	2	
+1	21	60	100	25	80	50	25	4	
+1	22	60	100	50	80	50	25	2	
+1	23	80	100	0	40	100	100	2	
+1	24	80	50	50	60	200	100	5	
+1	25	60	50	100	20	200	50	1	
+1	26	80	50	25	40	100	0	4	
+1	27	80	50	100	40	100	50	2	
+1	28	20	25	100	80	25	50	5	
+1	29	20	50	100	80	50	0	1	
+1	30	20	200	50	60	100	50	4	
+1	31	20	200	50	40	100	50	3	
+1	32	40	100	25	80	25	50	1	
+1	33	80	50	100	60	200	25	1	
+1	34	40	50	100	80	25	50	4	
+1	35	40	25	100	20	200	25	3	
+1	36	20	200	25	60	100	0	2	
+1	37	60	50	50	20	200	100	4	
+1	38	80	50	25	60	25	50	5	
+1	39	60	100	0	20	200	0	5	
+1	40	40	200	100	80	25	25	2	
+1	41	20	200	0	60	25	100	5	
+1	42	40	200	50	20	200	100	4	
+1	43	20	50	0	60	25	0	4	
+1	44	20	25	50	80	25	25	4	
+1	45	60	25	25	20	100	100	2	
+1	46	80	25	25	40	200	25	1	
+1	47	60	50	0	40	100	100	1	
+1	48	80	25	25	40	50	25	2	
+1	49	60	25	25	20	50	25	3	
+1	50	40	200	0	60	50	25	4	
+1	51	40	100	0	20	25	100	4	
+1	52	80	50	100	40	100	100	2	
+1	53	20	100	50	40	100	0	5	
+1	54	40	100	0	20	50	50	4	
+1	55	20	50	100	80	100	0	1	
+1	56	40	200	100	60	25	0	3	
+1	57	60	200	25	80	25	0	1	
+1	58	60	25	0	20	50	100	3	
+1	59	60	200	0	80	25	50	1	
+1	60	80	50	50	20	25	100	4	
+||||||||||
+design
+;alts = alt1, alt2
+;block = 5
+;eff = (mnl, d)
+;alg = swap
+;rows = 60
+
+
+
+;cond:
+if(alt1.x2+alt1.x3 >alt2.x2+alt2.x3   , alt1.x1<alt2.x1),
+if(alt1.x2+alt1.x3 <alt2.x2+alt2.x3   , alt1.x1>alt2.x1),
+if(alt1.x2=alt2.x2  , alt1.x3<>alt2.x3 )
+
+;model:
+U(alt1) = b1[-0.036]  * x1[20,40,60,80]
+        + b2[-0.0034] * x2[25,50,100,200]
+        + b3[-0.0049] * x3[0,25,50,100]
+/
+U(alt2) = b1 * x1
+        + b2 * x2
+        + b3 * x3
+$
\ No newline at end of file
diff --git a/generatemd.R b/generatemd.R
new file mode 100644
index 0000000..089752d
--- /dev/null
+++ b/generatemd.R
@@ -0,0 +1,2 @@
+rmarkdown::render("simulation_output.rmd",
+                  output_file = "SE_DRIVE/simulation_DRIVE_wrongpriors.html")
\ No newline at end of file
diff --git a/parameters_SE Design-Agri.R b/parameters_SE Design-Agri.R
index 565a8d1..5b5dcc0 100644
--- a/parameters_SE Design-Agri.R	
+++ b/parameters_SE Design-Agri.R	
@@ -1,37 +1,36 @@
-
-
-designpath<- "designs-seagri/"
-
-resps =360  # number of respondents
-nosim=2 # number of simulations to run (about 500 is minimum)
-
-#betacoefficients should not include "-"
-basc = 4.2 ## very high asc
-bprof = 0.3
-bexp = 0.3
-bdomestic = 0.3
-bforeign = 0.3
-bdamage = 0.6
-bprice = 0.2
-
-manipulations = list(alt1.professional=     expr(alt1.initiator==1), 
-                     alt2.professional=     expr(alt2.initiator==1),
-                     alt1.expert      =     expr(alt1.initiator==2), 
-                     alt2.expert      =     expr(alt2.initiator==2),
-                     alt1.domestic    =     expr(alt1.funding==1), 
-                     alt2.domestic    =     expr(alt2.funding==1),
-                     alt1.foreign     =     expr(alt1.funding==2), 
-                     alt2.foreign     =     expr(alt2.funding==2))
-
-
-
-
-
-
-#place your utility functions here
-u<-list(
-  v1 =V.1 ~  bprof*alt1.professional+ bexp * alt1.expert + bdomestic * alt1.domestic + bforeign * alt1.foreign + bdamage*alt1.damage + bprice * alt1.compensation,
-  v2 =V.2 ~  bprof*alt2.professional + bexp * alt2.expert + bdomestic * alt2.domestic + bforeign * alt2.foreign + bdamage*alt2.damage + bprice * alt2.compensation,
-  v3 =V.3 ~ basc)
-
-source("simulationcore_purrr.R")
\ No newline at end of file
+
+
+designpath<- "designs-seagri/"
+
+resps =360  # number of respondents
+nosim=2 # number of simulations to run (about 500 is minimum)
+
+#betacoefficients should not include "-"
+basc = 4.2 ## very high asc
+bprof = 0.3
+bexp = 0.3
+bdomestic = 0.3
+bforeign = 0.3
+bdamage = 0.6
+bprice = 0.2
+
+manipulations = list(alt1.professional=     expr(alt1.initiator==1), 
+                     alt2.professional=     expr(alt2.initiator==1),
+                     alt1.expert      =     expr(alt1.initiator==2), 
+                     alt2.expert      =     expr(alt2.initiator==2),
+                     alt1.domestic    =     expr(alt1.funding==1), 
+                     alt2.domestic    =     expr(alt2.funding==1),
+                     alt1.foreign     =     expr(alt1.funding==2), 
+                     alt2.foreign     =     expr(alt2.funding==2))
+
+
+
+
+
+
+#place your utility functions here
+u<-list(
+  v1 =V.1 ~  bprof*alt1.professional+ bexp * alt1.expert + bdomestic * alt1.domestic + bforeign * alt1.foreign + bdamage*alt1.damage + bprice * alt1.compensation,
+  v2 =V.2 ~  bprof*alt2.professional + bexp * alt2.expert + bdomestic * alt2.domestic + bforeign * alt2.foreign + bdamage*alt2.damage + bprice * alt2.compensation,
+  v3 =V.3 ~ basc)
+
diff --git a/parameters_SE_DRIVE.R b/parameters_SE_DRIVE.R
index 36c1e01..a25dd58 100644
--- a/parameters_SE_DRIVE.R
+++ b/parameters_SE_DRIVE.R
@@ -4,17 +4,25 @@
 
 designpath<- "SE_DRIVE/Designs/"
 
-resps =360  # number of respondents
-nosim= 100 # number of simulations to run (about 500 is minimum)
+resps =120  # number of respondents
+nosim= 500 # number of simulations to run (about 500 is minimum)
 
 
 
 
-## If beta values come from other source
 
-b1 = -0.036
-b2 = -0.034
-b3 = -0.049
+
+# bpreis = -0.036
+# blade  = -0.034
+# bwarte = -0.049
+
+
+# wrong parameters
+
+# 
+bpreis = -0.01
+blade = -0.07
+bwarte = 0.02
 
 manipulations = list(alt1.x2=     expr(alt1.x2/10), 
                      alt1.x3=     expr(alt1.x3/10),
@@ -25,6 +33,6 @@ manipulations = list(alt1.x2=     expr(alt1.x2/10),
 
 #place your utility functions here
 u<-list(
-  v1 =V.1~  b1 * alt1.x1 + b2*alt1.x2 + b3*alt1.x3   ,
-  v2 =V.2~  b1 * alt2.x1 + b2*alt2.x2 + b3*alt2.x3  
+  v1 =V.1~  bpreis * alt1.x1 + blade*alt1.x2 + bwarte*alt1.x3   ,
+  v2 =V.2~  bpreis * alt2.x1 + blade*alt2.x2 + bwarte*alt2.x3  
 )
diff --git a/simulationcore_purrr.R b/simulationcore_purrr.R
index e4991d9..778759c 100644
--- a/simulationcore_purrr.R
+++ b/simulationcore_purrr.R
@@ -3,9 +3,10 @@ rm(list=ls())
 source("functions.R")
 
 library("formula.tools")
+library(ggplot2)
+library(stringr)
 
-
-  #source("parameters_SE Design-Agri.R")
+#  source("parameters_SE Design-Agri.R")
 source("parameters_SE_DRIVE.R")
 
 
-- 
GitLab