Skip to contents

Simulate values from distributions

Usage

sim(..., length.out = 100, do_melt = TRUE)

Arguments

...

Every argument must be a function which takes the number of values which should be generated, e.g.:

    `function(n) random_n_values_from_distribution(n)`

length.out

How many samples should be drawn from each population

do_melt

TRUE: # A tibble: 200 × 2 Distribution Value 1 negative 0.805 2 positive 2.62 3 negative 1.19 4 positive 1.49

FALSE: # A tibble: 100 × 2 negative positive 1 0.631 2.81 2 0.687 1.87 3 0.0347 1.61 4 -1.15 0.529

Value

See do_melt parameter

Examples


sim(
    negative = function(x) rnorm(x, mean = 0, sd = 1),
    positive = function(x) rnorm(x, mean = 1, sd = 1)
)
#> # A tibble: 200 × 2
#>     Value Distribution
#>     <dbl> <chr>       
#>  1  0.386 negative    
#>  2 -0.839 negative    
#>  3 -0.530 negative    
#>  4 -2.29  negative    
#>  5  1.86  negative    
#>  6 -0.625 negative    
#>  7  0.176 negative    
#>  8 -1.37  negative    
#>  9 -1.35  negative    
#> 10  0.947 negative    
#> # ℹ 190 more rows
sim(
    list(
        negative = function(x) rnorm(x, mean = 0, sd = 1),
        positive = function(x) rnorm(x, mean = 1, sd = 1)
    )
)
#> # A tibble: 200 × 2
#>      Value Distribution
#>      <dbl> <chr>       
#>  1  1.07   negative    
#>  2  0.655  negative    
#>  3 -0.123  negative    
#>  4 -0.930  negative    
#>  5  1.52   negative    
#>  6 -0.0768 negative    
#>  7 -0.370  negative    
#>  8  0.606  negative    
#>  9  1.53   negative    
#> 10 -0.0815 negative    
#> # ℹ 190 more rows
sim(
    negative = function(x) rnorm(x, mean = 0, sd = 1),
    positive = function(x) rnorm(x, mean = 1, sd = 1),
    do_melt = FALSE
)
#> # A tibble: 100 × 2
#>    negative positive
#>       <dbl>    <dbl>
#>  1   0.605    2.12  
#>  2   0.801    1.40  
#>  3   0.318    0.0155
#>  4   0.103    0.497 
#>  5  -0.658    1.99  
#>  6   0.0339   3.19  
#>  7  -0.650    0.835 
#>  8   0.911    0.314 
#>  9  -0.0473   1.94  
#> 10  -1.18     0.836 
#> # ℹ 90 more rows
sim(
    negative = function(x) rnorm(x, mean = 0, sd = 1),
    positive = function(x) rnorm(x, mean = 1, sd = 1),
    do_melt = TRUE
)
#> # A tibble: 200 × 2
#>       Value Distribution
#>       <dbl> <chr>       
#>  1 -1.39    negative    
#>  2  0.437   negative    
#>  3  0.316   negative    
#>  4  0.195   negative    
#>  5 -0.456   negative    
#>  6  0.813   negative    
#>  7  0.275   negative    
#>  8  0.00601 negative    
#>  9  2.01    negative    
#> 10  0.314   negative    
#> # ℹ 190 more rows

sim(
    negative = function(x) rnorm(x, mean = 0, sd = 1),
    positive = function(x) rnorm(x, mean = 1, sd = 1),
    length.out = 10
)
#> # A tibble: 20 × 2
#>      Value Distribution
#>      <dbl> <chr>       
#>  1  0.0491 negative    
#>  2 -0.0328 negative    
#>  3 -0.511  negative    
#>  4  0.356  negative    
#>  5  0.418  negative    
#>  6  0.579  negative    
#>  7 -1.48   negative    
#>  8  1.32   negative    
#>  9  1.03   negative    
#> 10  0.317  negative    
#> 11 -0.112  positive    
#> 12  1.62   positive    
#> 13  2.81   positive    
#> 14  2.11   positive    
#> 15  1.47   positive    
#> 16 -0.0686 positive    
#> 17  1.26   positive    
#> 18  0.223  positive    
#> 19  0.0497 positive    
#> 20  2.23   positive