SE_Agri-vignette

Introduction

This vignette demonstrates how to use simulate situations in which different utility functions apply to diffferent subsets of respondents. We will use a sample dataset and utility functions to generate simulated data and analyze the results. First off it is good practice remove all objects (variables, functions, etc.) from the current workspace and load all R files in the package directory into the current R session.

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.

The manipulation variable allows the user to assign different terms based on the values of column values in the experimental design file

bcoeff <- list(
  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
ul <- list(
  u1 =
    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
    )
)

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", "SE_AGRI", 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 <- "ngene"

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 random 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 beta coefficients. In general these will be printed to the console, but the entire results can also be assigned to an r list object.

seagri <- simulateDCE::sim_all(
  nosim = nosim, resps = resps, designtype = destype,
  designpath = designpath, u = ul, bcoeff = bcoeff, manipulations = manipulations
)
#> '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 ~ bprof * alt1.professional + bexp * alt1.expert + bdomestic * 
#>     alt1.domestic + bforeign * alt1.foreign + bdamage * alt1.damage + 
#>     bprice * alt1.compensation
#> <environment: 0x5f74de6baf08>
#> 
#> $u1$v2
#> V.2 ~ bprof * alt2.professional + bexp * alt2.expert + bdomestic * 
#>     alt2.domestic + bforeign * alt2.foreign + bdamage * alt2.damage + 
#>     bprice * alt2.compensation
#> <environment: 0x5f74de6f0428>
#> 
#> $u1$v3
#> V.3 ~ basc
#> <environment: 0x5f74de721ac0>
#> New names:
#> • `Choice situation` -> `Choice.situation`
#> • `` -> `...12`
#> assign keys for bcoeff): 0 sec elapsed
#> user entered manipulations: 0.019 sec elapsed
#> split dataframe into groups: 0.004 sec elapsed
#> for each group calculate utility: 2.321 sec elapsed
#> add random component: 0.053 sec elapsed
#> whole simulate choices: 2.398 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_initiator alt1_funding alt1_damage alt1_compensation
#> 1  1                1              2            1           0                 2
#> 2  1               12              2            2           0                30
#> 3  1               20              0            1           1                20
#> 4  1               23              2            2           1                 2
#> 5  1               25              2            0           0                30
#> 6  1               26              1            2           1                20
#>   alt2_initiator alt2_funding alt2_damage alt2_compensation Block group
#> 1              1            0           1                30     1     1
#> 2              0            1           1                10     1     1
#> 3              2            2           0                10     1     1
#> 4              0            0           1                10     1     1
#> 5              0            2           0                20     1     1
#> 6              2            1           0                10     1     1
#>   alt1_professional alt2_professional alt1_expert alt2_expert alt1_domestic
#> 1             FALSE              TRUE        TRUE       FALSE          TRUE
#> 2             FALSE             FALSE        TRUE       FALSE         FALSE
#> 3             FALSE             FALSE       FALSE        TRUE          TRUE
#> 4             FALSE             FALSE        TRUE       FALSE         FALSE
#> 5             FALSE             FALSE        TRUE       FALSE         FALSE
#> 6              TRUE             FALSE       FALSE        TRUE         FALSE
#>   alt2_domestic alt1_foreign alt2_foreign V_1 V_2 V_3        e_1         e_2
#> 1         FALSE        FALSE        FALSE 1.0 6.9 4.2 -1.3431262  2.63622565
#> 2          TRUE         TRUE        FALSE 6.6 2.9 4.2  1.5177036  0.43091129
#> 3         FALSE        FALSE         TRUE 4.9 2.6 4.2  0.2870881 -0.06943918
#> 4         FALSE         TRUE        FALSE 1.6 2.6 4.2  1.5647928  0.58230520
#> 5         FALSE        FALSE         TRUE 6.3 4.3 4.2 -1.2806816  0.54726968
#> 6          TRUE         TRUE        FALSE 5.2 2.6 4.2  0.9839135  3.08688131
#>           e_3        U_1      U_2      U_3 CHOICE
#> 1  0.01658856 -0.3431262 9.536226 4.216589      2
#> 2 -0.98983394  8.1177036 3.330911 3.210166      1
#> 3  1.67247387  5.1870881 2.530561 5.872474      3
#> 4  0.09601975  3.1647928 3.182305 4.296020      3
#> 5 -2.08711740  5.0193184 4.847270 2.112883      1
#> 6 -0.49399837  6.1839135 5.686881 3.706002      1
#> assign keys for bcoeff): 0 sec elapsed
#> user entered manipulations: 0.028 sec elapsed
#> split dataframe into groups: 0.004 sec elapsed
#> for each group calculate utility: 2.277 sec elapsed
#> add random component: 0.054 sec elapsed
#> whole simulate choices: 2.364 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_initiator alt1_funding alt1_damage alt1_compensation
#> 1  1                1              2            1           0                 2
#> 2  1               12              2            2           0                30
#> 3  1               20              0            1           1                20
#> 4  1               23              2            2           1                 2
#> 5  1               25              2            0           0                30
#> 6  1               26              1            2           1                20
#>   alt2_initiator alt2_funding alt2_damage alt2_compensation Block group
#> 1              1            0           1                30     1     1
#> 2              0            1           1                10     1     1
#> 3              2            2           0                10     1     1
#> 4              0            0           1                10     1     1
#> 5              0            2           0                20     1     1
#> 6              2            1           0                10     1     1
#>   alt1_professional alt2_professional alt1_expert alt2_expert alt1_domestic
#> 1             FALSE              TRUE        TRUE       FALSE          TRUE
#> 2             FALSE             FALSE        TRUE       FALSE         FALSE
#> 3             FALSE             FALSE       FALSE        TRUE          TRUE
#> 4             FALSE             FALSE        TRUE       FALSE         FALSE
#> 5             FALSE             FALSE        TRUE       FALSE         FALSE
#> 6              TRUE             FALSE       FALSE        TRUE         FALSE
#>   alt2_domestic alt1_foreign alt2_foreign V_1 V_2 V_3          e_1        e_2
#> 1         FALSE        FALSE        FALSE 1.0 6.9 4.2  3.261831036 -0.5990366
#> 2          TRUE         TRUE        FALSE 6.6 2.9 4.2  0.002154937  0.5962256
#> 3         FALSE        FALSE         TRUE 4.9 2.6 4.2  1.795082315  0.4310999
#> 4         FALSE         TRUE        FALSE 1.6 2.6 4.2 -0.747121351 -1.0736813
#> 5         FALSE        FALSE         TRUE 6.3 4.3 4.2 -0.265176431  0.3375761
#> 6          TRUE         TRUE        FALSE 5.2 2.6 4.2  1.083209887  0.2774360
#>          e_3       U_1      U_2      U_3 CHOICE
#> 1  1.9167622 4.2618310 6.300963 6.116762      2
#> 2  1.2415698 6.6021549 3.496226 5.441570      1
#> 3  0.8683595 6.6950823 3.031100 5.068359      1
#> 4 -1.1185588 0.8528786 1.526319 3.081441      3
#> 5  2.1003382 6.0348236 4.637576 6.300338      3
#> 6  1.4533109 6.2832099 2.877436 5.653311      1
#> 
#> 
#> 
#> Transformed utility function (type: simple):
#> [1] "U_1 = @bprof * $alt1_professional + @bexp * $alt1_expert + @bdomestic * $alt1_domestic + @bforeign * $alt1_foreign + @bdamage * $alt1_damage + @bprice * $alt1_compensation ;U_2 = @bprof * $alt2_professional + @bexp * $alt2_expert + @bdomestic * $alt2_domestic + @bforeign * $alt2_foreign + @bdamage * $alt2_damage + @bprice * $alt2_compensation ;U_3 = @basc ;"
#> Initial function value: -2373.003 
#> Initial gradient value:
#>     bprof      bexp bdomestic  bforeign   bdamage    bprice      basc 
#>       -89       -28       -30        32       171      9404       175 
#> initial  value 2373.002544 
#> iter   2 value 2334.321165
#> iter   3 value 1713.787373
#> iter   4 value 1601.912088
#> iter   5 value 1595.680902
#> iter   6 value 1568.826935
#> iter   7 value 1533.832870
#> iter   8 value 1500.985992
#> iter   9 value 1384.292792
#> iter  10 value 1320.795323
#> iter  11 value 1309.420617
#> iter  12 value 1305.261961
#> iter  13 value 1305.147857
#> iter  14 value 1305.132294
#> iter  15 value 1305.131584
#> iter  16 value 1305.131425
#> iter  16 value 1305.131424
#> final  value 1305.131424 
#> converged
#> Initial function value: -2373.003 
#> Initial gradient value:
#>     bprof      bexp bdomestic  bforeign   bdamage    bprice      basc 
#>      -103       -14         9        63       189     10013       133 
#> initial  value 2373.002544 
#> iter   2 value 2307.950435
#> iter   3 value 1723.358248
#> iter   4 value 1619.082805
#> iter   5 value 1585.677502
#> iter   6 value 1562.232460
#> iter   7 value 1556.684066
#> iter   8 value 1372.428297
#> iter   9 value 1366.854646
#> iter  10 value 1335.700247
#> iter  11 value 1326.819324
#> iter  12 value 1323.852293
#> iter  13 value 1323.776761
#> iter  14 value 1323.774355
#> iter  15 value 1323.773810
#> iter  15 value 1323.773805
#> iter  15 value 1323.773805
#> final  value 1323.773805 
#> converged
#> start_estimation: 0.348 sec elapsed
#> 
#> Summary table:
#> 
#> 
#> ===================  ====  ===  ====  ====  ======  ====  ====  =====  ====  ========  ====
#> \                    vars    n  mean    sd  median   min   max  range  skew  kurtosis    se
#> ===================  ====  ===  ====  ====  ======  ====  ====  =====  ====  ========  ====
#> est_bprof               1    2  0.37  0.24    0.37  0.20  0.54   0.34     0     -2.75  0.17
#> est_bexp                2    2  0.35  0.11    0.35  0.27  0.42   0.15     0     -2.75  0.08
#> est_bdomestic           3    2  0.52  0.32    0.52  0.30  0.74   0.45     0     -2.75  0.22
#> est_bforeign            4    2  0.45  0.25    0.45  0.27  0.63   0.35     0     -2.75  0.18
#> est_bdamage             5    2  0.68  0.02    0.68  0.66  0.69   0.03     0     -2.75  0.01
#> est_bprice              6    2  0.20  0.00    0.20  0.20  0.20   0.01     0     -2.75  0.00
#> est_basc                7    2  4.46  0.09    4.46  4.40  4.52   0.12     0     -2.75  0.06
#> rob_pval0_bprof         8    2  0.03  0.05    0.03  0.00  0.07   0.07     0     -2.75  0.03
#> rob_pval0_bexp          9    2  0.01  0.01    0.01  0.00  0.02   0.02     0     -2.75  0.01
#> rob_pval0_bdomestic    10    2  0.00  0.01    0.00  0.00  0.01   0.01     0     -2.75  0.00
#> rob_pval0_bforeign     11    2  0.01  0.01    0.01  0.00  0.02   0.02     0     -2.75  0.01
#> rob_pval0_bdamage      12    2  0.00  0.00    0.00  0.00  0.00   0.00     0     -2.75  0.00
#> rob_pval0_bprice       13    2  0.00  0.00    0.00  0.00  0.00   0.00   NaN       NaN  0.00
#> rob_pval0_basc         14    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 ~ bprof * alt1.professional + bexp * alt1.expert + bdomestic * 
#>     alt1.domestic + bforeign * alt1.foreign + bdamage * alt1.damage + 
#>     bprice * alt1.compensation
#> <environment: 0x5f74de9133f8>
#> 
#> $u1$v2
#> V.2 ~ bprof * alt2.professional + bexp * alt2.expert + bdomestic * 
#>     alt2.domestic + bforeign * alt2.foreign + bdamage * alt2.damage + 
#>     bprice * alt2.compensation
#> <environment: 0x5f74de774278>
#> 
#> $u1$v3
#> V.3 ~ basc
#> <environment: 0x5f74de6cbf80>
#> 
#> 
#> New names:
#> assign keys for bcoeff): 0 sec elapsed
#> user entered manipulations: 0.021 sec elapsed
#> split dataframe into groups: 0.004 sec elapsed
#> for each group calculate utility: 2.347 sec elapsed
#> add random component: 0.045 sec elapsed
#> whole simulate choices: 2.419 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_initiator alt1_funding alt1_damage alt1_compensation
#> 1  1                6              1            0           1                 2
#> 2  1                8              0            1           1                 5
#> 3  1                9              2            1           0                15
#> 4  1               13              2            2           1                 2
#> 5  1               25              1            2           0                15
#> 6  1               28              0            1           0                15
#>   alt2_initiator alt2_funding alt2_damage alt2_compensation Block group
#> 1              2            2           0                 2     1     1
#> 2              1            2           0                 5     1     1
#> 3              1            2           1                15     1     1
#> 4              1            0           0                 5     1     1
#> 5              0            0           1                15     1     1
#> 6              2            0           1                15     1     1
#>   alt1_professional alt2_professional alt1_expert alt2_expert alt1_domestic
#> 1              TRUE             FALSE       FALSE        TRUE         FALSE
#> 2             FALSE              TRUE       FALSE       FALSE          TRUE
#> 3             FALSE              TRUE        TRUE       FALSE          TRUE
#> 4             FALSE              TRUE        TRUE       FALSE         FALSE
#> 5              TRUE             FALSE       FALSE       FALSE         FALSE
#> 6             FALSE             FALSE       FALSE        TRUE          TRUE
#>   alt2_domestic alt1_foreign alt2_foreign V_1 V_2 V_3        e_1         e_2
#> 1         FALSE        FALSE         TRUE 1.3 1.0 4.2  0.2283479  2.28650158
#> 2         FALSE        FALSE         TRUE 1.9 1.6 4.2 -0.9572889  0.68756630
#> 3         FALSE        FALSE         TRUE 3.6 4.2 4.2  0.1610206  1.26127583
#> 4         FALSE         TRUE        FALSE 1.6 1.3 4.2  0.3103184  1.65458741
#> 5         FALSE         TRUE        FALSE 3.6 3.6 4.2  1.3348132 -0.02035208
#> 6         FALSE        FALSE        FALSE 3.3 3.9 4.2  0.1725666  3.00758115
#>           e_3       U_1      U_2      U_3 CHOICE
#> 1  0.01814608 1.5283479 3.286502 4.218146      3
#> 2  1.71728688 0.9427111 2.287566 5.917287      3
#> 3  2.93101929 3.7610206 5.461276 7.131019      3
#> 4 -0.09398200 1.9103184 2.954587 4.106018      3
#> 5  0.84045996 4.9348132 3.579648 5.040460      3
#> 6  0.95409867 3.4725666 6.907581 5.154099      2
#> assign keys for bcoeff): 0 sec elapsed
#> user entered manipulations: 0.032 sec elapsed
#> split dataframe into groups: 0.003 sec elapsed
#> for each group calculate utility: 2.256 sec elapsed
#> add random component: 0.042 sec elapsed
#> whole simulate choices: 2.334 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_initiator alt1_funding alt1_damage alt1_compensation
#> 1  1                6              1            0           1                 2
#> 2  1                8              0            1           1                 5
#> 3  1                9              2            1           0                15
#> 4  1               13              2            2           1                 2
#> 5  1               25              1            2           0                15
#> 6  1               28              0            1           0                15
#>   alt2_initiator alt2_funding alt2_damage alt2_compensation Block group
#> 1              2            2           0                 2     1     1
#> 2              1            2           0                 5     1     1
#> 3              1            2           1                15     1     1
#> 4              1            0           0                 5     1     1
#> 5              0            0           1                15     1     1
#> 6              2            0           1                15     1     1
#>   alt1_professional alt2_professional alt1_expert alt2_expert alt1_domestic
#> 1              TRUE             FALSE       FALSE        TRUE         FALSE
#> 2             FALSE              TRUE       FALSE       FALSE          TRUE
#> 3             FALSE              TRUE        TRUE       FALSE          TRUE
#> 4             FALSE              TRUE        TRUE       FALSE         FALSE
#> 5              TRUE             FALSE       FALSE       FALSE         FALSE
#> 6             FALSE             FALSE       FALSE        TRUE          TRUE
#>   alt2_domestic alt1_foreign alt2_foreign V_1 V_2 V_3        e_1         e_2
#> 1         FALSE        FALSE         TRUE 1.3 1.0 4.2 -0.3410475 -0.23105142
#> 2         FALSE        FALSE         TRUE 1.9 1.6 4.2  1.6900014 -0.29490327
#> 3         FALSE        FALSE         TRUE 3.6 4.2 4.2  1.0465233  1.04675908
#> 4         FALSE         TRUE        FALSE 1.6 1.3 4.2 -0.6799246  0.35365800
#> 5         FALSE         TRUE        FALSE 3.6 3.6 4.2 -0.4481841 -0.51702784
#> 6         FALSE        FALSE        FALSE 3.3 3.9 4.2  1.3733862 -0.04140872
#>          e_3       U_1       U_2      U_3 CHOICE
#> 1  0.8742507 0.9589525 0.7689486 5.074251      3
#> 2  0.3086977 3.5900014 1.3050967 4.508698      3
#> 3  0.3649179 4.6465233 5.2467591 4.564918      2
#> 4  1.3958206 0.9200754 1.6536580 5.595821      3
#> 5 -0.5476639 3.1518159 3.0829722 3.652336      3
#> 6  0.1657436 4.6733862 3.8585913 4.365744      1
#> 
#> 
#> 
#> Transformed utility function (type: simple):
#> [1] "U_1 = @bprof * $alt1_professional + @bexp * $alt1_expert + @bdomestic * $alt1_domestic + @bforeign * $alt1_foreign + @bdamage * $alt1_damage + @bprice * $alt1_compensation ;U_2 = @bprof * $alt2_professional + @bexp * $alt2_expert + @bdomestic * $alt2_domestic + @bforeign * $alt2_foreign + @bdamage * $alt2_damage + @bprice * $alt2_compensation ;U_3 = @basc ;"
#> Initial function value: -2373.003 
#> Initial gradient value:
#>     bprof      bexp bdomestic  bforeign   bdamage    bprice      basc 
#>       -89      -136      -140      -133      -124       531       433 
#> initial  value 2373.002544 
#> iter   2 value 2368.658191
#> iter   3 value 1896.570468
#> iter   4 value 1746.334961
#> iter   5 value 1670.190976
#> iter   6 value 1662.377524
#> iter   7 value 1660.943655
#> iter   8 value 1641.781495
#> iter   9 value 1637.186945
#> iter  10 value 1633.387568
#> iter  11 value 1632.743983
#> iter  12 value 1632.676212
#> iter  13 value 1632.675388
#> iter  14 value 1632.675337
#> iter  14 value 1632.675335
#> iter  14 value 1632.675335
#> final  value 1632.675335 
#> converged
#> Initial function value: -2373.003 
#> Initial gradient value:
#>     bprof      bexp bdomestic  bforeign   bdamage    bprice      basc 
#>       -88      -141      -171      -134      -116       308       441 
#> initial  value 2373.002544 
#> iter   2 value 2368.601542
#> iter   3 value 2316.859773
#> iter   4 value 2113.238839
#> iter   5 value 1993.144440
#> iter   6 value 1953.749768
#> iter   7 value 1946.648896
#> iter   8 value 1890.163184
#> iter   9 value 1709.980051
#> iter  10 value 1666.741989
#> iter  11 value 1649.316459
#> iter  12 value 1647.434934
#> iter  13 value 1646.944177
#> iter  14 value 1646.800274
#> iter  15 value 1646.796787
#> iter  16 value 1646.796695
#> iter  16 value 1646.796694
#> final  value 1646.796694 
#> converged
#> start_estimation: 0.268 sec elapsed
#> 
#> Summary table:
#> 
#> 
#> ===================  ====  ===  ====  ====  ======  ====  ====  =====  ====  ========  ====
#> \                    vars    n  mean    sd  median   min   max  range  skew  kurtosis    se
#> ===================  ====  ===  ====  ====  ======  ====  ====  =====  ====  ========  ====
#> est_bprof               1    2  0.39  0.00    0.39  0.39  0.39   0.00     0     -2.75  0.00
#> est_bexp                2    2  0.33  0.01    0.33  0.32  0.34   0.02     0     -2.75  0.01
#> est_bdomestic           3    2  0.22  0.16    0.22  0.11  0.34   0.23     0     -2.75  0.12
#> est_bforeign            4    2  0.31  0.07    0.31  0.26  0.37   0.10     0     -2.75  0.05
#> est_bdamage             5    2  0.55  0.03    0.55  0.52  0.57   0.05     0     -2.75  0.02
#> est_bprice              6    2  0.20  0.01    0.20  0.19  0.20   0.01     0     -2.75  0.00
#> est_basc                7    2  4.20  0.13    4.20  4.11  4.29   0.18     0     -2.75  0.09
#> rob_pval0_bprof         8    2  0.00  0.00    0.00  0.00  0.00   0.00     0     -2.75  0.00
#> rob_pval0_bexp          9    2  0.00  0.00    0.00  0.00  0.00   0.00     0     -2.75  0.00
#> rob_pval0_bdomestic    10    2  0.10  0.14    0.10  0.00  0.20   0.20     0     -2.75  0.10
#> rob_pval0_bforeign     11    2  0.00  0.00    0.00  0.00  0.00   0.00     0     -2.75  0.00
#> rob_pval0_bdamage      12    2  0.00  0.00    0.00  0.00  0.00   0.00     0     -2.75  0.00
#> rob_pval0_bprice       13    2  0.00  0.00    0.00  0.00  0.00   0.00   NaN       NaN  0.00
#> rob_pval0_basc         14    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 ~ bprof * alt1.professional + bexp * alt1.expert + bdomestic * 
#>     alt1.domestic + bforeign * alt1.foreign + bdamage * alt1.damage + 
#>     bprice * alt1.compensation
#> <environment: 0x5f74df014cc8>
#> 
#> $u1$v2
#> V.2 ~ bprof * alt2.professional + bexp * alt2.expert + bdomestic * 
#>     alt2.domestic + bforeign * alt2.foreign + bdamage * alt2.damage + 
#>     bprice * alt2.compensation
#> <environment: 0x5f74defe1118>
#> 
#> $u1$v3
#> V.3 ~ basc
#> <environment: 0x5f74def9eed8>
#> 
#> 
#> New names:
#> assign keys for bcoeff): 0 sec elapsed
#> user entered manipulations: 0.021 sec elapsed
#> split dataframe into groups: 0.004 sec elapsed
#> for each group calculate utility: 2.35 sec elapsed
#> add random component: 0.043 sec elapsed
#> whole simulate choices: 2.419 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_initiator alt1_funding alt1_damage alt1_compensation
#> 1  1                4              2            1           1                15
#> 2  1                5              2            2           1                10
#> 3  1               10              2            2           1                15
#> 4  1               13              0            2           0                30
#> 5  1               14              2            2           0                 2
#> 6  1               15              1            0           1                 2
#>   alt2_initiator alt2_funding alt2_damage alt2_compensation Block group
#> 1              1            2           0                15     1     1
#> 2              0            1           0                10     1     1
#> 3              1            0           0                15     1     1
#> 4              1            0           1                30     1     1
#> 5              1            0           1                 5     1     1
#> 6              0            1           0                 2     1     1
#>   alt1_professional alt2_professional alt1_expert alt2_expert alt1_domestic
#> 1             FALSE              TRUE        TRUE       FALSE          TRUE
#> 2             FALSE             FALSE        TRUE       FALSE         FALSE
#> 3             FALSE              TRUE        TRUE       FALSE         FALSE
#> 4             FALSE              TRUE       FALSE       FALSE         FALSE
#> 5             FALSE              TRUE        TRUE       FALSE         FALSE
#> 6              TRUE             FALSE       FALSE       FALSE         FALSE
#>   alt2_domestic alt1_foreign alt2_foreign V_1 V_2 V_3          e_1         e_2
#> 1         FALSE        FALSE         TRUE 4.2 3.6 4.2  1.099838554  1.65516593
#> 2          TRUE         TRUE        FALSE 3.2 2.3 4.2  2.532366583 -0.45522161
#> 3         FALSE         TRUE        FALSE 4.2 3.3 4.2 -0.865335081 -0.09076180
#> 4         FALSE         TRUE        FALSE 6.3 6.9 4.2 -0.458208905  0.03336685
#> 5         FALSE         TRUE        FALSE 1.0 1.9 4.2  0.420976234  0.24476851
#> 6          TRUE        FALSE        FALSE 1.3 0.7 4.2  0.007028381 -0.31923689
#>          e_3      U_1       U_2      U_3 CHOICE
#> 1  2.3599458 5.299839 5.2551659 6.559946      3
#> 2  0.3645423 5.732367 1.8447784 4.564542      1
#> 3  0.6176394 3.334665 3.2092382 4.817639      3
#> 4 -1.4446060 5.841791 6.9333668 2.755394      2
#> 5  0.4793832 1.420976 2.1447685 4.679383      3
#> 6 -0.7543455 1.307028 0.3807631 3.445655      3
#> assign keys for bcoeff): 0 sec elapsed
#> user entered manipulations: 0.035 sec elapsed
#> split dataframe into groups: 0.004 sec elapsed
#> for each group calculate utility: 2.259 sec elapsed
#> add random component: 0.038 sec elapsed
#> whole simulate choices: 2.336 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_initiator alt1_funding alt1_damage alt1_compensation
#> 1  1                4              2            1           1                15
#> 2  1                5              2            2           1                10
#> 3  1               10              2            2           1                15
#> 4  1               13              0            2           0                30
#> 5  1               14              2            2           0                 2
#> 6  1               15              1            0           1                 2
#>   alt2_initiator alt2_funding alt2_damage alt2_compensation Block group
#> 1              1            2           0                15     1     1
#> 2              0            1           0                10     1     1
#> 3              1            0           0                15     1     1
#> 4              1            0           1                30     1     1
#> 5              1            0           1                 5     1     1
#> 6              0            1           0                 2     1     1
#>   alt1_professional alt2_professional alt1_expert alt2_expert alt1_domestic
#> 1             FALSE              TRUE        TRUE       FALSE          TRUE
#> 2             FALSE             FALSE        TRUE       FALSE         FALSE
#> 3             FALSE              TRUE        TRUE       FALSE         FALSE
#> 4             FALSE              TRUE       FALSE       FALSE         FALSE
#> 5             FALSE              TRUE        TRUE       FALSE         FALSE
#> 6              TRUE             FALSE       FALSE       FALSE         FALSE
#>   alt2_domestic alt1_foreign alt2_foreign V_1 V_2 V_3         e_1        e_2
#> 1         FALSE        FALSE         TRUE 4.2 3.6 4.2  0.18768477  0.4588249
#> 2          TRUE         TRUE        FALSE 3.2 2.3 4.2 -0.33070917 -0.1240796
#> 3         FALSE         TRUE        FALSE 4.2 3.3 4.2  3.09376692  0.9105486
#> 4         FALSE         TRUE        FALSE 6.3 6.9 4.2  1.87119573 -0.1629678
#> 5         FALSE         TRUE        FALSE 1.0 1.9 4.2 -0.98089710 -0.2788252
#> 6          TRUE        FALSE        FALSE 1.3 0.7 4.2  0.07346766  3.7600494
#>            e_3       U_1      U_2      U_3 CHOICE
#> 1 -0.198025826 4.3876848 4.058825 4.001974      1
#> 2  0.001823033 2.8692908 2.175920 4.201823      3
#> 3  0.543891110 7.2937669 4.210549 4.743891      1
#> 4 -0.695615761 8.1711957 6.737032 3.504384      1
#> 5  0.250409343 0.0191029 1.621175 4.450409      3
#> 6 -0.550718725 1.3734677 4.460049 3.649281      2
#> 
#> 
#> 
#> Transformed utility function (type: simple):
#> [1] "U_1 = @bprof * $alt1_professional + @bexp * $alt1_expert + @bdomestic * $alt1_domestic + @bforeign * $alt1_foreign + @bdamage * $alt1_damage + @bprice * $alt1_compensation ;U_2 = @bprof * $alt2_professional + @bexp * $alt2_expert + @bdomestic * $alt2_domestic + @bforeign * $alt2_foreign + @bdamage * $alt2_damage + @bprice * $alt2_compensation ;U_3 = @basc ;"
#> Initial function value: -2373.003 
#> Initial gradient value:
#>     bprof      bexp bdomestic  bforeign   bdamage    bprice      basc 
#>       -56       -84      -169      -143      -192      2460       369 
#> initial  value 2373.002544 
#> iter   2 value 2358.147830
#> iter   3 value 1941.507343
#> iter   4 value 1770.350816
#> iter   5 value 1690.220053
#> iter   6 value 1689.200729
#> iter   7 value 1683.035142
#> iter   8 value 1614.557655
#> iter   9 value 1614.516741
#> iter  10 value 1589.552101
#> iter  11 value 1588.545445
#> iter  12 value 1588.314836
#> iter  13 value 1588.294244
#> iter  14 value 1588.293821
#> iter  14 value 1588.293814
#> iter  14 value 1588.293814
#> final  value 1588.293814 
#> converged
#> Initial function value: -2373.003 
#> Initial gradient value:
#>     bprof      bexp bdomestic  bforeign   bdamage    bprice      basc 
#>       -41       -68      -145      -136      -172      2626       324 
#> initial  value 2373.002544 
#> iter   2 value 2357.017387
#> iter   3 value 2007.129201
#> iter   4 value 1860.769729
#> iter   5 value 1789.564116
#> iter   6 value 1789.025827
#> iter   7 value 1788.416074
#> iter   8 value 1777.343683
#> iter   9 value 1739.014997
#> iter  10 value 1712.293866
#> iter  11 value 1711.325024
#> iter  12 value 1711.163059
#> iter  13 value 1711.156368
#> iter  14 value 1711.155875
#> iter  14 value 1711.155861
#> iter  14 value 1711.155861
#> final  value 1711.155861 
#> converged
#> start_estimation: 0.251 sec elapsed
#> 
#> Summary table:
#> 
#> 
#> ===================  ====  ===  ====  ====  ======  ====  ====  =====  ====  ========  ====
#> \                    vars    n  mean    sd  median   min   max  range  skew  kurtosis    se
#> ===================  ====  ===  ====  ====  ======  ====  ====  =====  ====  ========  ====
#> est_bprof               1    2  0.33  0.00    0.33  0.33  0.33   0.00     0     -2.75  0.00
#> est_bexp                2    2  0.29  0.01    0.29  0.28  0.29   0.01     0     -2.75  0.00
#> est_bdomestic           3    2  0.24  0.01    0.24  0.23  0.25   0.02     0     -2.75  0.01
#> est_bforeign            4    2  0.23  0.06    0.23  0.18  0.27   0.09     0     -2.75  0.04
#> est_bdamage             5    2  0.60  0.05    0.60  0.56  0.63   0.08     0     -2.75  0.04
#> est_bprice              6    2  0.20  0.02    0.20  0.19  0.22   0.03     0     -2.75  0.01
#> est_basc                7    2  4.12  0.41    4.12  3.83  4.42   0.58     0     -2.75  0.29
#> rob_pval0_bprof         8    2  0.00  0.00    0.00  0.00  0.00   0.00     0     -2.75  0.00
#> rob_pval0_bexp          9    2  0.00  0.00    0.00  0.00  0.00   0.00     0     -2.75  0.00
#> rob_pval0_bdomestic    10    2  0.01  0.00    0.01  0.00  0.01   0.01     0     -2.75  0.00
#> rob_pval0_bforeign     11    2  0.02  0.02    0.02  0.00  0.04   0.03     0     -2.75  0.02
#> rob_pval0_bdamage      12    2  0.00  0.00    0.00  0.00  0.00   0.00     0     -2.75  0.00
#> rob_pval0_bprice       13    2  0.00  0.00    0.00  0.00  0.00   0.00   NaN       NaN  0.00
#> rob_pval0_basc         14    2  0.00  0.00    0.00  0.00  0.00   0.00   NaN       NaN  0.00
#> ===================  ====  ===  ====  ====  ======  ====  ====  =====  ====  ========  ====
#> 
#> Power results:
#> 
#> TRUE 
#>  100
#> total time for simulation and estimation: 20.193 sec elapsed
#> $tic
#> elapsed 
#>   0.923 
#> 
#> $toc
#> elapsed 
#>  21.116 
#> 
#> $msg
#> [1] "total time for simulation and estimation"
#> 
#> $callback_msg
#> [1] "total time for simulation and estimation: 20.193 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 located within {result}->{design}->coefs. and a summary table, which displays statistics of these b coefficients across all simulations is contained in {results}->{design}->summary. You can access these by either searching for a known design name or by browsing design names contained in the output list.

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

designs <- names(seagri[sapply(seagri, is.list)])

print(designs)
#> [1] "bayeff3newpriorsdummy" "bayeffnewpriors1"      "bayrevisednewpriors1" 
#> [4] "time"                  "arguements"            "summaryall"           
#> [7] "graphs"                "powa"

simulationCoeff <- seagri[[1]]$coefs
coeffSummary <- seagri[[1]]$summary

print(simulationCoeff)
#> # A tibble: 2 × 15
#>   run   est_bprof est_bexp est_bdomestic est_bforeign est_bdamage est_bprice
#>   <chr>     <dbl>    <dbl>         <dbl>        <dbl>       <dbl>      <dbl>
#> 1 1         0.541    0.422         0.297        0.274       0.693      0.204
#> 2 2         0.200    0.271         0.743        0.629       0.664      0.198
#> # ℹ 8 more variables: est_basc <dbl>, rob_pval0_bprof <dbl>,
#> #   rob_pval0_bexp <dbl>, rob_pval0_bdomestic <dbl>, rob_pval0_bforeign <dbl>,
#> #   rob_pval0_bdamage <dbl>, rob_pval0_bprice <dbl>, rob_pval0_basc <dbl>
print(coeffSummary)
#>                     vars n mean   sd median  min  max range skew kurtosis   se
#> est_bprof              1 2 0.37 0.24   0.37 0.20 0.54  0.34    0    -2.75 0.17
#> est_bexp               2 2 0.35 0.11   0.35 0.27 0.42  0.15    0    -2.75 0.08
#> est_bdomestic          3 2 0.52 0.32   0.52 0.30 0.74  0.45    0    -2.75 0.22
#> est_bforeign           4 2 0.45 0.25   0.45 0.27 0.63  0.35    0    -2.75 0.18
#> est_bdamage            5 2 0.68 0.02   0.68 0.66 0.69  0.03    0    -2.75 0.01
#> est_bprice             6 2 0.20 0.00   0.20 0.20 0.20  0.01    0    -2.75 0.00
#> est_basc               7 2 4.46 0.09   4.46 4.40 4.52  0.12    0    -2.75 0.06
#> rob_pval0_bprof        8 2 0.03 0.05   0.03 0.00 0.07  0.07    0    -2.75 0.03
#> rob_pval0_bexp         9 2 0.01 0.01   0.01 0.00 0.02  0.02    0    -2.75 0.01
#> rob_pval0_bdomestic   10 2 0.00 0.01   0.00 0.00 0.01  0.01    0    -2.75 0.00
#> rob_pval0_bforeign    11 2 0.01 0.01   0.01 0.00 0.02  0.02    0    -2.75 0.01
#> rob_pval0_bdamage     12 2 0.00 0.00   0.00 0.00 0.00  0.00    0    -2.75 0.00
#> rob_pval0_bprice      13 2 0.00 0.00   0.00 0.00 0.00  0.00  NaN      NaN 0.00
#> rob_pval0_basc        14 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")