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)

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: 0x5588aea7c310>
#> 
#> $u1$v2
#> V.2 ~ bprof * alt2.professional + bexp * alt2.expert + bdomestic * 
#>     alt2.domestic + bforeign * alt2.foreign + bdamage * alt2.damage + 
#>     bprice * alt2.compensation
#> <environment: 0x5588aeab9e10>
#> 
#> $u1$v3
#> V.3 ~ basc
#> <environment: 0x5588aeaf0bd0>
#> New names:
#> 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 -1.3431262 2.63622565 2 FALSE FALSE TRUE 1.9
#> 1.6 4.2 1.5177036 0.43091129 3 FALSE FALSE TRUE 3.6 4.2 4.2 0.2870881
#> -0.06943918 4 FALSE TRUE FALSE 1.6 1.3 4.2 1.5647928 0.58230520 5 FALSE TRUE
#> FALSE 3.6 3.6 4.2 -1.2806816 0.54726968 6 FALSE FALSE FALSE 3.3 3.9 4.2
#> 0.9839135 3.08688131 e_3 U_1 U_2 U_3 CHOICE 1 0.01658856 -0.04312623 3.636226
#> 4.216589 3 2 -0.98983394 3.41770356 2.030911 3.210166 1 3 1.67247387 3.88708806
#> 4.130561 5.872474 3 4 0.09601975 3.16479283 1.882305 4.296020 3 5 -2.08711740
#> 2.31931835 4.147270 2.112883 2 6 -0.49399837 4.28391348 6.986881 3.706002 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_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 3.261831036 -0.5990366 2 FALSE FALSE TRUE
#> 1.9 1.6 4.2 0.002154937 0.5962256 3 FALSE FALSE TRUE 3.6 4.2 4.2 1.795082315
#> 0.4310999 4 FALSE TRUE FALSE 1.6 1.3 4.2 -0.747121351 -1.0736813 5 FALSE TRUE
#> FALSE 3.6 3.6 4.2 -0.265176431 0.3375761 6 FALSE FALSE FALSE 3.3 3.9 4.2
#> 1.083209887 0.2774360 e_3 U_1 U_2 U_3 CHOICE 1 1.9167622 4.5618310 0.4009634
#> 6.116762 3 2 1.2415698 1.9021549 2.1962256 5.441570 3 3 0.8683595 5.3950823
#> 4.6310999 5.068359 1 4 -1.1185588 0.8528786 0.2263187 3.081441 3 5 2.1003382
#> 3.3348236 3.9375761 6.300338 3 6 1.4533109 4.3832099 4.1774360 5.653311 3
#> 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 ;"
#> • `Choice situation` -> `Choice.situation`
#> • `` -> `...12`
#> Initial function value: -2373.003 
#> Initial gradient value:
#>     bprof      bexp bdomestic  bforeign   bdamage    bprice      basc 
#>       -71      -136      -117      -129       -88       976       405 
#> initial  value 2373.002544 
#> iter   2 value 2367.379602
#> iter   3 value 1964.645050
#> iter   4 value 1835.404658
#> iter   5 value 1742.192109
#> iter   6 value 1741.734913
#> iter   7 value 1711.964813
#> iter   8 value 1680.199286
#> iter   9 value 1650.610306
#> iter  10 value 1627.971338
#> iter  11 value 1625.622402
#> iter  12 value 1625.224770
#> iter  13 value 1625.204590
#> iter  14 value 1625.203035
#> iter  15 value 1625.202940
#> iter  15 value 1625.202937
#> iter  15 value 1625.202937
#> final  value 1625.202937 
#> converged
#> Initial function value: -2373.003 
#> Initial gradient value:
#>     bprof      bexp bdomestic  bforeign   bdamage    bprice      basc 
#>       -99      -140      -121      -153       -73       855       401 
#> initial  value 2373.002544 
#> iter   2 value 2367.878241
#> iter   3 value 1948.123268
#> iter   4 value 1856.230890
#> iter   5 value 1784.911121
#> iter   6 value 1783.162573
#> iter   7 value 1748.742585
#> iter   8 value 1716.488849
#> iter   9 value 1714.450080
#> iter  10 value 1674.991878
#> iter  11 value 1674.216624
#> iter  12 value 1673.949505
#> iter  13 value 1673.947172
#> iter  14 value 1673.947128
#> iter  14 value 1673.947127
#> iter  14 value 1673.947127
#> final  value 1673.947127 
#> converged
#> 
#> 
#> Summary table:
#> 
#> 
#> ===================  ====  ===  ====  ====  ======  ====  ====  =====  ====  ========  ====
#> \                    vars    n  mean    sd  median   min   max  range  skew  kurtosis    se
#> ===================  ====  ===  ====  ====  ======  ====  ====  =====  ====  ========  ====
#> est_bprof               1    2  0.30  0.18    0.30  0.17  0.42   0.25     0     -2.75  0.12
#> est_bexp                2    2  0.21  0.12    0.21  0.12  0.29   0.17     0     -2.75  0.09
#> est_bdomestic           3    2  0.35  0.13    0.35  0.25  0.44   0.18     0     -2.75  0.09
#> est_bforeign            4    2  0.28  0.17    0.28  0.16  0.40   0.25     0     -2.75  0.12
#> est_bdamage             5    2  0.62  0.01    0.62  0.62  0.63   0.02     0     -2.75  0.01
#> est_bprice              6    2  0.20  0.01    0.20  0.19  0.21   0.01     0     -2.75  0.01
#> est_basc                7    2  4.16  0.34    4.16  3.92  4.40   0.47     0     -2.75  0.24
#> rob_pval0_bprof         8    2  0.02  0.03    0.02  0.00  0.04   0.04     0     -2.75  0.02
#> rob_pval0_bexp          9    2  0.08  0.12    0.08  0.00  0.17   0.16     0     -2.75  0.08
#> rob_pval0_bdomestic    10    2  0.00  0.00    0.00  0.00  0.00   0.00     0     -2.75  0.00
#> rob_pval0_bforeign     11    2  0.04  0.06    0.04  0.00  0.09   0.09     0     -2.75  0.04
#> 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: 0x5588b8b7ad50>
#> 
#> $u1$v2
#> V.2 ~ bprof * alt2.professional + bexp * alt2.expert + bdomestic * 
#>     alt2.domestic + bforeign * alt2.foreign + bdamage * alt2.damage + 
#>     bprice * alt2.compensation
#> <environment: 0x5588b8b41d80>
#> 
#> $u1$v3
#> V.3 ~ basc
#> <environment: 0x5588b8b09028>
#> 
#> 
#> New names:
#>  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  0.2283479  2.28650158
#> 2          TRUE         TRUE        FALSE 6.6 2.9 4.2 -0.9572889  0.68756630
#> 3         FALSE        FALSE         TRUE 4.9 2.6 4.2  0.1610206  1.26127583
#> 4         FALSE         TRUE        FALSE 1.6 2.6 4.2  0.3103184  1.65458741
#> 5         FALSE        FALSE         TRUE 6.3 4.3 4.2  1.3348132 -0.02035208
#> 6          TRUE         TRUE        FALSE 5.2 2.6 4.2  0.1725666  3.00758115
#>           e_3      U_1      U_2      U_3 CHOICE
#> 1  0.01814608 1.228348 9.186502 4.218146      2
#> 2  1.71728688 5.642711 3.587566 5.917287      3
#> 3  2.93101929 5.061021 3.861276 7.131019      3
#> 4 -0.09398200 1.910318 4.254587 4.106018      2
#> 5  0.84045996 7.634813 4.279648 5.040460      1
#> 6  0.95409867 5.372567 5.607581 5.154099      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_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 -0.3410475 -0.23105142
#> 2          TRUE         TRUE        FALSE 6.6 2.9 4.2  1.6900014 -0.29490327
#> 3         FALSE        FALSE         TRUE 4.9 2.6 4.2  1.0465233  1.04675908
#> 4         FALSE         TRUE        FALSE 1.6 2.6 4.2 -0.6799246  0.35365800
#> 5         FALSE        FALSE         TRUE 6.3 4.3 4.2 -0.4481841 -0.51702784
#> 6          TRUE         TRUE        FALSE 5.2 2.6 4.2  1.3733862 -0.04140872
#>          e_3       U_1      U_2      U_3 CHOICE
#> 1  0.8742507 0.6589525 6.668949 5.074251      2
#> 2  0.3086977 8.2900014 2.605097 4.508698      1
#> 3  0.3649179 5.9465233 3.646759 4.564918      1
#> 4  1.3958206 0.9200754 2.953658 5.595821      3
#> 5 -0.5476639 5.8518159 3.782972 3.652336      1
#> 6  0.1657436 6.5733862 2.558591 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 
#> -119.000000   -5.999999  -32.999999   57.000000  183.000001 9763.000000 
#>        basc 
#>  155.000001 
#> initial  value 2373.002544 
#> iter   2 value 2319.313011
#> iter   3 value 1692.211150
#> iter   4 value 1588.982590
#> iter   5 value 1562.931840
#> iter   6 value 1538.682344
#> iter   7 value 1523.349994
#> iter   8 value 1434.571809
#> iter   9 value 1342.247691
#> iter  10 value 1316.292968
#> iter  11 value 1308.797776
#> iter  12 value 1307.131698
#> iter  13 value 1307.030565
#> iter  14 value 1307.009247
#> iter  15 value 1307.007733
#> iter  16 value 1307.007675
#> iter  16 value 1307.007675
#> final  value 1307.007675 
#> converged
#> Initial function value: -2373.003 
#> Initial gradient value:
#>     bprof      bexp bdomestic  bforeign   bdamage    bprice      basc 
#>      -111       -21       -12        32       163      9254       169 
#> initial  value 2373.002544 
#> iter   2 value 2340.169861
#> iter   3 value 1777.102289
#> iter   4 value 1675.618160
#> iter   5 value 1647.440889
#> iter   6 value 1625.245579
#> iter   7 value 1617.690498
#> iter   8 value 1553.900970
#> iter   9 value 1458.371264
#> iter  10 value 1390.258494
#> iter  11 value 1371.211992
#> iter  12 value 1365.633621
#> iter  13 value 1365.014537
#> iter  14 value 1364.999975
#> iter  15 value 1364.997013
#> iter  16 value 1364.996949
#> iter  16 value 1364.996948
#> final  value 1364.996948 
#> converged
#> 
#> 
#> Summary table:
#> 
#> 
#> ===================  ====  ===  ====  ====  ======  ====  ====  =====  ====  ========  ====
#> \                    vars    n  mean    sd  median   min   max  range  skew  kurtosis    se
#> ===================  ====  ===  ====  ====  ======  ====  ====  =====  ====  ========  ====
#> est_bprof               1    2  0.20  0.05    0.20  0.16  0.23   0.07     0     -2.75  0.04
#> est_bexp                2    2  0.34  0.03    0.34  0.32  0.36   0.04     0     -2.75  0.02
#> est_bdomestic           3    2  0.39  0.13    0.39  0.30  0.49   0.19     0     -2.75  0.10
#> est_bforeign            4    2  0.37  0.03    0.37  0.35  0.39   0.04     0     -2.75  0.02
#> est_bdamage             5    2  0.69  0.07    0.69  0.64  0.74   0.10     0     -2.75  0.05
#> 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.27  0.08    4.27  4.21  4.33   0.12     0     -2.75  0.06
#> rob_pval0_bprof         8    2  0.12  0.12    0.12  0.04  0.20   0.16     0     -2.75  0.08
#> 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.00  0.01    0.00  0.00  0.01   0.01     0     -2.75  0.00
#> 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: 0x5588b2cd45d0>
#> 
#> $u1$v2
#> V.2 ~ bprof * alt2.professional + bexp * alt2.expert + bdomestic * 
#>     alt2.domestic + bforeign * alt2.foreign + bdamage * alt2.damage + 
#>     bprice * alt2.compensation
#> <environment: 0x5588b384f880>
#> 
#> $u1$v3
#> V.3 ~ basc
#> <environment: 0x5588b33a0e60>
#> 
#> 
#> New names:
#>  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
#> 
#> 
#> 
#>  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
#> 
#> 
#> 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: 8.251 sec elapsed
#> $tic
#> elapsed 
#>   11.95 
#> 
#> $toc
#> elapsed 
#>  20.201 
#> 
#> $msg
#> [1] "total time for simulation and estimation"
#> 
#> $callback_msg
#> [1] "total time for simulation and estimation: 8.251 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] "bayeffnewpriors1"      "bayeff3newpriorsdummy" "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.420    0.293         0.437        0.404       0.615      0.208
#> 2 2         0.171    0.122         0.254        0.158       0.632      0.194
#> # ℹ 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.30 0.18   0.30 0.17 0.42  0.25    0    -2.75 0.12
#> est_bexp               2 2 0.21 0.12   0.21 0.12 0.29  0.17    0    -2.75 0.09
#> est_bdomestic          3 2 0.35 0.13   0.35 0.25 0.44  0.18    0    -2.75 0.09
#> est_bforeign           4 2 0.28 0.17   0.28 0.16 0.40  0.25    0    -2.75 0.12
#> est_bdamage            5 2 0.62 0.01   0.62 0.62 0.63  0.02    0    -2.75 0.01
#> est_bprice             6 2 0.20 0.01   0.20 0.19 0.21  0.01    0    -2.75 0.01
#> est_basc               7 2 4.16 0.34   4.16 3.92 4.40  0.47    0    -2.75 0.24
#> rob_pval0_bprof        8 2 0.02 0.03   0.02 0.00 0.04  0.04    0    -2.75 0.02
#> rob_pval0_bexp         9 2 0.08 0.12   0.08 0.00 0.17  0.16    0    -2.75 0.08
#> rob_pval0_bdomestic   10 2 0.00 0.00   0.00 0.00 0.00  0.00    0    -2.75 0.00
#> rob_pval0_bforeign    11 2 0.04 0.06   0.04 0.00 0.09  0.09    0    -2.75 0.04
#> 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")