percentify_random.Rd
This function is a wrapper around percentify
. Given a width`` and a
n`, it will generate a number of random interval with fixed width.
percentify_random(data, var, width, n = 10)
data | A data.frame or tibble, |
---|---|
var | Variable to do grouping by as string or symbol. |
width | Numerical values for the width of the interval. Must be between 0 and 1. |
n | Integer, number of intervals to create. |
percentile grouped tibble
There is a ggplot2::autoplot()
to visualize the the percentile ranges.
Other percentile samplers: autoplot.percentiled_df
,
percentify_cut
,
percentify_max
,
percentify_min
library(dplyr) library(broom) set.seed(1234) percent_mtcars <- percentify_random(mtcars, mpg, 0.4, 10) percent_mtcars#> # A tibble: 32 x 11 #> # Groups: .percentile_mpg [10] #> mpg cyl disp hp drat wt qsec vs am gear carb #> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> #> 1 21 6 160 110 3.9 2.62 16.5 0 1 4 4 #> 2 21 6 160 110 3.9 2.88 17.0 0 1 4 4 #> 3 22.8 4 108 93 3.85 2.32 18.6 1 1 4 1 #> 4 21.4 6 258 110 3.08 3.22 19.4 1 0 3 1 #> 5 18.7 8 360 175 3.15 3.44 17.0 0 0 3 2 #> 6 18.1 6 225 105 2.76 3.46 20.2 1 0 3 1 #> 7 14.3 8 360 245 3.21 3.57 15.8 0 0 3 4 #> 8 24.4 4 147. 62 3.69 3.19 20 1 0 4 2 #> 9 22.8 4 141. 95 3.92 3.15 22.9 1 0 4 2 #> 10 19.2 6 168. 123 3.92 3.44 18.3 1 0 4 4 #> # … with 22 more rows#> # A tibble: 10 x 4 #> .percentile_mpg mean_hp mean_wt n_obs #> <chr> <dbl> <dbl> <int> #> 1 6.8%-46.8% 193. 3.71 12 #> 2 37.3%-77.3% 123. 3.06 13 #> 3 36.6%-76.6% 123. 3.06 13 #> 4 37.4%-77.4% 123. 3.06 13 #> 5 51.7%-91.7% 98.7 2.51 13 #> 6 38.4%-78.4% 123. 3.06 13 #> 7 0.6%-40.6% 208. 4.01 13 #> 8 14%-54% 178. 3.58 12 #> 9 40%-80% 123. 3.03 12 #> 10 30.9%-70.9% 140. 3.31 12#> # A tibble: 30 x 6 #> # Groups: .percentile_mpg [10] #> .percentile_mpg term estimate std.error statistic p.value #> <chr> <chr> <dbl> <dbl> <dbl> <dbl> #> 1 6.8%-46.8% (Intercept) -306. 154. -1.99 0.0778 #> 2 6.8%-46.8% wt 44.9 25.8 1.74 0.115 #> 3 6.8%-46.8% cyl 57.9 18.6 3.12 0.0123 #> 4 37.3%-77.3% (Intercept) -235. 90.7 -2.59 0.0269 #> 5 37.3%-77.3% wt 58.3 41.3 1.41 0.188 #> 6 37.3%-77.3% cyl 44.2 13.8 3.21 0.00939 #> 7 36.6%-76.6% (Intercept) -235. 90.7 -2.59 0.0269 #> 8 36.6%-76.6% wt 58.3 41.3 1.41 0.188 #> 9 36.6%-76.6% cyl 44.2 13.8 3.21 0.00939 #> 10 37.4%-77.4% (Intercept) -235. 90.7 -2.59 0.0269 #> # … with 20 more rows