Problem 1
Show that if \(Y\sim POI(\lambda)\) , that \(U = cY\) is NOT \(POI(c\lambda)\) .
Show for a grid of \(\lambda \in \{1,2,3,4\}\) and with \(c = 2\) that \(U\) is NOT \(POI(2\lambda)\) .
library (tidyverse)
library (purrrfect)
N <- 10000
(scaled_pois_sims <- parameters (~ lambda,
c (1 ,2 ,3 ,4 ))
%>% add_trials (N)
%>% mutate (Y = map_int (lambda, .f = \(l) rpois (1 , l)))
%>% mutate (U = 2 * Y)
%>% mutate (Fhat = cume_dist (U), .by = lambda,
F = ppois (U, lambda = 2 * lambda))
) %>% head
# A tibble: 6 × 6
lambda .trial Y U Fhat F
<dbl> <dbl> <int> <dbl> <dbl> <dbl>
1 1 1 0 0 0.367 0.135
2 1 2 0 0 0.367 0.135
3 1 3 1 2 0.731 0.677
4 1 4 0 0 0.367 0.135
5 1 5 0 0 0.367 0.135
6 1 6 0 0 0.367 0.135
(ggplot (data = scaled_pois_sims)
+ geom_step (aes (x = U, y = Fhat, col = 'Empirical' ))
+ geom_step (aes (x = U, y = F, col = 'Analytic' ))
+ facet_wrap (~ lambda)
+ theme_classic ()
)
(ggplot (data = scaled_pois_sims)
+ geom_point (aes (x = F, y = Fhat))
+ geom_abline (aes (intercept = 0 , slope = 1 ))
+ facet_wrap (~ lambda, labeller = label_both)
)
Problem 2
If \(X \sim \chi^2_p\) and \(Y \sim \chi^2_q\) , show that \(U = X + Y \sim \chi^2_{p+q}\) for \(p, q \in \{1,2,3,4\}\) .
(chi_sims <- parameters (~ p, ~ q,
1 : 4 , 1 : 4 )
%>% add_trials (N)
%>% mutate (X = map_dbl (p, .f = \(p) rchisq (1 , df = p)),
Y = map_dbl (q, .f = \(q) rchisq (1 , df = q)))
%>% mutate (U = X + Y)
%>% mutate (fU = dchisq (U, df = p+ q))
) %>% head
# A tibble: 6 × 7
p q .trial X Y U fU
<int> <int> <dbl> <dbl> <dbl> <dbl> <dbl>
1 1 1 1 0.157 0.0311 0.188 0.455
2 1 1 2 2.22 0.309 2.53 0.141
3 1 1 3 0.204 0.182 0.386 0.412
4 1 1 4 5.49 1.34 6.84 0.0164
5 1 1 5 1.59 0.000286 1.59 0.225
6 1 1 6 0.0602 0.559 0.619 0.367
(ggplot (data = chi_sims)
+ geom_histogram (aes (x = U, y = after_stat (density)))
+ geom_line (aes (x = U, y = fU), col = 'cornflowerblue' )
+ facet_grid (p~ q, labeller = label_both)
+ theme_classic ()
)
`stat_bin()` using `bins = 30`. Pick better value `binwidth`.