Title
to_tsibble.Rd
Title
Examples
library(tidyverse)
#> ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
#> ✔ forcats 1.0.0 ✔ readr 2.1.4
#> ✔ ggplot2 3.4.1 ✔ stringr 1.5.0
#> ✔ lubridate 1.9.2 ✔ tibble 3.2.0
#> ✔ purrr 1.0.1 ✔ tidyr 1.3.0
#> ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
#> ✖ tidyr::extract() masks magrittr::extract()
#> ✖ dplyr::filter() masks stats::filter()
#> ✖ dplyr::lag() masks stats::lag()
#> ✖ purrr::set_names() masks magrittr::set_names()
#> ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
bernoulli_trial() |>
add_trials() |>
to_tsibble()
#> # A tibble: 8 × 4
#> history trial outcome prob
#> <int> <chr> <dbl> <dbl>
#> 1 1 t1 0 0.75
#> 2 1 t2 0 0.75
#> 3 2 t1 0 0.75
#> 4 2 t2 1 0.25
#> 5 3 t1 1 0.25
#> 6 3 t2 0 0.75
#> 7 4 t1 1 0.25
#> 8 4 t2 1 0.25
bernoulli_trial(prob = .5) |>
add_trials() |>
add_trials() |>
to_tsibble() |>
group_by(history) |>
summarize(hist_prob = prod(prob),
count_successes = sum(outcome),
paths = paste(outcome, collapse = ",")) |>
arrange(count_successes) |>
group_by(count_successes) |>
summarize(prob = sum(hist_prob))
#> # A tibble: 4 × 2
#> count_successes prob
#> <dbl> <dbl>
#> 1 0 0.125
#> 2 1 0.375
#> 3 2 0.375
#> 4 3 0.125