% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/PMF.R
\name{PMF}
\alias{PMF}
\alias{PMF_sample}
\alias{PMF_get_mean}
\alias{PMF_get_var}
\alias{PMF_get_quantile}
\alias{PMF_summary}
\title{PMF operations and utilities}
\usage{
PMF_sample(pmf, N_samples)
PMF_get_mean(pmf)
PMF_get_var(pmf)
PMF_get_quantile(pmf, p)
PMF_summary(pmf, Ltoll = .TOLL, Rtoll = .RTOLL)

PMF_get_mean(pmf)

PMF_get_var(pmf)

PMF_get_quantile(pmf, p)

PMF_summary(pmf, Ltoll = .TOLL, Rtoll = .RTOLL)
}
\arguments{
\item{pmf}{A PMF object (numeric vector where element j+1 is the probability of value j).}

\item{N_samples}{Number of samples to draw from the PMF.}

\item{p}{Probability level for quantile computation. Either a number or a vector with all elements between 0 and 1.}

\item{Ltoll}{Lower tolerance for computing the minimum of the PMF (default: 1e-15).}

\item{Rtoll}{Upper tolerance for computing the maximum of the PMF (default: 1e-9).}
}
\description{
A set of functions for working with Probability Mass Functions (PMFs) in bayesRecon.
A PMF is represented as a normalized numeric vector where element \code{v[j+1]} represents
the probability of value \code{j} (support starts from 0).

These functions provide utilities for:
\itemize{
\item Drawing samples from PMFs
\item Computing summary statistics (mean, variance, quantiles)
\item Summarizing PMF distributions
}
}
\section{Functions}{


\describe{
\item{\code{PMF_sample(pmf, N_samples)}}{
Draws random samples from the probability distribution specified by the PMF.
Uses sampling with replacement from the discrete support values, weighted by
their probabilities. This is useful for generating synthetic data or for
Monte Carlo simulations.
}

\item{\code{PMF_get_mean(pmf)}}{
Computes the expected value (mean) of the distribution represented by the PMF.
The mean is calculated as the sum of each value in the support weighted by
its probability: \eqn{\sum_{x} x \cdot P(X=x)}.
}

\item{\code{PMF_get_var(pmf)}}{
Computes the variance of the distribution represented by the PMF.
The variance measures the spread of the distribution and is calculated as
\eqn{E[X^2] - (E[X])^2}, where \eqn{E[X]} is the mean.
}

\item{\code{PMF_get_quantile(pmf, p)}}{
Computes the quantile of the distribution at probability level \code{p}.
Returns the smallest value \code{x} such that the cumulative probability up to \code{x}
is greater than or equal to \code{p}. For example, \code{p=0.5} gives the median.
The parameter \code{p} can be a single number or a vector of probabilities.
}

\item{\code{PMF_summary(pmf, Ltoll, Rtoll)}}{
Provides a comprehensive summary of the distribution including minimum, maximum,
quartiles, median, and mean. The minimum and maximum are determined based on
probability thresholds to handle the potentially infinite tails of discrete distributions.
}
}
}

\examples{
library(bayesRecon)

# Let's build the pmf of a Binomial distribution with parameters n and p
n <- 10
p <- 0.6
pmf_binomial <- apply(matrix(seq(0, n)), MARGIN = 1, FUN = \(x) dbinom(x, size = n, prob = p))

# Draw samples from the PMF object
set.seed(1)
samples <- PMF_sample(pmf = pmf_binomial, N_samples = 1e4)

# Compute statistics
PMF_get_mean(pmf_binomial) # Mean: should be close to n*p = 6
PMF_get_var(pmf_binomial) # Variance: should be close to n*p*(1-p) = 2.4
PMF_get_quantile(pmf_binomial, 0.5) # Median
PMF_summary(pmf_binomial) # Full summary

}
