knitr::opts_chunk$set(collapse = T, comment = "#>") library(binomial)
"binomial"
The package "binomial"
is a simple package to compute binomial probabilities, binomial distributions, as well as summary measures of a binomial random variable.
You can begin by creating a binomial random variable object with the function bin_variable()
:
binvar1 <- bin_variable(10, 0.3) binvar1
The output of bin_variable()
is an object of class "binvar"
, which simply contains the parameters: number of trials, and probability of success.
Once you have a "binvar"
object, you can get summary measures such as the mean, variance, mode, skewness and kurtosis, via the function summary()
:
summary(binvar1)
To compute binomial probabilities, you should use the function bin_probability
. This functions requires three inputs: number of successes, number of trials, and probability of success.
For example, say you want to compute the probability of 3 heads when tossing a fair coin 5 times:
bin_probability(3, 5, 0.5)
If instead of a fair coin you suppose tossing a loaded coin with probability of heads 0.7, then:
bin_probability(3, 5, 0.7)
You can also use bin_probability()
to compute the probabilities for a range of successes. For example, the probabilities of less than 3 heads in 5 tosses of a fair coin is:
bin_probability(0:3, 5, 0.5)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.