Beta Distribution Calculator
Calculator
Parameters
Distribution Chart
Click Calculate to view the distribution chart
Learn More
Beta Distribution: Definition, Formula, and Applications
Beta Distribution
Definition: The beta distribution is a family of continuous probability distributions defined on the interval [0, 1]. It is characterized by two positive shape parameters, α (alpha) and β (beta), which determine its shape and properties.
Formula:The probability density function (PDF) is given by:where:
Where:
- is the first shape parameter
- is the second shape parameter
- is the gamma function
Properties
Key Statistics:
- Mean:
- Variance:
- Mode:
- for
- 0 when
- 1 when
- Undefined when
Special Cases:
- : Uniform distribution on [0,1]
- : Symmetric distribution around 0.5
- : U-shaped distribution
- : Unimodal distribution
Applications
1. Bayesian Statistics
The beta distribution is the conjugate prior for the Bernoulli, binomial, and geometric distributions. This makes it particularly useful in Bayesian inference for:
- Estimating probabilities of success
- Modeling conversion rates
- A/B testing analysis
2. Project Management
Used in PERT (Program Evaluation and Review Technique) for:
- Modeling task completion times
- Risk assessment
- Project duration estimation
3. Quality Control
Applied in manufacturing and quality control for:
- Modeling proportions of defective items
- Process capability analysis
- Tolerance interval estimation
4. Market Research
Used in marketing analytics for:
- Customer behavior modeling
- Market share analysis
- Customer lifetime value prediction
How to Calculate Beta Distribution in R?
R
1library(tidyverse)
2
3# Parameters
4alpha <- 2
5beta <- 5
6
7# Calculate probability between two values
8x1 <- 0.2
9x2 <- 0.6
10prob <- pbeta(x2, shape1 = alpha, shape2 = beta) - pbeta(x1, shape1 = alpha, shape2 = beta)
11print(str_glue("P({x1} < X < {x2}) = {round(prob, 4)}"))
12
13# Create plot
14x <- seq(0, 1, length.out = 1000)
15y <- dbeta(x, shape1 = alpha, shape2 = beta)
16df <- tibble(x = x, y = y)
17
18ggplot(df, aes(x = x, y = y)) +
19 geom_line(color = "blue") +
20 geom_area(data = subset(df, x >= x1 & x <= x2),
21 aes(x = x, y = y),
22 fill = "blue",
23 alpha = 0.2) +
24 labs(title = str_glue("Beta Distribution (α = {alpha}, β = {beta})"),
25 x = "x",
26 y = "Probability Density",
27 caption = str_glue("P({x1} < X < {x2}) = {round(prob, 4)}")) +
28 theme_minimal() +
29 coord_cartesian(expand = FALSE)
How to Calculate Beta Distribution in Python?
Python
1import numpy as np
2import pandas as pd
3from scipy import stats
4import matplotlib.pyplot as plt
5import seaborn as sns
6
7# Set parameters
8alpha = 2 # shape parameter 1
9beta = 5 # shape parameter 2
10
11# Calculate probability between two values
12x1, x2 = 0.2, 0.6
13prob = stats.beta.cdf(x2, alpha, beta) - stats.beta.cdf(x1, alpha, beta)
14print(f"P({x1} < X < {x2}) = {prob:.4f}")
15
16# Create plot
17x = np.linspace(0, 1, 1000)
18pdf = stats.beta.pdf(x, alpha, beta)
19
20plt.figure(figsize=(10, 6))
21plt.plot(x, pdf, 'blue', label='PDF')
22
23# Add shaded area
24x_shade = x[(x >= x1) & (x <= x2)]
25pdf_shade = stats.beta.pdf(x_shade, alpha, beta)
26plt.fill_between(x_shade, pdf_shade, alpha=0.2, color='blue')
27
28# Customize plot
29plt.title(f'Beta Distribution (α = {alpha}, β = {beta})')
30plt.xlabel('x')
31plt.ylabel('Probability Density')
32plt.annotate(f'P({x1} < X < {x2}) = {prob:.4f}',
33 xy=(0.5, max(pdf)/2),
34 xytext=(0.5, max(pdf)/2))
35
36plt.grid(True, alpha=0.3)
37plt.show()