knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "README-" )
"binomial"
is a minimal R package
that provides functions for calculating probabilities of a Binomial random
variable, and related calculations such as the probability distribution,
the expected value, variance, mode, etc.
The creation of this package was used as a project assignment in one of the editions of Stat 133 Concepts in Computing with Data. The main purpose of this assignment was to illustrate some of the concepts behind the creation of an R package.
Install the development version from GitHub via the package "devtools"
:
# development version from GitHub: install.packages("devtools") # install "binomial" devtools::install_github("gastonstat/binomial")
library(binomial) # probability of getting 2 successes in 5 trials # (assuming prob of success = 0.5) bin_probability(success = 2, trials = 5, prob = 0.5) # probabilities of getting 2 or less successes in 5 trials # (assuming prob of success = 0.5) bin_probability(success = 0:2, trials = 5, prob = 0.5) # 55 heads in 100 tosses of a loaded coin with 45% chance of heads bin_probability(success = 55, trials = 100, prob = 0.45)
# binomial probability distribution bin_distribution(trials = 5, prob = 0.5)
# plotting binomial probability distribution dis1 <- bin_distribution(trials = 5, prob = 0.5) plot(dis1)
# binomial cumulative distribution bin_cumulative(trials = 5, prob = 0.5)
The package "binomial"
also has the function bin_variable()
that lets you
create a binomial random variable. To be more precise, this function returns
an object of class "binvar"
# binomial variable bin1 <- bin_variable(trials = 10, p = 0.3) bin1 # summary method binsum1 <- summary(bin1) binsum1
Finally, "binomial"
has a couple of additional functions to compute summary
measures such as the mean, variance, kurtosis
# mean bin_mean(10, 0.3) # variance bin_variance(10, 0.3) # mode bin_mode(10, 0.3) # skewness bin_skewness(10, 0.3) # kurtosis bin_kurtosis(10, 0.3)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.