Skip to content

Commit

Permalink
⚡ Refactor rpois_dispersion()
Browse files Browse the repository at this point in the history
  • Loading branch information
heavywatal committed Jun 2, 2024
1 parent b1740c1 commit 7988e28
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions R/dispersion.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,17 @@ mutate_chisq = function(.data, ...) {
#' @rdname dispersion
#' @export
rpois_dispersion = function(n, lambda, nrep = 1L) {
seq_len(nrep) |>
purrr::map(\(.i) summary_row(stats::rpois(n, lambda))) |>
purrr::list_rbind(names_to = "repl") |>
list(
repl = rep(seq_len(nrep), each = n),
x = stats::rpois(n * nrep, lambda)
) |>
tibble::new_tibble() |>
dplyr::summarize(
nsam = length(!!as.name("x")),
mean = mean(!!as.name("x")),
var = stats::var(!!as.name("x")),
.by = !!as.name("repl")
) |>
mutate_chisq()
}

Expand Down

0 comments on commit 7988e28

Please sign in to comment.