knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "README-"
)

Overview

"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.

Motivation

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.

Installation

Install the development version from GitHub via the package "devtools":

# development version from GitHub:
install.packages("devtools") 

# install "binomial"
devtools::install_github("gastonstat/binomial")

Usage

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)

Binomial Random Variable

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

Summary Meausres

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)


gastonstat/binomial documentation built on April 5, 2022, 6:37 a.m.