Create mixture model data and resulting density and line plots.
Arguments
- ...
The random data you want to pass. Example rnorm(50,0,1) or something like tidy_normal(.mean = 5, .sd = 1)
Details
This function allows you to make mixture model data. It allows you to produce density data and plots for data that is not strictly of one family or of one single type of distribution with a given set of parameters.
For example this function will allow you to mix say tidy_normal(.mean = 0, .sd = 1) and tidy_normal(.mean = 5, .sd = 1) or you can mix and match distributions.
The output is a list object with three components.
Data
input_data (The random data passed)
dist_tbl (A tibble of the passed random data)
density_tbl (A tibble of the x and y data from
stats::density()
)
Plots
line_plot - Plots the dist_tbl
dens_plot - Plots the density_tbl
Input Functions
input_fns - A list of the functions and their parameters passed to the function itself
Examples
output <- tidy_mixture_density(rnorm(100, 0, 1), tidy_normal(.mean = 5, .sd = 1))
output$data
#> $dist_tbl
#> # A tibble: 150 × 2
#> x y
#> <int> <dbl>
#> 1 1 -0.235
#> 2 2 -1.08
#> 3 3 -0.394
#> 4 4 0.378
#> 5 5 -0.305
#> 6 6 0.558
#> 7 7 -1.39
#> 8 8 1.68
#> 9 9 -1.08
#> 10 10 -0.699
#> # ℹ 140 more rows
#>
#> $dens_tbl
#> # A tibble: 150 × 2
#> x y
#> <dbl> <dbl>
#> 1 -5.13 0.0000554
#> 2 -5.03 0.0000794
#> 3 -4.94 0.000113
#> 4 -4.84 0.000159
#> 5 -4.74 0.000221
#> 6 -4.65 0.000304
#> 7 -4.55 0.000414
#> 8 -4.45 0.000558
#> 9 -4.36 0.000746
#> 10 -4.26 0.000986
#> # ℹ 140 more rows
#>
#> $input_data
#> $input_data$`rnorm(100, 0, 1)`
#> [1] -0.235353001 -1.078278941 -0.394494306 0.378351368 -0.305441689
#> [6] 0.558246758 -1.393532326 1.684877827 -1.081165240 -0.699117005
#> [11] -0.725905652 -1.517417803 -0.687345982 1.138408622 -0.828156661
#> [16] -1.764248116 -0.394656802 0.680190219 1.674713389 -1.622145315
#> [21] -1.139302224 -0.653020621 1.259829155 -1.657913877 -0.205151049
#> [26] 0.471233597 0.126930606 0.776793531 0.463766570 1.121856454
#> [31] 0.287754635 -0.942991367 -1.326285422 -0.831089780 0.870650245
#> [36] 2.220308388 -0.517924250 0.176057409 -0.079394425 0.464457785
#> [41] -1.228834634 -0.827114503 -0.442650039 0.563441181 3.045195603
#> [46] 0.630522340 -2.287277571 -1.963242402 -0.587886403 0.660829020
#> [51] 0.575452544 -0.732980663 0.646981831 -0.304213920 0.478974620
#> [56] -0.680208172 1.020957064 0.211375567 2.556798079 -0.357284695
#> [61] 1.296430536 -0.106096171 -1.788955128 1.306353861 0.267957365
#> [66] 0.046148651 0.881654738 -1.521475135 -1.074093381 0.784098611
#> [71] -1.325868925 -0.908470832 0.092405292 -0.637334735 0.420245842
#> [76] -0.445381955 -0.005572972 -0.095291648 1.458740814 -0.225460424
#> [81] 0.539405404 0.914422018 0.849907176 1.167660314 0.872550773
#> [86] -2.588423803 -0.614142664 0.739495589 0.065735720 -0.789692769
#> [91] -0.382117193 -0.542426104 -0.499944756 2.499905149 0.345791751
#> [96] -0.489950558 1.045149401 -0.597249064 0.385316128 -1.478374322
#>
#> $input_data$`tidy_normal(.mean = 5, .sd = 1)`
#> # A tibble: 50 × 7
#> sim_number x y dx dy p q
#> <fct> <int> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 1 1 4.75 1.90 0.000361 0.401 4.75
#> 2 1 2 5.83 2.02 0.00102 0.797 5.83
#> 3 1 3 4.81 2.14 0.00255 0.425 4.81
#> 4 1 4 3.95 2.26 0.00563 0.147 3.95
#> 5 1 5 4.42 2.38 0.0110 0.282 4.42
#> 6 1 6 2.90 2.50 0.0192 0.0179 2.90
#> 7 1 7 4.51 2.62 0.0299 0.313 4.51
#> 8 1 8 6.53 2.73 0.0420 0.937 6.53
#> 9 1 9 6.73 2.85 0.0541 0.958 6.73
#> 10 1 10 6.07 2.97 0.0654 0.857 6.07
#> # ℹ 40 more rows
#>
#>
output$plots
#> $line_plot
#>
#> $dens_plot
#>
output$input_fns
#> [[1]]
#> rnorm(100, 0, 1)
#>
#> [[2]]
#> tidy_normal(.mean = 5, .sd = 1)
#>