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)
#> 
#> Attaching package: 'formula.tools'
#> The following object is masked from 'package:rlang':
#> 
#>     env

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: 0x64535828f8f0>
#> 
#> $u1$v2
#> V.2 ~ bx1 * alt2.x1 + bx2 * alt2.x2 + bx3 * alt2.x3 + bx4 * alt2.x4
#> <environment: 0x6453582d2470>
#> 
#> $u1$v3
#> V.3 ~ -5
#> <environment: 0x645358301018>
#> 
#>  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
#> 1     120       1     1     1 -2.50 -3.15  -5 -1.3431262  0.4311932
#> 2      80       1     1     1 -8.10 -7.05  -5  1.5177036 -0.7730600
#> 3     130       1     1     1 -2.30 -3.35  -5  0.2870881  0.0786451
#> 4      80       1     1     1 -5.25 -4.60  -5  1.5647928  1.1257428
#> 5     150       1     1     1 -5.55 -6.25  -5 -1.2806816 -0.4102479
#> 6     130       1     1     1 -2.10 -5.90  -5  0.9839135  1.3273417
#>            e_3       U_1       U_2       U_3 CHOICE
#> 1  0.618892998 -3.843126 -2.718807 -4.381107      2
#> 2 -0.003069536 -6.582296 -7.823060 -5.003070      3
#> 3  0.329465008 -2.012912 -3.271355 -4.670535      1
#> 4 -0.410028767 -3.685207 -3.474257 -5.410029      2
#> 5 -0.134615085 -6.830682 -6.660248 -5.134615      3
#> 6  1.590954748 -1.116087 -4.572658 -3.409045      1
#> 
#>  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
#> 1     120       1     1     1 -2.50 -3.15  -5  3.261831036 -0.2080592
#> 2      80       1     1     1 -8.10 -7.05  -5  0.002154937 -0.8044204
#> 3     130       1     1     1 -2.30 -3.35  -5  1.795082315 -0.1115009
#> 4      80       1     1     1 -5.25 -4.60  -5 -0.747121351  0.6680545
#> 5     150       1     1     1 -5.55 -6.25  -5 -0.265176431 -0.5003314
#> 6     130       1     1     1 -2.10 -5.90  -5  1.083209887  1.3210412
#>          e_3        U_1       U_2       U_3 CHOICE
#> 1  0.3793593  0.7618310 -3.358059 -4.620641      1
#> 2  1.3282928 -8.0978451 -7.854420 -3.671707      3
#> 3  1.8405168 -0.5049177 -3.461501 -3.159483      1
#> 4  0.2740223 -5.9971214 -3.931946 -4.725978      2
#> 5  1.1296270 -5.8151764 -6.750331 -3.870373      3
#> 6 -0.7475822 -1.0167901 -4.578959 -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: -4011.625 
#> Initial gradient value:
#>         bx1         bx2         bx3         bx4 
#> -24359.1607   -143.1723   -324.7693 -65577.4606 
#> initial  value 4011.625180 
#> iter   2 value 2242.346879
#> iter   3 value 2124.609072
#> iter   4 value 2119.388696
#> iter   5 value 2117.047458
#> iter   6 value 1712.530505
#> iter   7 value 1699.349949
#> iter   8 value 1684.529726
#> iter   9 value 1684.372229
#> iter  10 value 1683.852662
#> iter  11 value 1683.852224
#> iter  12 value 1683.851937
#> iter  13 value 1683.851248
#> iter  14 value 1683.851227
#> iter  15 value 1683.849890
#> iter  16 value 1683.849443
#> iter  16 value 1683.849443
#> iter  16 value 1683.849443
#> final  value 1683.849443 
#> converged
#> Initial function value: -4231.625 
#> Initial gradient value:
#>         bx1         bx2         bx3         bx4 
#> -25109.1607   -168.1723   -369.7693 -69127.4606 
#> initial  value 4231.625180 
#> iter   2 value 2312.805941
#> iter   3 value 2158.658712
#> iter   4 value 2146.314073
#> iter   5 value 1914.129390
#> iter   6 value 1895.606947
#> iter   7 value 1744.554758
#> iter   8 value 1742.989739
#> iter   9 value 1736.926702
#> iter  10 value 1736.884285
#> iter  11 value 1736.883422
#> iter  12 value 1736.878133
#> iter  13 value 1736.876580
#> iter  14 value 1736.876542
#> iter  15 value 1736.875692
#> iter  16 value 1736.874250
#> iter  16 value 1736.874250
#> iter  16 value 1736.874250
#> final  value 1736.874250 
#> converged
#> 
#> 
#> 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.04  0.02   -0.04  -0.05  -0.02   0.03     0     -2.75  0.01
#> est_bx3           3    2  -0.03  0.09   -0.03  -0.10   0.03   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.55  0.21    0.55   0.40   0.70   0.30     0     -2.75  0.15
#> rob_pval0_bx3     7    2   0.36  0.34    0.36   0.12   0.60   0.48     0     -2.75  0.24
#> 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: 0x64535bbc7b78>
#> 
#> $u1$v2
#> V.2 ~ bx1 * alt2.x1 + bx2 * alt2.x2 + bx3 * alt2.x3 + bx4 * alt2.x4
#> <environment: 0x64535baa5320>
#> 
#> $u1$v3
#> V.3 ~ -5
#> <environment: 0x64535ba80e78>
#> 
#>  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.2283479  0.2114376
#> 2     110       1     1     1  -4.50  -2.85  -5 -0.9572889 -0.3431828
#> 3     140       1     1     1  -4.90  -3.60  -5  0.1610206 -0.4258625
#> 4      80       1     1     1 -13.05  -4.60  -5  0.3103184 -1.4416677
#> 5      90       1     1     1 -12.00 -12.35  -5  1.3348132 -0.1615000
#> 6     150       1     1     1  -8.90  -6.25  -5  0.1725666  3.9096835
#>          e_3        U_1        U_2       U_3 CHOICE
#> 1  0.4238020  -3.521652 -11.838562 -4.576198      1
#> 2  1.8055939  -5.457289  -3.193183 -3.194406      2
#> 3 -0.2960403  -4.738979  -4.025862 -5.296040      2
#> 4  0.3262861 -12.739682  -6.041668 -4.673714      3
#> 5 -0.2705518 -10.665187 -12.511500 -5.270552      3
#> 6 -1.5870600  -8.727433  -2.340316 -6.587060      2
#> 
#>  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.3410475  1.0663781
#> 2     110       1     1     1  -4.50  -2.85  -5  1.6900014  1.8647184
#> 3     140       1     1     1  -4.90  -3.60  -5  1.0465233  0.3460339
#> 4      80       1     1     1 -13.05  -4.60  -5 -0.6799246 -1.7138636
#> 5      90       1     1     1 -12.00 -12.35  -5 -0.4481841  1.9378475
#> 6     150       1     1     1  -8.90  -6.25  -5  1.3733862  0.7375437
#>          e_3        U_1         U_2       U_3 CHOICE
#> 1  0.2114102  -4.091047 -10.9836219 -4.788590      1
#> 2 -0.4196018  -2.809999  -0.9852816 -5.419602      2
#> 3 -0.3157360  -3.853477  -3.2539661 -5.315736      2
#> 4  1.0692299 -13.729925  -6.3138636 -3.930770      3
#> 5  1.3412840 -12.448184 -10.4121525 -3.658716      3
#> 6  0.3656113  -7.526614  -5.5124563 -4.634389      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: -6756.625 
#> Initial gradient value:
#>          bx1          bx2          bx3          bx4 
#>  -92542.5915    -463.7693    -528.3737 -120657.6065 
#> initial  value 6756.625180 
#> iter   2 value 2773.052615
#> iter   3 value 1042.472243
#> iter   4 value 1041.724405
#> iter   5 value 1022.750697
#> iter   6 value 1022.102480
#> iter   7 value 1011.269492
#> iter   8 value 996.476915
#> iter   9 value 994.589346
#> iter  10 value 994.197087
#> iter  11 value 994.196890
#> iter  12 value 994.196419
#> iter  13 value 994.196362
#> iter  14 value 994.195883
#> iter  15 value 994.195873
#> iter  16 value 994.195638
#> iter  17 value 994.195594
#> iter  17 value 994.195594
#> iter  17 value 994.195594
#> final  value 994.195594 
#> converged
#> Initial function value: -6661.625 
#> Initial gradient value:
#>          bx1          bx2          bx3          bx4 
#>  -91292.5915    -453.7693    -518.3737 -119117.6065 
#> initial  value 6661.625180 
#> iter   2 value 2753.828662
#> iter   3 value 1144.340190
#> iter   4 value 1143.185319
#> iter   5 value 1121.618995
#> iter   6 value 1115.681307
#> iter   7 value 1072.725508
#> iter   8 value 1065.177544
#> iter   9 value 1063.828401
#> iter  10 value 1063.793997
#> iter  11 value 1063.793948
#> iter  11 value 1063.793945
#> iter  12 value 1063.793917
#> iter  12 value 1063.793917
#> iter  13 value 1063.793902
#> iter  13 value 1063.793899
#> iter  14 value 1063.793887
#> iter  14 value 1063.793886
#> iter  14 value 1063.793882
#> final  value 1063.793882 
#> converged
#> 
#> 
#> Summary table:
#> 
#> 
#> =============  ====  ===  =====  ====  ======  =====  =====  =====  ====  ========  ====
#> \              vars    n   mean    sd  median    min    max  range  skew  kurtosis    se
#> =============  ====  ===  =====  ====  ======  =====  =====  =====  ====  ========  ====
#> est_bx1           1    2  -0.10  0.01   -0.10  -0.10  -0.09   0.01     0     -2.75  0.00
#> est_bx2           2    2   0.04  0.02    0.04   0.02   0.05   0.03     0     -2.75  0.02
#> est_bx3           3    2  -0.17  0.00   -0.17  -0.17  -0.16   0.01     0     -2.75  0.00
#> est_bx4           4    2  -0.03  0.00   -0.03  -0.03  -0.03   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.70  0.21    0.70   0.54   0.85   0.30     0     -2.75  0.15
#> rob_pval0_bx3     7    2   0.06  0.02    0.06   0.04   0.08   0.03     0     -2.75  0.02
#> 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: 0x64535a07c870>
#> 
#> $u1$v2
#> V.2 ~ bx1 * alt2.x1 + bx2 * alt2.x2 + bx3 * alt2.x3 + bx4 * alt2.x4
#> <environment: 0x645359f40ac0>
#> 
#> $u1$v3
#> V.3 ~ -5
#> <environment: 0x645359d7d098>
#> 
#>  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.099838554  0.15880011
#> 2      90       1     1     1  -4.85 -2.30  -5  2.532366583 -1.12394155
#> 3      80       1     1     1 -11.05 -7.10  -5 -0.865335081 -0.98131103
#> 4      90       1     1     1  -3.50 -2.40  -5 -0.458208905 -0.20352704
#> 5      80       1     1     1  -3.30 -2.15  -5  0.420976234 -1.18968314
#> 6     110       1     1     1  -2.10 -2.75  -5  0.007028381 -0.08608272
#>           e_3         U_1       U_2       U_3 CHOICE
#> 1  0.09572715  -0.9001614 -2.941200 -4.904273      1
#> 2  1.68952223  -2.3176334 -3.423942 -3.310478      1
#> 3  1.62469324 -11.9153351 -8.081311 -3.375307      3
#> 4 -0.96400436  -3.9582089 -2.603527 -5.964004      2
#> 5  0.11649541  -2.8790238 -3.339683 -4.883505      1
#> 6  0.92257558  -2.0929716 -2.836083 -4.077424      1
#> 
#>  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  0.18768477  0.6182522
#> 2      90       1     1     1  -4.85 -2.30  -5 -0.33070917  0.9394820
#> 3      80       1     1     1 -11.05 -7.10  -5  3.09376692 -0.8518250
#> 4      90       1     1     1  -3.50 -2.40  -5  1.87119573  0.6142236
#> 5      80       1     1     1  -3.30 -2.15  -5 -0.98089710  0.5232656
#> 6     110       1     1     1  -2.10 -2.75  -5  0.07346766  1.0457122
#>           e_3       U_1       U_2       U_3 CHOICE
#> 1  1.34067687 -1.812315 -2.481748 -3.659323      1
#> 2 -0.24989946 -5.180709 -1.360518 -5.249899      2
#> 3  2.09885304 -7.956233 -7.951825 -2.901147      3
#> 4  1.10797049 -1.628804 -1.785776 -3.892030      1
#> 5 -0.03074646 -4.280897 -1.626734 -5.030746      2
#> 6  1.14518851 -2.026532 -1.704288 -3.854811      2
#> 
#> 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: -3326.625 
#> Initial gradient value:
#>          bx1          bx2          bx3          bx4 
#> -27929.12418    -68.97081    -63.17227 -48218.04443 
#> initial  value 3326.625180 
#> iter   2 value 2148.319815
#> iter   3 value 1832.767533
#> iter   4 value 1785.141737
#> iter   5 value 1768.982824
#> iter   6 value 1601.160503
#> iter   7 value 1545.183222
#> iter   8 value 1536.542043
#> iter   9 value 1532.908834
#> iter  10 value 1532.572043
#> iter  11 value 1532.571589
#> iter  12 value 1532.571209
#> iter  13 value 1532.567781
#> iter  14 value 1532.567740
#> iter  15 value 1532.566894
#> iter  16 value 1532.566877
#> iter  16 value 1532.566877
#> iter  16 value 1532.566877
#> final  value 1532.566877 
#> converged
#> Initial function value: -3321.625 
#> Initial gradient value:
#>          bx1          bx2          bx3          bx4 
#> -28129.12418    -68.97081    -56.17227 -47438.04443 
#> initial  value 3321.625180 
#> iter   2 value 2164.015283
#> iter   3 value 1845.797908
#> iter   4 value 1797.993301
#> iter   5 value 1776.921708
#> iter   6 value 1568.761667
#> iter   7 value 1539.965148
#> iter   8 value 1529.815655
#> iter   9 value 1527.562483
#> iter  10 value 1527.353622
#> iter  11 value 1527.353152
#> iter  12 value 1527.353129
#> iter  13 value 1527.350204
#> iter  14 value 1527.349872
#> iter  15 value 1527.349362
#> iter  16 value 1527.349144
#> iter  16 value 1527.349144
#> iter  16 value 1527.349144
#> final  value 1527.349144 
#> converged
#> 
#> 
#> 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.14  0.00   -0.14  -0.14  -0.13   0.00     0     -2.75  0.00
#> est_bx3           3    2   0.01  0.02    0.01   0.00   0.02   0.02     0     -2.75  0.01
#> est_bx4           4    2  -0.02  0.00   -0.02  -0.03  -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.02  0.00    0.02   0.02   0.02   0.00     0     -2.75  0.00
#> rob_pval0_bx3     7    2   0.86  0.19    0.86   0.73   0.99   0.26     0     -2.75  0.13
#> 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: 6.896 sec elapsed
#> $tic
#> elapsed 
#>   0.644 
#> 
#> $toc
#> elapsed 
#>    7.54 
#> 
#> $msg
#> [1] "total time for simulation and estimation"
#> 
#> $callback_msg
#> [1] "total time for simulation and estimation: 6.896 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] "BLIbay"     "BLIeff"     "BLIIbay"    "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.100 -0.0241  0.0308 -0.0248     5.57e-193         0.698
#> 2 2      -0.104 -0.0524 -0.0973 -0.0247     8.67e-218         0.396
#> # ℹ 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.04 0.02  -0.04 -0.05 -0.02  0.03    0    -2.75 0.01
#> est_bx3          3 2 -0.03 0.09  -0.03 -0.10  0.03  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.55 0.21   0.55  0.40  0.70  0.30    0    -2.75 0.15
#> rob_pval0_bx3    7 2  0.36 0.34   0.36  0.12  0.60  0.48    0    -2.75 0.24
#> 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")