binomial

final class boring_math.probability_distributions.distributions.binomial.Binomial

Bases: DiscreteDist

Class for visualizing Binomial distributed data.

A Binomial distribution represents the number of events with probability p happening in n numbers of trials.

Attributes (some inherited):

  • mean (float) representing the mean value of the distribution

  • stdev (float) representing the standard deviation of the distribution

  • data extracted from a data file (taken to be a population)

  • p (float) representing the probability of an event occurring

  • n (int) the total number of trials

__init__(p: float = 0.5, n: int = 20)

init

param p:

Probability of success.

param n:

Number of trials.

pdf(kf: float) → float

PDF

Binomial probability distribution function.

cdf(kf: float) → float

CDF

Cumulative binomial probability distribution function.

calculate_mean() → float

mean

Calculate the mean from p and n.

calculate_stdev() → float

Calculate the standard deviation using p and n

replace_stats_from_dataset(dset: DataSet) → tuple[float, int]

Replace stats from dataset

Function to calculate p and n from a data set, taken as a population.

plot_bar_data() → None

Plat bar graph

Produce a bar-graph of the data using the matplotlib pyplot library.

plot_pdf_bar_graph(show: bool = True, lower_cap: int | None = None, upper_cap: int | None = None) → tuple[list[int], list[float]]

Plat pdf bar graph

Function to plot the pdf of the binomial distribution.

param show:

If False suppress printing the bar graph, useful in pytest test suite.

param lower_cap:

Put a lower cap on the values printed.

param upper_cap:

Put an upper cap on the values printed.

returns:

A tuple[list[int], list[float]] where list[int] are the x values used for the bar graph and list[float] are the corresponding probabilities for each x.

__add__(other: Self) → Self

add

Add together two Binomial distributions with equal p.

__repr__() → str

repr string

returns:

A string to reproduce the distribution.

__str__() → str

user string

returns:

A string meaningful to an end user.