Verify that Y_((k) ), the k^th order statistic from an i.i.d. sample of UNIF(0,1) random variables, follows a BETA(k,n-k+1) density by simulating Y_((k) ) over a grid of n∈{4,8,12,16}. Obtain 10,000 replications per n of Y_((1) ),Y_((3) ), and Y_((n) ). Plot the simulated densities superimposed with their analytic counterparts. Publish your results to Rpubs and submit a link to your published simulation study. (Hint: one way to find the general k^th order statistic is to write a helper function that takes a sample x as input, sorts the sample, and returns the k^th value. Then use this function in map_dbl.)
library(purrrfect)
Attaching package: 'purrrfect'
The following objects are masked from 'package:base':
replicate, tabulate
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
(uniform_order_stat_sim <-parameters(~n,c(4, 8, 12, 16)) %>%add_trials(10000) %>%mutate(y_sample =pmap(list(n, .trial),\(n, t) runif(n, min =0, max =1))) %>%mutate(y1 =map_dbl(y_sample, ~sort(.x)[1]),y3 =map_dbl(y_sample, ~sort(.x)[3]),yn =map2_dbl(y_sample, n, ~sort(.x)[.y]) ) %>%mutate(f_1 =dbeta(y1, 1, n),f_3 =dbeta(y3, 3, n -2),f_n =dbeta(yn, n, 1) ))