Skip to contents

Tidy_dbinom returns a data table that pairs number of successes with probabilities given the probability of a single trial and the total number of trials.

Usage

tidy_dbinom(single_trial_prob = 0.5, num_trials = 10)

Arguments

single_trial_prob

a numeric value between 0 and 1

num_trials

positive integer which is the total number of trials

Value

A data frame pairing number of successes with probabilities.

Examples

tidy_dbinom(single_trial_prob = 1/6, num_trials = 4)
#> # A tibble: 5 × 4
#>   num_successes probability single_trial_prob num_trials
#>           <int>       <dbl>             <dbl>      <dbl>
#> 1             0    0.482                0.167          4
#> 2             1    0.386                0.167          4
#> 3             2    0.116                0.167          4
#> 4             3    0.0154               0.167          4
#> 5             4    0.000772             0.167          4
tidy_dbinom(.5, 10)
#> # A tibble: 11 × 4
#>    num_successes probability single_trial_prob num_trials
#>            <int>       <dbl>             <dbl>      <dbl>
#>  1             0    0.000977               0.5         10
#>  2             1    0.00977                0.5         10
#>  3             2    0.0439                 0.5         10
#>  4             3    0.117                  0.5         10
#>  5             4    0.205                  0.5         10
#>  6             5    0.246                  0.5         10
#>  7             6    0.205                  0.5         10
#>  8             7    0.117                  0.5         10
#>  9             8    0.0439                 0.5         10
#> 10             9    0.00977                0.5         10
#> 11            10    0.000977               0.5         10
tidy_dbinom(1/12, 3)
#> # A tibble: 4 × 4
#>   num_successes probability single_trial_prob num_trials
#>           <int>       <dbl>             <dbl>      <dbl>
#> 1             0    0.770               0.0833          3
#> 2             1    0.210               0.0833          3
#> 3             2    0.0191              0.0833          3
#> 4             3    0.000579            0.0833          3
tidy_dbinom(.5, 20)
#> # A tibble: 21 × 4
#>    num_successes probability single_trial_prob num_trials
#>            <int>       <dbl>             <dbl>      <dbl>
#>  1             0 0.000000954               0.5         20
#>  2             1 0.0000191                 0.5         20
#>  3             2 0.000181                  0.5         20
#>  4             3 0.00109                   0.5         20
#>  5             4 0.00462                   0.5         20
#>  6             5 0.0148                    0.5         20
#>  7             6 0.0370                    0.5         20
#>  8             7 0.0739                    0.5         20
#>  9             8 0.120                     0.5         20
#> 10             9 0.160                     0.5         20
#> # ℹ 11 more rows

library(ggplot2)
ggplot(tidy_dbinom(1/6, num_trials = 8)) +
  aes(x = num_successes) +
  scale_x_counting() +
  aes(y = probability) +
  geom_lollipop()