csa-vignette

Introduction

This vignette demonstrates how to use the simulateDCE package to simulate discrete choice experiments (DCEs). We will use a sample dataset and utility functions to generate simulated data and analyze the results.

library(simulateDCE)
library(rlang)
library(formula.tools)

Inititalize Variables

sim_all is the highest level function in the package and will run simulations for all designs contained in the specified design folder. Accordingly, this is generally the function the user will want to call. To prepare for using this function, a hypothesized utility function with corresponding beta coefficients representing the weight of each term must be declared in R like so:

bcoeff <- list(
  bx1 = -0.1,
  bx2 = -0.1,
  bx3 = -0.05,
  bx4 = -0.025
)

# 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,
  v3 = V.3 ~ -5
))

Other parameters

Besides these arguments the user must also specify the number of respondents in the simulated survey and the number of times to run the model. The number of respondents (resps) should be selected based on experimental design parameters, while the number of simulations (nosim) should be large enough to glean statistically significant data. It is best to use a small number for this while learning to use the package and a large number (at least 500) once the other parameters have been settled.

The simulation can be ran using spdesign or NGENE design files which will be contained in the design path. The design path and design type, must also be specified as strings:

designpath <- system.file("extdata", "CSA", "linear", package = "simulateDCE")
## can also be specified using relative path eg. designpath<- "Projects/CSA/Designs/"

# 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)

## design type must be either 'spdesign' or 'ngene'
destype <- "spdesign"

Randomness

As several part of the simulation rely on random values within experimentally defined bounds, the output of a given simulation call using sim_all will vary each time it is called. Unless the seed for R’s randome number generator is set like so:

set.seed(3393)

Output

The sim_all function returns a multidimensional R list containing graphs, simulated observations and a dataframe containing sumaries of estimated b coefficients. In general these will be printed to the console, but the entire results can also be assigned to an r list object.

csa <- simulateDCE::sim_all(
  nosim = nosim, resps = resps, designtype = destype,
  designpath = designpath, u = ul, bcoeff = bcoeff
)
#> 'simple' is deprecated and will be removed in the future. Use 'exact' instead.
#> bcoeff_lookup already exists; skipping modification.
#> 
#> Utility function used in simulation (true utility):
#> $u1
#> $u1$v1
#> V.1 ~ bx1 * alt1.x1 + bx2 * alt1.x2 + bx3 * alt1.x3 + bx4 * alt1.x4
#> <environment: 0x5f74e3a6d360>
#> 
#> $u1$v2
#> V.2 ~ bx1 * alt2.x1 + bx2 * alt2.x2 + bx3 * alt2.x3 + bx4 * alt2.x4
#> <environment: 0x5f74e3a8b478>
#> 
#> $u1$v3
#> V.3 ~ -5
#> <environment: 0x5f74e3aa5178>
#> assign keys for bcoeff): 0 sec elapsed
#> user entered manipulations: 0.013 sec elapsed
#> split dataframe into groups: 0.004 sec elapsed
#> for each group calculate utility: 2.272 sec elapsed
#> add random component: 0.048 sec elapsed
#> whole simulate choices: 2.339 sec elapsed
#> 
#>  No preprocess function provided. Proceeding without additional preprocessing.
#> 
#>  dataset preprossed_data exists: FALSE
#> 
#>  decisiongroups exists: FALSE
#> 
#>  data has been created
#> 
#> First few observations of the dataset
#>   ID Choice_situation alt1_x1 alt1_x2 alt1_x3 alt1_x4 alt2_x1 alt2_x2 alt2_x3
#> 1  1                1       0       0       0      80       0       1       0
#> 2  1                2      25       1       0      90       0       0       1
#> 3  1                3      75       0       1     140      50       1       0
#> 4  1                5       0       0       0     140       0       1       1
#> 5  1                6       0       0       1     130       0       1       1
#> 6  1                8       0       1       0      80       0       0       0
#>   alt2_x4 alt3_sq Block group    V_1   V_2 V_3        e_1        e_2
#> 1     120       1     1     1  -2.00 -3.10  -5 -1.3431262  0.4311932
#> 2      90       1     1     1  -4.85 -2.30  -5  1.5177036 -0.7730600
#> 3      80       1     1     1 -11.05 -7.10  -5  0.2870881  0.0786451
#> 4      90       1     1     1  -3.50 -2.40  -5  1.5647928  1.1257428
#> 5      80       1     1     1  -3.30 -2.15  -5 -1.2806816 -0.4102479
#> 6     110       1     1     1  -2.10 -2.75  -5  0.9839135  1.3273417
#>            e_3        U_1       U_2       U_3 CHOICE
#> 1  0.618892998  -3.343126 -2.668807 -4.381107      2
#> 2 -0.003069536  -3.332296 -3.073060 -5.003070      2
#> 3  0.329465008 -10.762912 -7.021355 -4.670535      3
#> 4 -0.410028767  -1.935207 -1.274257 -5.410029      2
#> 5 -0.134615085  -4.580682 -2.560248 -5.134615      2
#> 6  1.590954748  -1.116087 -1.422658 -3.409045      1
#> assign keys for bcoeff): 0 sec elapsed
#> user entered manipulations: 0.012 sec elapsed
#> split dataframe into groups: 0.016 sec elapsed
#> for each group calculate utility: 2.215 sec elapsed
#> add random component: 0.041 sec elapsed
#> whole simulate choices: 2.286 sec elapsed
#> 
#>  No preprocess function provided. Proceeding without additional preprocessing.
#> 
#>  dataset preprossed_data exists: FALSE
#> 
#>  decisiongroups exists: FALSE
#> 
#>  data has been created
#> 
#> First few observations of the dataset
#>   ID Choice_situation alt1_x1 alt1_x2 alt1_x3 alt1_x4 alt2_x1 alt2_x2 alt2_x3
#> 1  1                1       0       0       0      80       0       1       0
#> 2  1                2      25       1       0      90       0       0       1
#> 3  1                3      75       0       1     140      50       1       0
#> 4  1                5       0       0       0     140       0       1       1
#> 5  1                6       0       0       1     130       0       1       1
#> 6  1                8       0       1       0      80       0       0       0
#>   alt2_x4 alt3_sq Block group    V_1   V_2 V_3          e_1        e_2
#> 1     120       1     1     1  -2.00 -3.10  -5  3.261831036 -0.2080592
#> 2      90       1     1     1  -4.85 -2.30  -5  0.002154937 -0.8044204
#> 3      80       1     1     1 -11.05 -7.10  -5  1.795082315 -0.1115009
#> 4      90       1     1     1  -3.50 -2.40  -5 -0.747121351  0.6680545
#> 5      80       1     1     1  -3.30 -2.15  -5 -0.265176431 -0.5003314
#> 6     110       1     1     1  -2.10 -2.75  -5  1.083209887  1.3210412
#>          e_3       U_1       U_2       U_3 CHOICE
#> 1  0.3793593  1.261831 -3.308059 -4.620641      1
#> 2  1.3282928 -4.847845 -3.104420 -3.671707      2
#> 3  1.8405168 -9.254918 -7.211501 -3.159483      3
#> 4  0.2740223 -4.247121 -1.731946 -4.725978      2
#> 5  1.1296270 -3.565176 -2.650331 -3.870373      2
#> 6 -0.7475822 -1.016790 -1.428959 -5.747582      1
#> 
#> Transformed utility function (type: simple):
#> [1] "U_1 = @bx1 * $alt1_x1 + @bx2 * $alt1_x2 + @bx3 * $alt1_x3 + @bx4 * $alt1_x4 ;U_2 = @bx1 * $alt2_x1 + @bx2 * $alt2_x2 + @bx3 * $alt2_x3 + @bx4 * $alt2_x4 ;U_3 = -5 ;"
#> Initial function value: -3241.625 
#> Initial gradient value:
#>          bx1          bx2          bx3          bx4 
#> -28054.12418    -22.97081    -81.17227 -45028.04443 
#> initial  value 3241.625180 
#> iter   2 value 2163.092733
#> iter   3 value 1857.581013
#> iter   4 value 1820.021052
#> iter   5 value 1813.183543
#> iter   6 value 1581.129314
#> iter   7 value 1527.985382
#> iter   8 value 1517.275373
#> iter   9 value 1513.456144
#> iter  10 value 1512.977664
#> iter  11 value 1512.977326
#> iter  12 value 1512.976861
#> iter  13 value 1512.972705
#> iter  14 value 1512.972630
#> iter  15 value 1512.971555
#> iter  15 value 1512.971548
#> iter  15 value 1512.971548
#> final  value 1512.971548 
#> converged
#> Initial function value: -3356.625 
#> Initial gradient value:
#>          bx1          bx2          bx3          bx4 
#> -28479.12418    -69.97081    -69.17227 -46358.04443 
#> initial  value 3356.625180 
#> iter   2 value 2225.160583
#> iter   3 value 1901.848155
#> iter   4 value 1850.163988
#> iter   5 value 1850.113838
#> iter   6 value 1670.787468
#> iter   7 value 1569.049800
#> iter   8 value 1558.448720
#> iter   9 value 1552.795707
#> iter  10 value 1552.221662
#> iter  11 value 1552.199486
#> iter  12 value 1552.178401
#> iter  13 value 1552.165301
#> iter  14 value 1552.164895
#> iter  15 value 1552.160211
#> iter  15 value 1552.160198
#> iter  15 value 1552.160198
#> final  value 1552.160198 
#> converged
#> start_estimation: 0.136 sec elapsed
#> 
#> Summary table:
#> 
#> 
#> =============  ====  ===  =====  ====  ======  =====  =====  =====  ====  ========  ====
#> \              vars    n   mean    sd  median    min    max  range  skew  kurtosis    se
#> =============  ====  ===  =====  ====  ======  =====  =====  =====  ====  ========  ====
#> est_bx1           1    2  -0.10  0.00   -0.10  -0.10  -0.10   0.00     0     -2.75  0.00
#> est_bx2           2    2  -0.05  0.10   -0.05  -0.13   0.02   0.15     0     -2.75  0.07
#> est_bx3           3    2  -0.12  0.09   -0.12  -0.19  -0.06   0.13     0     -2.75  0.06
#> est_bx4           4    2  -0.02  0.00   -0.02  -0.02  -0.02   0.00     0     -2.75  0.00
#> rob_pval0_bx1     5    2   0.00  0.00    0.00   0.00   0.00   0.00   NaN       NaN  0.00
#> rob_pval0_bx2     6    2   0.38  0.51    0.38   0.02   0.74   0.72     0     -2.75  0.36
#> rob_pval0_bx3     7    2   0.21  0.27    0.21   0.01   0.40   0.38     0     -2.75  0.19
#> rob_pval0_bx4     8    2   0.00  0.00    0.00   0.00   0.00   0.00   NaN       NaN  0.00
#> =============  ====  ===  =====  ====  ======  =====  =====  =====  ====  ========  ====
#> 
#> Power results:
#> 
#> FALSE 
#>   100
#> 'simple' is deprecated and will be removed in the future. Use 'exact' instead.
#> bcoeff_lookup already exists; skipping modification.
#> 
#> Utility function used in simulation (true utility):
#> $u1
#> $u1$v1
#> V.1 ~ bx1 * alt1.x1 + bx2 * alt1.x2 + bx3 * alt1.x3 + bx4 * alt1.x4
#> <environment: 0x5f74e604fe30>
#> 
#> $u1$v2
#> V.2 ~ bx1 * alt2.x1 + bx2 * alt2.x2 + bx3 * alt2.x3 + bx4 * alt2.x4
#> <environment: 0x5f74e606d068>
#> 
#> $u1$v3
#> V.3 ~ -5
#> <environment: 0x5f74e6090c18>
#> assign keys for bcoeff): 0 sec elapsed
#> user entered manipulations: 0.012 sec elapsed
#> split dataframe into groups: 0.003 sec elapsed
#> for each group calculate utility: 2.162 sec elapsed
#> add random component: 0.044 sec elapsed
#> whole simulate choices: 2.223 sec elapsed
#> 
#>  No preprocess function provided. Proceeding without additional preprocessing.
#> 
#>  dataset preprossed_data exists: FALSE
#> 
#>  decisiongroups exists: FALSE
#> 
#>  data has been created
#> 
#> First few observations of the dataset
#>   ID Choice_situation alt1_x1 alt1_x2 alt1_x3 alt1_x4 alt2_x1 alt2_x2 alt2_x3
#> 1  1                2       0       0       0     100       0       1       1
#> 2  1                5      50       1       0     120      50       0       1
#> 3  1                9       0       0       1      90       0       1       0
#> 4  1               10      25       0       0     110      25       1       0
#> 5  1               12      25       0       1     120      25       0       0
#> 6  1               13       0       1       0      80      25       1       1
#>   alt2_x4 alt3_sq Block group   V_1   V_2 V_3        e_1        e_2        e_3
#> 1     120       1     1     1 -2.50 -3.15  -5  0.2283479  0.2114376  0.4238020
#> 2      80       1     1     1 -8.10 -7.05  -5 -0.9572889 -0.3431828  1.8055939
#> 3     130       1     1     1 -2.30 -3.35  -5  0.1610206 -0.4258625 -0.2960403
#> 4      80       1     1     1 -5.25 -4.60  -5  0.3103184 -1.4416677  0.3262861
#> 5     150       1     1     1 -5.55 -6.25  -5  1.3348132 -0.1615000 -0.2705518
#> 6     130       1     1     1 -2.10 -5.90  -5  0.1725666  3.9096835 -1.5870600
#>         U_1       U_2       U_3 CHOICE
#> 1 -2.271652 -2.938562 -4.576198      1
#> 2 -9.057289 -7.393183 -3.194406      3
#> 3 -2.138979 -3.775862 -5.296040      1
#> 4 -4.939682 -6.041668 -4.673714      3
#> 5 -4.215187 -6.411500 -5.270552      1
#> 6 -1.927433 -1.990316 -6.587060      1
#> assign keys for bcoeff): 0 sec elapsed
#> user entered manipulations: 0.013 sec elapsed
#> split dataframe into groups: 0.003 sec elapsed
#> for each group calculate utility: 2.163 sec elapsed
#> add random component: 0.041 sec elapsed
#> whole simulate choices: 2.222 sec elapsed
#> 
#>  No preprocess function provided. Proceeding without additional preprocessing.
#> 
#>  dataset preprossed_data exists: FALSE
#> 
#>  decisiongroups exists: FALSE
#> 
#>  data has been created
#> 
#> First few observations of the dataset
#>   ID Choice_situation alt1_x1 alt1_x2 alt1_x3 alt1_x4 alt2_x1 alt2_x2 alt2_x3
#> 1  1                2       0       0       0     100       0       1       1
#> 2  1                5      50       1       0     120      50       0       1
#> 3  1                9       0       0       1      90       0       1       0
#> 4  1               10      25       0       0     110      25       1       0
#> 5  1               12      25       0       1     120      25       0       0
#> 6  1               13       0       1       0      80      25       1       1
#>   alt2_x4 alt3_sq Block group   V_1   V_2 V_3        e_1        e_2        e_3
#> 1     120       1     1     1 -2.50 -3.15  -5 -0.3410475  1.0663781  0.2114102
#> 2      80       1     1     1 -8.10 -7.05  -5  1.6900014  1.8647184 -0.4196018
#> 3     130       1     1     1 -2.30 -3.35  -5  1.0465233  0.3460339 -0.3157360
#> 4      80       1     1     1 -5.25 -4.60  -5 -0.6799246 -1.7138636  1.0692299
#> 5     150       1     1     1 -5.55 -6.25  -5 -0.4481841  1.9378475  1.3412840
#> 6     130       1     1     1 -2.10 -5.90  -5  1.3733862  0.7375437  0.3656113
#>          U_1       U_2       U_3 CHOICE
#> 1 -2.8410475 -2.083622 -4.788590      2
#> 2 -6.4099986 -5.185282 -5.419602      2
#> 3 -1.2534767 -3.003966 -5.315736      1
#> 4 -5.9299246 -6.313864 -3.930770      3
#> 5 -5.9981841 -4.312153 -3.658716      3
#> 6 -0.7266138 -5.162456 -4.634389      1
#> 
#> Transformed utility function (type: simple):
#> [1] "U_1 = @bx1 * $alt1_x1 + @bx2 * $alt1_x2 + @bx3 * $alt1_x3 + @bx4 * $alt1_x4 ;U_2 = @bx1 * $alt2_x1 + @bx2 * $alt2_x2 + @bx3 * $alt2_x3 + @bx4 * $alt2_x4 ;U_3 = -5 ;"
#> Initial function value: -4151.625 
#> Initial gradient value:
#>         bx1         bx2         bx3         bx4 
#> -24759.1607   -200.1723   -381.7693 -67317.4606 
#> initial  value 4151.625180 
#> iter   2 value 2308.317330
#> iter   3 value 2169.184540
#> iter   4 value 2162.167322
#> iter   5 value 2159.854401
#> iter   6 value 1751.606220
#> iter   7 value 1744.384185
#> iter   8 value 1732.443177
#> iter   9 value 1731.953830
#> iter  10 value 1731.739704
#> iter  11 value 1731.739123
#> iter  12 value 1731.736671
#> iter  13 value 1731.730892
#> iter  13 value 1731.730876
#> iter  14 value 1731.730633
#> iter  15 value 1731.730597
#> iter  16 value 1731.728088
#> iter  17 value 1731.728056
#> iter  18 value 1731.725973
#> iter  19 value 1731.725934
#> iter  19 value 1731.725934
#> iter  19 value 1731.725934
#> final  value 1731.725934 
#> converged
#> Initial function value: -4151.625 
#> Initial gradient value:
#>         bx1         bx2         bx3         bx4 
#> -24484.1607   -167.1723   -377.7693 -67497.4606 
#> initial  value 4151.625180 
#> iter   2 value 2307.420675
#> iter   3 value 2209.980123
#> iter   4 value 2196.109675
#> iter   5 value 2194.015777
#> iter   6 value 1831.148974
#> iter   7 value 1790.235633
#> iter   8 value 1764.462901
#> iter   9 value 1760.031032
#> iter  10 value 1759.750702
#> iter  11 value 1759.740814
#> iter  12 value 1759.716490
#> iter  13 value 1759.715751
#> iter  14 value 1759.700739
#> iter  15 value 1759.670884
#> iter  16 value 1759.669231
#> iter  16 value 1759.669231
#> iter  16 value 1759.669231
#> final  value 1759.669231 
#> converged
#> start_estimation: 0.153 sec elapsed
#> 
#> Summary table:
#> 
#> 
#> =============  ====  ===  =====  ====  ======  =====  =====  =====  ====  ========  ====
#> \              vars    n   mean    sd  median    min    max  range  skew  kurtosis    se
#> =============  ====  ===  =====  ====  ======  =====  =====  =====  ====  ========  ====
#> est_bx1           1    2  -0.10  0.00   -0.10  -0.10  -0.10   0.00     0     -2.75  0.00
#> est_bx2           2    2  -0.13  0.07   -0.13  -0.18  -0.07   0.10     0     -2.75  0.05
#> est_bx3           3    2  -0.15  0.01   -0.15  -0.16  -0.15   0.01     0     -2.75  0.01
#> est_bx4           4    2  -0.02  0.00   -0.02  -0.02  -0.02   0.00     0     -2.75  0.00
#> rob_pval0_bx1     5    2   0.00  0.00    0.00   0.00   0.00   0.00   NaN       NaN  0.00
#> rob_pval0_bx2     6    2   0.10  0.14    0.10   0.00   0.21   0.20     0     -2.75  0.10
#> rob_pval0_bx3     7    2   0.02  0.00    0.02   0.01   0.02   0.00     0     -2.75  0.00
#> rob_pval0_bx4     8    2   0.00  0.00    0.00   0.00   0.00   0.00   NaN       NaN  0.00
#> =============  ====  ===  =====  ====  ======  =====  =====  =====  ====  ========  ====
#> 
#> Power results:
#> 
#> FALSE  TRUE 
#>    50    50
#> 'simple' is deprecated and will be removed in the future. Use 'exact' instead.
#> bcoeff_lookup already exists; skipping modification.
#> 
#> Utility function used in simulation (true utility):
#> $u1
#> $u1$v1
#> V.1 ~ bx1 * alt1.x1 + bx2 * alt1.x2 + bx3 * alt1.x3 + bx4 * alt1.x4
#> <environment: 0x5f74e04eb440>
#> 
#> $u1$v2
#> V.2 ~ bx1 * alt2.x1 + bx2 * alt2.x2 + bx3 * alt2.x3 + bx4 * alt2.x4
#> <environment: 0x5f74e049aa20>
#> 
#> $u1$v3
#> V.3 ~ -5
#> <environment: 0x5f74e046a428>
#> assign keys for bcoeff): 0 sec elapsed
#> user entered manipulations: 0.012 sec elapsed
#> split dataframe into groups: 0.003 sec elapsed
#> for each group calculate utility: 2.206 sec elapsed
#> add random component: 0.042 sec elapsed
#> whole simulate choices: 2.264 sec elapsed
#> 
#>  No preprocess function provided. Proceeding without additional preprocessing.
#> 
#>  dataset preprossed_data exists: FALSE
#> 
#>  decisiongroups exists: FALSE
#> 
#>  data has been created
#> 
#> First few observations of the dataset
#>   ID Choice_situation alt1_x1 alt1_x2 alt1_x3 alt1_x4 alt2_x1 alt2_x2 alt2_x3
#> 1  1                5       0       0       0     150     100       0       1
#> 2  1                7      25       0       0      80       0       1       0
#> 3  1                9      25       1       1      90       0       1       0
#> 4  1               10     100       0       1     120      25       1       0
#> 5  1               11     100       0       0      80     100       1       0
#> 6  1               12      50       1       1     150      25       0       0
#>   alt2_x4 alt3_sq Block group    V_1    V_2 V_3          e_1         e_2
#> 1      80       1     1     1  -3.75 -12.05  -5  1.099838554  0.15880011
#> 2     110       1     1     1  -4.50  -2.85  -5  2.532366583 -1.12394155
#> 3     140       1     1     1  -4.90  -3.60  -5 -0.865335081 -0.98131103
#> 4      80       1     1     1 -13.05  -4.60  -5 -0.458208905 -0.20352704
#> 5      90       1     1     1 -12.00 -12.35  -5  0.420976234 -1.18968314
#> 6     150       1     1     1  -8.90  -6.25  -5  0.007028381 -0.08608272
#>           e_3        U_1        U_2       U_3 CHOICE
#> 1  0.09572715  -2.650161 -11.891200 -4.904273      1
#> 2  1.68952223  -1.967633  -3.973942 -3.310478      1
#> 3  1.62469324  -5.765335  -4.581311 -3.375307      3
#> 4 -0.96400436 -13.508209  -4.803527 -5.964004      2
#> 5  0.11649541 -11.579024 -13.539683 -4.883505      3
#> 6  0.92257558  -8.892972  -6.336083 -4.077424      3
#> assign keys for bcoeff): 0 sec elapsed
#> user entered manipulations: 0.014 sec elapsed
#> split dataframe into groups: 0.003 sec elapsed
#> for each group calculate utility: 2.256 sec elapsed
#> add random component: 0.044 sec elapsed
#> whole simulate choices: 2.318 sec elapsed
#> 
#>  No preprocess function provided. Proceeding without additional preprocessing.
#> 
#>  dataset preprossed_data exists: FALSE
#> 
#>  decisiongroups exists: FALSE
#> 
#>  data has been created
#> 
#> First few observations of the dataset
#>   ID Choice_situation alt1_x1 alt1_x2 alt1_x3 alt1_x4 alt2_x1 alt2_x2 alt2_x3
#> 1  1                5       0       0       0     150     100       0       1
#> 2  1                7      25       0       0      80       0       1       0
#> 3  1                9      25       1       1      90       0       1       0
#> 4  1               10     100       0       1     120      25       1       0
#> 5  1               11     100       0       0      80     100       1       0
#> 6  1               12      50       1       1     150      25       0       0
#>   alt2_x4 alt3_sq Block group    V_1    V_2 V_3         e_1        e_2
#> 1      80       1     1     1  -3.75 -12.05  -5  0.18768477  0.6182522
#> 2     110       1     1     1  -4.50  -2.85  -5 -0.33070917  0.9394820
#> 3     140       1     1     1  -4.90  -3.60  -5  3.09376692 -0.8518250
#> 4      80       1     1     1 -13.05  -4.60  -5  1.87119573  0.6142236
#> 5      90       1     1     1 -12.00 -12.35  -5 -0.98089710  0.5232656
#> 6     150       1     1     1  -8.90  -6.25  -5  0.07346766  1.0457122
#>           e_3        U_1        U_2       U_3 CHOICE
#> 1  1.34067687  -3.562315 -11.431748 -3.659323      1
#> 2 -0.24989946  -4.830709  -1.910518 -5.249899      2
#> 3  2.09885304  -1.806233  -4.451825 -2.901147      1
#> 4  1.10797049 -11.178804  -3.985776 -3.892030      3
#> 5 -0.03074646 -12.980897 -11.826734 -5.030746      3
#> 6  1.14518851  -8.826532  -5.204288 -3.854811      3
#> 
#> Transformed utility function (type: simple):
#> [1] "U_1 = @bx1 * $alt1_x1 + @bx2 * $alt1_x2 + @bx3 * $alt1_x3 + @bx4 * $alt1_x4 ;U_2 = @bx1 * $alt2_x1 + @bx2 * $alt2_x2 + @bx3 * $alt2_x3 + @bx4 * $alt2_x4 ;U_3 = -5 ;"
#> Initial function value: -6681.625 
#> Initial gradient value:
#>          bx1          bx2          bx3          bx4 
#>  -91767.5915    -472.7693    -511.3737 -118787.6065 
#> initial  value 6681.625180 
#> iter   2 value 2756.044069
#> iter   3 value 1111.217791
#> iter   4 value 1109.265251
#> iter   5 value 1079.106395
#> iter   6 value 1075.189394
#> iter   7 value 1054.846075
#> iter   8 value 1047.903438
#> iter   9 value 1046.453679
#> iter  10 value 1046.450252
#> iter  10 value 1046.450249
#> final  value 1046.450249 
#> converged
#> Initial function value: -6521.625 
#> Initial gradient value:
#>          bx1          bx2          bx3          bx4 
#>  -91392.5915    -475.7693    -502.3737 -114547.6065 
#> initial  value 6521.625180 
#> iter   2 value 2659.253067
#> iter   3 value 1096.442932
#> iter   4 value 1090.366677
#> iter   5 value 1081.573972
#> iter   6 value 1047.323643
#> iter   7 value 1034.941655
#> iter   8 value 1026.477332
#> iter   9 value 1025.174185
#> iter  10 value 1025.069913
#> iter  10 value 1025.069906
#> final  value 1025.069906 
#> converged
#> start_estimation: 0.1 sec elapsed
#> 
#> Summary table:
#> 
#> 
#> =============  ====  ===  =====  ====  ======  =====  =====  =====  ====  ========  ====
#> \              vars    n   mean    sd  median    min    max  range  skew  kurtosis    se
#> =============  ====  ===  =====  ====  ======  =====  =====  =====  ====  ========  ====
#> est_bx1           1    2  -0.10  0.00   -0.10  -0.10  -0.10   0.00     0     -2.75  0.00
#> est_bx2           2    2  -0.20  0.12   -0.20  -0.29  -0.12   0.17     0     -2.75  0.09
#> est_bx3           3    2  -0.11  0.02   -0.11  -0.12  -0.09   0.03     0     -2.75  0.01
#> est_bx4           4    2  -0.02  0.00   -0.02  -0.02  -0.02   0.00     0     -2.75  0.00
#> rob_pval0_bx1     5    2   0.00  0.00    0.00   0.00   0.00   0.00   NaN       NaN  0.00
#> rob_pval0_bx2     6    2   0.10  0.13    0.10   0.00   0.19   0.19     0     -2.75  0.09
#> rob_pval0_bx3     7    2   0.26  0.11    0.26   0.18   0.34   0.15     0     -2.75  0.08
#> rob_pval0_bx4     8    2   0.00  0.00    0.00   0.00   0.00   0.00   NaN       NaN  0.00
#> =============  ====  ===  =====  ====  ======  =====  =====  =====  ====  ========  ====
#> 
#> Power results:
#> 
#> FALSE 
#>   100
#> total time for simulation and estimation: 18.667 sec elapsed
#> $tic
#> elapsed 
#>  35.809 
#> 
#> $toc
#> elapsed 
#>  54.476 
#> 
#> $msg
#> [1] "total time for simulation and estimation"
#> 
#> $callback_msg
#> [1] "total time for simulation and estimation: 18.667 sec elapsed"
#> Trying tidyr::pivot_longer for reshaping...

Accessing the Output in R

The beta cofficients for each simulation are contained in a dataframe called coeffs within within a nested list structure output. A summary table showing the beta coefficient statistics is also made within each experimental design.

You can also save the results to disk using saveRDS(csa,file = “tests/manual-tests/csa.RDS”)

topLevelResults <- names(csa[sapply(csa, is.list)])

print(topLevelResults)
#> [1] "BLIIbay"    "BLIbay"     "BLIeff"     "time"       "arguements"
#> [6] "summaryall" "graphs"     "powa"

## saves and prints the key results of the first expreimental design
simulationCoeff <- csa[[1]]$coefs
coeffSummary <- csa[[1]]$summary

print(simulationCoeff)
#> # A tibble: 2 × 9
#>   run   est_bx1 est_bx2 est_bx3 est_bx4 rob_pval0_bx1 rob_pval0_bx2
#>   <chr>   <dbl>   <dbl>   <dbl>   <dbl>         <dbl>         <dbl>
#> 1 1      -0.102  0.0188 -0.187  -0.0229     1.77e-169        0.739 
#> 2 2      -0.105 -0.129  -0.0613 -0.0234     6.41e-152        0.0227
#> # ℹ 2 more variables: rob_pval0_bx3 <dbl>, rob_pval0_bx4 <dbl>
print(coeffSummary)
#>               vars n  mean   sd median   min   max range skew kurtosis   se
#> est_bx1          1 2 -0.10 0.00  -0.10 -0.10 -0.10  0.00    0    -2.75 0.00
#> est_bx2          2 2 -0.05 0.10  -0.05 -0.13  0.02  0.15    0    -2.75 0.07
#> est_bx3          3 2 -0.12 0.09  -0.12 -0.19 -0.06  0.13    0    -2.75 0.06
#> est_bx4          4 2 -0.02 0.00  -0.02 -0.02 -0.02  0.00    0    -2.75 0.00
#> rob_pval0_bx1    5 2  0.00 0.00   0.00  0.00  0.00  0.00  NaN      NaN 0.00
#> rob_pval0_bx2    6 2  0.38 0.51   0.38  0.02  0.74  0.72    0    -2.75 0.36
#> rob_pval0_bx3    7 2  0.21 0.27   0.21  0.01  0.40  0.38    0    -2.75 0.19
#> rob_pval0_bx4    8 2  0.00 0.00   0.00  0.00  0.00  0.00  NaN      NaN 0.00
## saveRDS(csa,file = "tests/manual-tests/csa.RDS")