Practice_set_7.3

library(tidyverse)
Warning: package 'tidyverse' was built under R version 4.3.3
Warning: package 'tibble' was built under R version 4.3.3
Warning: package 'tidyr' was built under R version 4.3.3
Warning: package 'readr' was built under R version 4.3.3
Warning: package 'purrr' was built under R version 4.3.3
Warning: package 'dplyr' was built under R version 4.3.3
Warning: package 'stringr' was built under R version 4.3.3
Warning: package 'forcats' was built under R version 4.3.3
Warning: package 'lubridate' was built under R version 4.3.3
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
βœ” dplyr     1.1.4     βœ” readr     2.1.5
βœ” forcats   1.0.0     βœ” stringr   1.5.1
βœ” ggplot2   4.0.1     βœ” tibble    3.2.1
βœ” lubridate 1.9.4     βœ” tidyr     1.3.1
βœ” purrr     1.0.2     
── 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
library(purrrfect)

Attaching package: 'purrrfect'

The following objects are masked from 'package:base':

    replicate, tabulate

Practice Set 7.3

Creating the Dataset

df <-(parameters(~i,~n,~lambda,c(3,5,9),c(10,15,20),c(.05,.1))
      %>%add_trials(10000)
      %>%mutate(Y = pmap(list(n,lambda),\(x,y) sort(rexp(x,y))),Y_i = pmap_dbl(list(i,Y),\(x,y) pluck(y,x)),Y_i_1 = pmap_dbl(list(i,Y),\(x,y) pluck(y,x-1)),T_s=pmap_dbl(list(Y_i,Y_i_1),\(x,y) x-y),ft = pmap_dbl(list(T_s,i,n,lambda),\(x,y,z,w) dexp(x,w*(z-y+1))))
)

Plotting all combinations

(ggplot(data = df)
+ geom_histogram(aes(x = T_s,y = after_stat(density)), fill = "gold",binwidth = .05,center = .01)
+ geom_line(aes(x=T_s,y=ft),color = "blue")
+ facet_grid(~i~n~lambda,labeller =label_both,scales = "free")
+ theme_classic()
+ labs(title = "Y1")
+ scale_x_continuous(limits = c(0, 4))
)
Warning: Removed 24313 rows containing non-finite outside the scale range
(`stat_bin()`).
Warning: Removed 36 rows containing missing values or values outside the scale range
(`geom_bar()`).
Warning: Removed 24313 rows containing missing values or values outside the scale range
(`geom_line()`).