knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
First, load the package.
library(binomial)
Binomial distribution is the theoretical probability model we use when calculating probabilities about the number of successes in a fixed number of random trials performed under identical conditions (assuming a constant probability of success on each trial).
The first step is to calculates the number of combinations in which $k$ successes can occur in $n$ trials.
bin_choose(n = 5, k = 2)
Then, we can calculate the probability in which $k$ successes can occur in $n$ trials with the probability of success. In this process, the function takes three arguments: success, trials, and prob.
# probability of getting 2 successes in 5 trials # (assuming prob of success = 0.5) bin_probability(success = 2, trials = 5, prob = 0.5)
When we calculate the binomial distribution, we get a data frame with class "bindis","data.frame"
.
bin_distribution(trials=5, prob = 0.5)
The plot()
function gives you a barplot of the distribution:
dis1 <- bin_distribution(trials = 5, prob = 0.5) plot(dis1)
bin_cumulative()
calculates the cumulative probability of a binomial distribution. The output is a data frame with class "bincum","data.frame"
.
bin_cumulative(trials=5, prob = 0.5)
The plot()
function gives you a line plot of the cumulative distribution:
dis2 <- bin_cumulative(trials = 5, prob = 0.5) plot(dis2)
bin_variable()
gives the binomial variable with class "binvar"
. It prints out the parameters.
bin_variable(trials = 10, p = 0.3)
The summary()
functions gives you a summary of the variable: mean, variable, mode, skewness, kurtosis. It is printed out nicely:
bin1 <- bin_variable(trials = 10, p = 0.3) binsum1 <- summary(bin1) binsum1
bin_mean()
calculates mean of binomial distributions:
bin_mean(trials = 10, prob = 0.3)
bin_variance()
calculates variance of binomial distributions:
bin_variance(trials = 10, prob = 0.3)
bin_mode()
calculates mode of binomial distributions:
bin_mode(trials = 10, prob = 0.3)
bin_skewness()
calculates skewness of binomial distributions:
bin_skewness(trials = 10, prob = 0.3)
bin_kurtosis()
calculates kurtosis of binomial distributions:
bin_kurtosis(trials = 10, prob = 0.3)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.