knitr::opts_chunk$set(collapse = T, comment = "#>") library(Binomial)
This document is an introduction to the Binomial package. The binomial package is a implementation of basical statistical functions; the methods are designed to calculate and visualize binomial distributions.
Let's consider a case with 10 trials, with each trial having a 0.7 chance of succeededing.
Included in the package are 5 base summary functions:
Let's review each one more carefully.
The binomial mean is the average number of successes in n trials given p probability of success. To get the mean, call bin_mean(trials, probability)
bin_mean(10,0.7)
The binomial variance is the square of the standard deviation of a binomial distribution. To get the variance, call bin_variance(trials, probability)
bin_variance(10,0.7)
The binomial mode is the most likely number of succeses. To obtain the mode, call bin_mode(trials,probability)
bin_mode(10,0.7)
The binomial skewness is a measure of the asymmetry of the binomial distribution. To obtain the skewness, call bin_skewness(trials,probability)
bin_skewness(10,0.7)
The binomial kurtosis is a measure of the sharpness of a peak in a frequency-distirbution curve. To obtain the kurtosis, call bin_kurtosis(trials,probability)
bin_kurtosis(10,0.7)
bin_variable(trials,probability)
provides a basic return
bin_variable(10,0.7)
To easily obtain a summary of all the above binomial variables, use summary(bin_variable(trials,probability))
summary(bin_variable(10,0.7))
The following main functions are to calculate binomial distributions. Two methods are used to calculate some more basic statistics:
These functions can be used to model coin flips, for example.
bin_choose(trials, successes)
provides the number of permutations to obtain the specific number of successes in the given amount of trials.
bin_choose(10,6) #This means there are 210 different ways to obtain 6 successes in 10 trials
bin_probability(successes,trials,probability)
provides the percent chance of obtaining k successes in n trials with a p probability of succeeding on each trial. This function can be used to determine how likely it is to get 1, 2, or 3 heads for 5 total coin flips.
bin_probability(6,10,0.6) #This means there is a around a 25% chance of obtaining 6 successes in 10 trials where each trial has a 60% chance of succeeding. bin_probability(1:3,5,0.5) #Calling bin_probability with multiple success values gives us the seperate probability of obtaining each success value. There is about a 15% chance of obtaining 1 success and about the same 31% chance of obtaining 2 or 3 successes out of 5.
Finally, the two following functions provide a visualization method for binomial distributions.
bin_distirbution(trials,probability)
returns a data frame with how likely it is to obtiain each possible success number in n trials.
#This function call provides the likelihood of seeing 0, 1, 2, 3, or 4 heads in 4 coin tosses. bin_distribution(4,0.5)
An easier way to see this data is with a frequency histogram, which can be obtaining by calling plot(bin_distribution(trials,probability))
plot(bin_distribution(4,0.5)) #Here, we see that flipping 2 heads is the most likely option in 4 coin tosses.
bin_cumulative(trials,probability)
provides additional information about the cumulative probability
#This function call provides the likelihood of seeing 0, 1, 2, 3, or 4 heads in 4 coin tosses, along with the cumulative probability. bin_cumulative(4,0.5)
Finally, the cumulative probability can be visualized by plot(bin_cumulative(trials,probability))
plot(bin_cumulative(10,0.5)) #We see that most iterations of 10 coin flips will have less than 8 "heads"; the cumulative probability that we get less than 8 heads is above 90%
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.