Skip to contents

gen_psa_samp generates a data.frame of sampled parameter values from user-specified distributions to be used in a probabilistic sensitivity analysis (PSA)

Usage

gen_psa_samp(
  params = NULL,
  dists = c("normal", "log-normal", "truncated-normal", "beta", "gamma", "dirichlet",
    "bootstrap", "constant", "triangle"),
  parameterization_types = c("mean, sd", "a, b", "shape, scale", "value, mean_prop, sd",
    "value, n", "value, alpha", "mean, sd, ll, ul", "val", "meanlog, sdlog",
    "ll, ul, mode", "value, weight"),
  dists_params = NULL,
  nsamp = 100
)

Arguments

params

string vector with the names of parameters to be generated by gen_psa_samp and used by a user-defined function in run_psa to calculate outcomes.

dists

string vector with the distributions from which params will be drawn.

parameterization_types

string vector with parameterization types for each dists

dists_params

list of input parameters required to by specific dists and parameterization_types to fully describe distribution and generate parameter samples.

nsamp

number of sets of parameter values to be generated

Value

A dataframe with samples of parameters for a probabilistic sensitivity analysis (PSA)

Details

Length of vectors params, dists, parameterization_types, and list dists_params must all be the same. The nth element of dists, parameterization_types, and dists_params all define the distribution that will be used to draw samples of the corresponding nth element of the params vector.

For a given element of params:

  • If dists == "normal", parameterization_types can only be "mean, sd", and the corresponding element of list dists_params must be the the vector c(mean, sd)

  • If dists == "log-normal", parameterization_types can be either "mean, sd" or "meanlog, sdlog", and the corresponding element of list dists_params must be either the the vector c(mean, sd) or c(meanlog, sdlog). Use "mean, sd" if you have sample mean and sample standard deviation of an empirical sample of the random variable, and use "meanlog, sdlog" if you want to directly specify the parameters of the log-normal distribution as specified by rlnorm

  • If dists == "truncated-normal", parameterization_types can only be "mean, sd, ll, ul", and dists_params must be the vector c(mean, sd, ll, ul), where ll is the lower limit of the distribution and ul is the upper limit of the distribution. If either the lower limit or the upper limit does not exist, simply specify NA in the corresponding position of the dists_params vector.

  • If dists == "beta", parameterization_types can be "mean, sd" or "a, b" and the corresponding element of list dists_params must be the the vector c(mean, sd) or c(a, b), respectively.

  • If dists == "gamma", parameterization_types can be "mean, sd" or "shape, scale" and the corresponding element of list dists_params must be the the vector c(mean, sd) or c(shape, scale), respectively.

  • If dists == "dirichlet", parameterization_types can be "value, mean_prop, sd", "value, n", or "value, alpha".

    • If parameterization_types == "value, mean_prop, sd", then the corresponding element of list dists_params must be a data.frame where the first column is a string vector of the the different multinomial outcomes. These multinomial outcomes will become column names in the data.frame returned by gen_psa_samp, and therefore the strings in this column should correspond to variable names used in FUN for run_psa. The second and third columns of this dists_params should be numerical vectors containing the sample means and sample standard errors for each of the multinomial outcomes.

    • If parameterization_types == "value, n", then dists_params must be a data.frame with the first column being a string vector of the multinomial outcomes, and the second column being a vector of the observed number of each multinomial outcome in a sample.

    • If parameterization_types == "value, alpha", then dists_params must be a data.frame with the first column being a string vector of the multinomial outcomes, and the second column must be a numerical vector of the alpha parameter values for each multinomial outcome in the dirichlet distribution.

  • If dists == "bootstrap", parameterization_types can only be "value, weight", and dists_params must be a data.frame with the first column being a numerical vector containing all of the bootstrap sample values, and the second column being an integer vector designating the sampling weights of each bootstrap sample value. For example, the number of rows in the dists_params data.frame is the number of individuals in the population to be sampled from (with replacement) or the number of values an empirical distribution (e.g. a histogram). If each individual value in the sample is unique and should be weighted equally, set each weight to 1. If the sample distribution resembles a histogram, the weights should be equal to the number of observations for each unique value in the empirical distribution.

  • If dists == "constant", parameterization_types can only be "val", and dists_params must be a single numerical value.

See also

Examples

#define parameter names
params <- c("normal_param", "lognorm_param", "truncnorm_param", "beta_param",
            "gamma_param", "dirichlet_param", "bootstrap_param")

#indicate parent distribution types for each parameter
dists <- c("normal", "log-normal", "truncated-normal", "beta", "gamma", "dirichlet", "bootstrap")

#indicate which type of parameterization is used for each parent distribution
parameterization_types <- c("mean, sd", "mean, sd", "mean, sd, ll, ul", "mean, sd", "mean, sd",
                          "value, mean_prop, sd", "value, weight")

#provide distribution parameters that fully define each parent distribution, and
#ensure that these distribution parameters match the form expected by each combination of dists
#and parameterization_types
dists_params <- list(c(1, 2), c(1, 3), c(1, 0.1, NA, 1), c(.5, .2), c(100, 1),
                   data.frame(value = c("level1", "level2", "level3"),
                              mean_prop = c(.1, .4, .5), sd = c(.05, .01, .1)),
                   data.frame(value = c(1, 2, 4, 6, 7, 8),
                              weight = c(1, 1, 1, 1, 1, 4)))

#generate 100 samples of parameter values to be used in a probabilistic sensitivity analysis
gen_psa_samp(params = params,
             dists = dists,
             parameterization_types = parameterization_types,
             dists_params = dists_params,
             nsamp = 100)
#>     nsamp normal_param lognorm_param truncnorm_param beta_param gamma_param
#> 1       1   0.51160079   0.446353664       0.7351068  0.8896776    99.65962
#> 2       2   0.43458910   1.395763384       0.9213637  0.3296233   101.33663
#> 3       3  -0.10739877   0.230326653       0.9457858  0.5020955    99.77190
#> 4       4   2.25796408   0.037824587       0.9924894  0.1932318   100.28633
#> 5       5   5.13004979   0.468143198       0.9441486  0.7704896   100.19305
#> 6       6  -2.26197880   0.161751993       0.9584594  0.4500366    98.79509
#> 7       7   2.02485390   0.749399027       0.9058794  0.4073927   100.16484
#> 8       8  -2.72602298   7.972897999       0.9959796  0.8745054   100.10914
#> 9       9  -0.04402503   0.602540244       0.9875699  0.2974318    99.20044
#> 10     10   0.89479618   0.024549420       0.8766610  0.2715297   101.14249
#> 11     11   2.08599269   0.461698355       0.9659576  0.7406381    98.75996
#> 12     12  -0.82814965   1.610687848       0.9291247  0.1648725   101.03648
#> 13     13   1.93630884   6.981764645       0.9762575  0.2242159    99.54572
#> 14     14   1.72590251   0.625452938       0.9252971  0.6529333    99.79672
#> 15     15  -1.60908709   2.613483081       0.9928947  0.9223750    99.54564
#> 16     16   2.47555264   0.604104009       0.9324755  0.3509534   100.07466
#> 17     17   4.77700986   0.372305071       0.8846624  0.1414038    98.74017
#> 18     18   0.80510979   0.327108973       0.8682366  0.4974291   100.36380
#> 19     19  -0.87169471   0.790288806       0.8899810  0.3408979   101.37988
#> 20     20   0.96809938   0.212280737       0.8796232  0.3378487    99.12980
#> 21     21  -0.65357791   0.141862813       0.8617089  0.3831281   100.54595
#> 22     22  -2.02479930   0.423280669       0.9996874  0.8025042   100.54543
#> 23     23   2.87072638   0.055544709       0.9558572  0.6544216    99.33656
#> 24     24   1.35297722   1.141942798       0.9871077  0.6254339   100.56624
#> 25     25   1.48737093   0.357976132       0.8544159  0.1231976    99.45102
#> 26     26   4.24709777   0.043642994       0.9710226  0.7134261    99.21417
#> 27     27   1.22407617   0.075386449       0.8539890  0.5548224   100.38740
#> 28     28   0.73200597   0.630109109       0.9850321  0.6412625   100.90296
#> 29     29  -2.82017494   0.086379921       0.8106640  0.4562636   101.20022
#> 30     30   0.44152552   0.204612950       0.9760040  0.6787492   101.17855
#> 31     31   0.37310804   1.229670815       0.9939101  0.2637016    98.93069
#> 32     32   3.13461576   0.350230782       0.9887705  0.6736715   100.60976
#> 33     33   1.14006970   0.247055559       0.9992114  0.3312079    99.37810
#> 34     34  -0.27824665   0.090114388       0.8122256  0.1029585   101.27246
#> 35     35   0.90007020   5.453011317       0.7841243  0.5187835    99.74003
#> 36     36   0.49703311   1.011793607       0.9290285  0.7093337    99.91119
#> 37     37   1.88959423   1.398947725       0.9233017  0.6109197    98.93447
#> 38     38   6.51083515   2.349996384       0.8987998  0.2961974    99.77849
#> 39     39   1.09306276   0.057822799       0.9436620  0.6377951   100.22433
#> 40     40   2.15541814   0.690440954       0.9677517  0.7690946   100.61777
#> 41     41   1.23638975   0.032024899       0.9633326  0.3177401   100.10989
#> 42     42  -2.82344098   3.236624475       0.8870165  0.3805683   101.50188
#> 43     43   2.72417296   0.606474447       0.9782162  0.2280560    99.42176
#> 44     44   0.51352652   0.380598786       0.8584588  0.3828689    99.04417
#> 45     45   0.58782561   0.056239077       0.9519275  0.5283891   101.21395
#> 46     46   1.03835518   0.135600822       0.8395593  0.1207177    99.55387
#> 47     47   1.05912151   1.561829646       0.9123223  0.1808423    99.19069
#> 48     48   2.09965508   0.884301687       0.9375868  0.6713893    98.67329
#> 49     49  -3.54822971   0.335252168       0.7887723  0.2129161   101.64355
#> 50     50   6.36511437   0.184137038       0.8922883  0.4097455    99.35215
#> 51     51   0.27755749   1.037294967       0.8818424  0.6129052   101.67468
#> 52     52   1.42671150   1.071804271       0.9801608  0.4208032   100.00506
#> 53     53   3.14869176   0.017694589       0.9383846  0.2037567   101.42193
#> 54     54  -0.33017650   1.308252028       0.8025843  0.2566586   100.26317
#> 55     55   3.22790484   0.197848106       0.8115338  0.8382918   100.39930
#> 56     56   0.50820718   0.471371837       0.9440894  0.5850521    99.15218
#> 57     57  -1.35512662   0.020892079       0.9606656  0.8809594    99.29568
#> 58     58  -0.95170123   0.095615733       0.9957866  0.5946920    99.51498
#> 59     59   3.13011464   0.056666597       0.8820336  0.2809881    99.15716
#> 60     60   1.26334127   0.549099139       0.9801223  0.1496947    99.09428
#> 61     61   1.97725762   0.204925942       0.9349466  0.4793071    99.36162
#> 62     62  -2.39890114   0.693664157       0.9656087  0.5008786   100.95772
#> 63     63  -1.94147261   0.270509258       0.8522468  0.4127935    99.85354
#> 64     64   1.56830069   0.072123729       0.9927974  0.7678855    99.10299
#> 65     65   3.67464083   2.174633349       0.7873555  0.4456307    99.73182
#> 66     66   1.47339257   1.359000834       0.9592112  0.7407866    99.46901
#> 67     67   3.63658677   1.015302010       0.8606022  0.4352242   101.54910
#> 68     68   2.04781958   1.522961675       0.9639722  0.3136299    99.60852
#> 69     69   2.21349609   0.154064852       0.9345450  0.2798258   100.34579
#> 70     70   0.78012866   0.045660564       0.8947845  0.4323378   101.43380
#> 71     71   1.34436343   0.198880796       0.8791614  0.3557578   100.76235
#> 72     72   0.81934543   9.069403328       0.9704970  0.4699052   101.16590
#> 73     73   4.84868668   0.065092340       0.8733659  0.7747566    99.85811
#> 74     74   3.59678552   0.055517392       0.9890007  0.6554730   101.39839
#> 75     75   2.49758254   0.024885259       0.9147095  0.3472187   100.43995
#> 76     76   2.11244866   3.203385331       0.7913311  0.3059398   100.16414
#> 77     77  -0.09651453   0.733185594       0.8295391  0.2939954   100.16571
#> 78     78   3.22106979   6.508487154       0.9213537  0.1867670   100.70124
#> 79     79  -4.22466867   0.250283867       0.9473542  0.3796396    99.80981
#> 80     80   0.68861245  15.487143628       0.8266422  0.3585395    99.43497
#> 81     81   1.86777958   1.584412644       0.8551343  0.4588635    97.98723
#> 82     82   0.23609778   1.790802176       0.8481807  0.6186486    98.08769
#> 83     83   1.84837515   1.740288673       0.8172875  0.1948169   100.48203
#> 84     84   3.12620399   0.173129851       0.8937124  0.4356528    99.89738
#> 85     85   3.09742524   0.090669763       0.9186942  0.6581364   101.98148
#> 86     86   0.92379421   0.131373906       0.8196517  0.6805688    99.48937
#> 87     87   1.97229784   4.595737785       0.9017547  0.7140873    98.71666
#> 88     88   4.34576522   0.386939606       0.8899508  0.8339343   100.47240
#> 89     89   0.29127767   0.559908304       0.9821188  0.3402192    99.20140
#> 90     90   2.89269577   1.779999955       0.8847653  0.6309141   100.26477
#> 91     91   3.63365271   2.079720935       0.9594899  0.6800957    99.13945
#> 92     92   0.40671995   0.800523700       0.8773318  0.8973345    98.51132
#> 93     93   0.22557285   0.164829192       0.9667056  0.5158905    99.96915
#> 94     94  -0.57086531   2.492056764       0.9965234  0.4348752    99.87359
#> 95     95  -1.11347373   0.283990772       0.9613873  0.3906413    98.12232
#> 96     96  -0.59108286   0.209241555       0.9979169  0.1802768   100.66263
#> 97     97  -2.51255086   0.007719921       0.9992413  0.3764578    98.57855
#> 98     98  -0.38107579   0.349266045       0.9069156  0.4337476   100.61493
#> 99     99  -0.11708399   0.059713345       0.9662598  0.2449108   100.96239
#> 100   100  -0.07332665   0.120984325       0.9065739  0.5887576   100.55784
#>         level1    level2    level3 bootstrap_param
#> 1   0.04761296 0.3520060 0.6003810        4.333333
#> 2   0.08347283 0.4323955 0.4841317        6.222222
#> 3   0.19707025 0.3883145 0.4146153        7.444444
#> 4   0.10047832 0.3217874 0.5777343        5.888889
#> 5   0.11331879 0.3225344 0.5641468        6.333333
#> 6   0.06321098 0.4030492 0.5337398        4.777778
#> 7   0.05009228 0.4500473 0.4998605        6.000000
#> 8   0.15715686 0.3553112 0.4875319        6.444444
#> 9   0.11679406 0.4516646 0.4315413        6.444444
#> 10  0.13983605 0.2974643 0.5626996        6.333333
#> 11  0.04033910 0.4680115 0.4916494        5.222222
#> 12  0.06947776 0.3197570 0.6107652        4.888889
#> 13  0.01471428 0.4699814 0.5153043        5.444444
#> 14  0.08578036 0.3158352 0.5983844        6.111111
#> 15  0.09136281 0.5441459 0.3644912        7.000000
#> 16  0.05577025 0.4670350 0.4771948        4.888889
#> 17  0.23968809 0.2866355 0.4736764        6.444444
#> 18  0.07141568 0.2890752 0.6395091        5.555556
#> 19  0.05051722 0.2442333 0.7052495        6.333333
#> 20  0.16375004 0.4419547 0.3942952        5.000000
#> 21  0.09503953 0.3215558 0.5834047        7.666667
#> 22  0.02641193 0.4593972 0.5141908        6.888889
#> 23  0.11681877 0.3043794 0.5788019        6.555556
#> 24  0.09623954 0.5135980 0.3901624        6.111111
#> 25  0.04729648 0.4035694 0.5491341        3.888889
#> 26  0.09368652 0.2864934 0.6198201        6.111111
#> 27  0.07822392 0.3994980 0.5222780        5.888889
#> 28  0.08362927 0.3429436 0.5734271        6.000000
#> 29  0.10543570 0.4524717 0.4420926        5.666667
#> 30  0.04784016 0.4537797 0.4983802        7.000000
#> 31  0.11732677 0.3073925 0.5752807        5.888889
#> 32  0.08847112 0.4625121 0.4490168        5.666667
#> 33  0.02331799 0.4079316 0.5687504        4.666667
#> 34  0.06855661 0.4627914 0.4686520        5.555556
#> 35  0.10620069 0.3720713 0.5217280        5.888889
#> 36  0.02587708 0.5491759 0.4249471        7.666667
#> 37  0.04427838 0.5119080 0.4438136        6.444444
#> 38  0.04952997 0.4703458 0.4801242        6.333333
#> 39  0.12429287 0.1980954 0.6776117        6.222222
#> 40  0.05717916 0.4458224 0.4969984        3.666667
#> 41  0.12131496 0.4442294 0.4344557        6.555556
#> 42  0.17592533 0.3107888 0.5132859        5.222222
#> 43  0.07516031 0.4171802 0.5076595        4.111111
#> 44  0.10706934 0.3516159 0.5413147        4.666667
#> 45  0.15115752 0.4367871 0.4120553        4.444444
#> 46  0.16489891 0.4938080 0.3412930        6.222222
#> 47  0.05822455 0.2385978 0.7031776        6.777778
#> 48  0.09816734 0.2781503 0.6236823        4.333333
#> 49  0.19712919 0.4130428 0.3898280        6.888889
#> 50  0.18026876 0.5081472 0.3115840        6.222222
#> 51  0.02195979 0.4478953 0.5301449        6.222222
#> 52  0.04341193 0.4268200 0.5297681        7.888889
#> 53  0.11572211 0.2805505 0.6037274        6.444444
#> 54  0.18193914 0.3429396 0.4751213        7.111111
#> 55  0.15017569 0.2122460 0.6375783        5.888889
#> 56  0.11108262 0.3448154 0.5441020        6.777778
#> 57  0.09932662 0.3801152 0.5205582        6.444444
#> 58  0.12866262 0.4458581 0.4254793        6.333333
#> 59  0.08560863 0.4108975 0.5034938        6.000000
#> 60  0.12135190 0.3482195 0.5304286        6.888889
#> 61  0.13506792 0.3331020 0.5318301        4.000000
#> 62  0.08776343 0.4290438 0.4831928        6.444444
#> 63  0.16353082 0.3543963 0.4820729        6.222222
#> 64  0.13530700 0.2441461 0.6205469        7.555556
#> 65  0.08558919 0.3420102 0.5724006        5.666667
#> 66  0.05634147 0.4950961 0.4485624        5.222222
#> 67  0.06338926 0.3471732 0.5894376        5.333333
#> 68  0.04728082 0.3271182 0.6256010        7.111111
#> 69  0.13421825 0.3229982 0.5427835        6.333333
#> 70  0.05633841 0.4235597 0.5201019        5.444444
#> 71  0.13009212 0.4049690 0.4649389        6.111111
#> 72  0.03424782 0.5184195 0.4473327        6.666667
#> 73  0.04578048 0.4347123 0.5195072        6.555556
#> 74  0.21163039 0.4147407 0.3736289        6.222222
#> 75  0.06683493 0.2453378 0.6878272        5.777778
#> 76  0.24142356 0.4657859 0.2927906        4.222222
#> 77  0.20205436 0.4662230 0.3317227        4.555556
#> 78  0.16162228 0.3875802 0.4507975        6.666667
#> 79  0.12613233 0.3615064 0.5123613        6.000000
#> 80  0.09380797 0.4623613 0.4438308        5.888889
#> 81  0.13371166 0.3381225 0.5281658        6.222222
#> 82  0.01363619 0.5142322 0.4721316        5.888889
#> 83  0.09979074 0.5080092 0.3922001        5.888889
#> 84  0.11059905 0.4666183 0.4227826        5.111111
#> 85  0.06789079 0.4740013 0.4581079        6.111111
#> 86  0.06662505 0.3570279 0.5763470        5.333333
#> 87  0.11126730 0.3049662 0.5837665        5.111111
#> 88  0.23303356 0.4363886 0.3305778        5.222222
#> 89  0.01528286 0.4416931 0.5430241        5.777778
#> 90  0.11128638 0.3759887 0.5127249        6.222222
#> 91  0.05769636 0.3030742 0.6392295        4.333333
#> 92  0.15239660 0.3772744 0.4703290        5.777778
#> 93  0.13518773 0.3343903 0.5304220        3.555556
#> 94  0.12709453 0.3703973 0.5025082        5.111111
#> 95  0.08088300 0.4081157 0.5110013        4.555556
#> 96  0.08503578 0.4400264 0.4749378        5.777778
#> 97  0.12484563 0.4330499 0.4421045        6.555556
#> 98  0.03178664 0.3130361 0.6551772        3.777778
#> 99  0.17043102 0.3351801 0.4943889        7.666667
#> 100 0.09076519 0.3891330 0.5201018        4.888889