| Title: | Moment-Preserving Finitization for Power-Series Distributions |
|---|---|
| Description: | Implements the finitization of discrete probability distributions, a technique that approximates a distribution by preserving a finite number of moments. These finitized distributions enable faster random variate generation than inverse transform sampling and are useful in simulation and statistical modeling. |
| Authors: | Bogdan Oancea [aut, cre] (ORCID: <https://orcid.org/0000-0001-6987-5137>) |
| Maintainer: | Bogdan Oancea <[email protected]> |
| License: | GPL (>= 2) |
| Version: | 0.1.0 |
| Built: | 2026-06-09 10:43:44 UTC |
| Source: | https://github.com/bogdanoancea/finitization |
dbinom(n, p, N, val, log) computes the finitized Binomial density for each value in val.
dbinom(n, p, N, val = NULL, log = FALSE)dbinom(n, p, N, val = NULL, log = FALSE)
n |
The finitization order. An integer > 0. |
p |
The success probability for each trial (must satisfy 0 <= p <= 1). |
N |
The number of trials. |
val |
A vector of values at which the density is computed. If |
log |
Logical; if TRUE, the (natural) logarithm of the probabilities is returned. |
A data.frame with two columns: val, which contains the values, and prob,
which contains the corresponding density (or log density if log = TRUE).
library(finitization) dbinom(4, 0.5, 4) dbinom(4, 0.5, 4, log = TRUE)library(finitization) dbinom(4, 0.5, 4) dbinom(4, 0.5, 4, log = TRUE)
dlog(n, theta, val, log) computes the finitized Logarithmic density for each value in val.
dlog(n, theta, val = NULL, log = FALSE)dlog(n, theta, val = NULL, log = FALSE)
n |
The finitization order. It should be an integer > 0. |
theta |
The parameter of the finitized Logarithmic distribution. |
val |
A vector with the values of the variable for which the probability density is computed.
If |
log |
Logical; if TRUE, the (natural) logarithm of the computed probabilities is returned. |
A data.frame object with two columns: val containing the values and
prob containing the corresponding densities (or their logarithms if log = TRUE).
library(finitization) dlog(4, 0.1, c(0,1,3)) dlog(4, 0.1, c(0,1,3), log = TRUE)library(finitization) dlog(4, 0.1, c(0,1,3)) dlog(4, 0.1, c(0,1,3), log = TRUE)
dnegbinom(n, q, k, val, log) computes the finitized Negative Binomial density for val.
dnegbinom(n, q, k, val = NULL, log = FALSE)dnegbinom(n, q, k, val = NULL, log = FALSE)
n |
The finitization order. It should be an integer > 0. |
q |
The parameter of the finitized Negative Binomial distribution - the success probability for each trial ( |
k |
The number of failures until the experiment is stopped, |
val |
A vector with the values of the variable for which the probability density is computed. If |
log |
Logical; if TRUE, the (natural) logarithm of the computed densities is returned. |
A data.frame object with two columns: val containing the values and prob containing the corresponding densities (or their logarithms if log = TRUE).
library(finitization) dnegbinom(4, 0.12, 4) dnegbinom(4, 0.12, 4, log = TRUE)library(finitization) dnegbinom(4, 0.12, 4) dnegbinom(4, 0.12, 4, log = TRUE)
dpois(n, theta, val, log) computes the finitized Poisson density for each value in val.
dpois(n, theta, val = NULL, log = FALSE)dpois(n, theta, val = NULL, log = FALSE)
n |
The finitization order. It should be an integer > 0. |
theta |
The parameter of the finitized Poisson distribution. |
val |
A vector with the values of the variable for which the probability density is computed.
If |
log |
Logical; if TRUE, the (natural) logarithm of the computed probabilities is returned. |
A data.frame object with two columns: val containing the values and
prob containing the corresponding densities (or their logarithms if log = TRUE).
library(finitization) dpois(4, 0.5, c(0,1,3)) dpois(4, 0.5, c(0,1,3), log = TRUE)library(finitization) dpois(4, 0.5, c(0,1,3)) dpois(4, 0.5, c(0,1,3), log = TRUE)
getBinomialMFPS(n, N) computes and returns the maximum feasible parameter space for the finitized Binomial distribution.
getBinomialMFPS(n, N)getBinomialMFPS(n, N)
n |
The finitization order. An integer > 0. |
N |
The number of trials. |
A vector of two elements, where the first element is the lower limit and the second element is the upper limit of the maximum feasible parameter space.
library(finitization) getBinomialMFPS(2, 4)library(finitization) getBinomialMFPS(2, 4)
getLogarithmicMFPS(n) computes and returns the maximum feasible parameter space for the finitized Logarithmic distribution.
getLogarithmicMFPS(n)getLogarithmicMFPS(n)
n |
The finitization order. It should be an integer > 0. |
A vector with two elements where the first element is the lower limit and the second is the upper limit.
library(finitization) getLogarithmicMFPS(1)library(finitization) getLogarithmicMFPS(1)
getNegativeBinomialMFPS(n, k) computes and returns the maximum feasible parameter space for the finitized Negative
Binomial distribution with parameter k.
getNegativeBinomialMFPS(n, k)getNegativeBinomialMFPS(n, k)
n |
The finitization order. It should be an integer > 0. |
k |
The number of failures until the experiment is stopped, |
A vector with two elements where the first element is the lower limit of the maximum feasible parameter space and the second is the upper limit.
library(finitization) getNegativeBinomialMFPS(2, 4)library(finitization) getNegativeBinomialMFPS(2, 4)
getPoissonMFPS(n) computes and returns the maximum feasible parameter space for the finitized Poisson distribution.
getPoissonMFPS(n)getPoissonMFPS(n)
n |
The finitization order. It should be an integer > 0. |
A vector with two elements where the first element is the lower limit of the maximum feasible parameter space and the second is the upper limit.
library(finitization) getPoissonMFPS(4)library(finitization) getPoissonMFPS(4)
pbinom(n, p, N, val, lower.tail, log.p) computes the CDF for the finitized Binomial distribution at specified value(s).
pbinom(n, p, N, val = NULL, lower.tail = TRUE, log.p = FALSE)pbinom(n, p, N, val = NULL, lower.tail = TRUE, log.p = FALSE)
n |
The finitization order. A positive integer (> 0). |
p |
The success probability for each trial (0 <= p <= 1). |
N |
The number of trials. |
val |
A numeric vector of values at which the CDF is computed.
If |
lower.tail |
Logical; if |
log.p |
Logical; if |
If val is provided, a data.frame with two columns:
valThe input values.
cdfThe corresponding cumulative probabilities (or log-probabilities if log.p = TRUE).
If val is NULL, a data.frame with all possible values (0, ..., n) and their cumulative probabilities is returned.
library(finitization) # CDF evaluated at specific points pbinom(4, 0.5, 4, val = c(0, 2, 4)) # Full CDF over all values (0 to 4) pbinom(4, 0.5, 4) # CDF upper tail (P(X > x)) pbinom(4, 0.5, 4, lower.tail = FALSE) # CDF on log scale pbinom(4, 0.5, 4, log.p = TRUE)library(finitization) # CDF evaluated at specific points pbinom(4, 0.5, 4, val = c(0, 2, 4)) # Full CDF over all values (0 to 4) pbinom(4, 0.5, 4) # CDF upper tail (P(X > x)) pbinom(4, 0.5, 4, lower.tail = FALSE) # CDF on log scale pbinom(4, 0.5, 4, log.p = TRUE)
plog(n, theta, val, log.p, lower.tail) computes the CDF for the finitized Logarithmic distribution at specified value(s).
plog(n, theta, val = NULL, log.p = FALSE, lower.tail = TRUE)plog(n, theta, val = NULL, log.p = FALSE, lower.tail = TRUE)
n |
The finitization order. A positive integer (> 0). |
theta |
The parameter of the finitized Logarithmic distribution. |
val |
A numeric vector of values at which to compute the CDF.
If |
log.p |
Logical; if |
lower.tail |
Logical; if |
A data.frame with the following columns:
valThe input values (either the user-supplied val or 0:n).
cdfThe corresponding cumulative probabilities (or log-probabilities if log.p = TRUE).
library(finitization) # Evaluate CDF at specific points plog(4, 0.1, val = c(0, 2, 4)) # Full CDF from 0 to 4 plog(4, 0.1) # Upper-tail probabilities plog(4, 0.1, val = c(0, 2, 4), lower.tail = FALSE) # Log-scale CDF plog(4, 0.1, log.p = TRUE)library(finitization) # Evaluate CDF at specific points plog(4, 0.1, val = c(0, 2, 4)) # Full CDF from 0 to 4 plog(4, 0.1) # Upper-tail probabilities plog(4, 0.1, val = c(0, 2, 4), lower.tail = FALSE) # Log-scale CDF plog(4, 0.1, log.p = TRUE)
pnegbinom(n, q, k, val, log.p, lower.tail) computes the CDF for the finitized Negative Binomial distribution at specified value(s).
pnegbinom(n, q, k, val = NULL, log.p = FALSE, lower.tail = TRUE)pnegbinom(n, q, k, val = NULL, log.p = FALSE, lower.tail = TRUE)
n |
The finitization order. A positive integer (> 0). |
q |
The success probability for each trial ( |
k |
The target number of failures before stopping; a positive integer. |
val |
A numeric vector of values at which to compute the CDF.
If |
log.p |
Logical; if |
lower.tail |
Logical; if |
A data.frame with two columns:
valThe input values (either specified val or the full sequence from 0 to n).
cdfThe corresponding cumulative probabilities (or log-probabilities if log.p = TRUE).
library(finitization) # Compute CDF at specific values pnegbinom(4, 0.12, 4, val = c(0, 2, 4)) # Compute full CDF over range 0 to 4 pnegbinom(4, 0.12, 4) # Upper-tail probabilities pnegbinom(4, 0.12, 4, val = c(0, 2, 4), lower.tail = FALSE) # Log-scale cumulative probabilities pnegbinom(4, 0.12, 4, log.p = TRUE)library(finitization) # Compute CDF at specific values pnegbinom(4, 0.12, 4, val = c(0, 2, 4)) # Compute full CDF over range 0 to 4 pnegbinom(4, 0.12, 4) # Upper-tail probabilities pnegbinom(4, 0.12, 4, val = c(0, 2, 4), lower.tail = FALSE) # Log-scale cumulative probabilities pnegbinom(4, 0.12, 4, log.p = TRUE)
ppois(n, theta, val, log.p, lower.tail) computes the CDF for the finitized Poisson distribution at specified value(s).
ppois(n, theta, val = NULL, log.p = FALSE, lower.tail = TRUE)ppois(n, theta, val = NULL, log.p = FALSE, lower.tail = TRUE)
n |
The finitization order. A positive integer (> 0). |
theta |
The mean parameter of the finitized Poisson distribution. |
val |
A numeric vector of values at which to compute the CDF.
If |
log.p |
Logical; if |
lower.tail |
Logical; if |
A data.frame with columns:
valThe evaluated values (input val or the full range 0:n).
cdfThe corresponding cumulative probabilities (or log-probabilities if log.p = TRUE).
# Compute CDF at specific values ppois(n = 4, theta = 0.5, val = c(0, 2, 4)) # Compute full CDF over range 0 to 4 ppois(n = 4, theta = 0.5) # Upper-tail probabilities ppois(n = 4, theta = 0.5, val = c(0, 2, 4), lower.tail = FALSE) # Log-scale cumulative probabilities ppois(n = 4, theta = 0.5, log.p = TRUE)# Compute CDF at specific values ppois(n = 4, theta = 0.5, val = c(0, 2, 4)) # Compute full CDF over range 0 to 4 ppois(n = 4, theta = 0.5) # Upper-tail probabilities ppois(n = 4, theta = 0.5, val = c(0, 2, 4), lower.tail = FALSE) # Log-scale cumulative probabilities ppois(n = 4, theta = 0.5, log.p = TRUE)
printFinitizedBinomialDensity(n, N, val, latex) computes and prints the string
representation of the probability density function for the finitized Binomial distribution.
printFinitizedBinomialDensity(n, N, val = NULL, latex = FALSE)printFinitizedBinomialDensity(n, N, val = NULL, latex = FALSE)
n |
The finitization order. An integer > 0. |
N |
The number of trials. |
val |
The value(s) at which the density is printed. If |
latex |
Logical; if TRUE, the output is formatted in LaTeX. |
Silently returns a character vector with the string representation(s) of the pdf.
library(finitization) printFinitizedBinomialDensity(4, 4)library(finitization) printFinitizedBinomialDensity(4, 4)
printFinitizedLogarithmicDensity(n, val, latex) computes and prints the string representation of the pdf.
printFinitizedLogarithmicDensity(n, val = NULL, latex = FALSE)printFinitizedLogarithmicDensity(n, val = NULL, latex = FALSE)
n |
The finitization order. It should be an integer > 0. |
val |
The value for which the pdf is printed. If |
latex |
Logical; if TRUE the output is formatted in LaTeX. |
A character vector containing the string representation(s) of the pdf.
library(finitization) printFinitizedLogarithmicDensity(4)library(finitization) printFinitizedLogarithmicDensity(4)
printFinitizedNegativeBinomialDensity(n,k, val, latex) computes and prints the string
representation of the probability density function for the finitized Negative Binomial distribution with parameter k.
printFinitizedNegativeBinomialDensity(n, k, val = NULL, latex = FALSE)printFinitizedNegativeBinomialDensity(n, k, val = NULL, latex = FALSE)
n |
The finitization order. It should be an integer > 0. |
k |
The number of failures until the experiment is stopped, |
val |
The value of the variable for which the probability density function is printed. If NULL, this function computes the
string representation of the pdf for all possible values, i.e. |
latex |
If TRUE, a string representation of the pdf formatted in Latex format is printed, otherwise this function prints the string representation of the pdf as an R expression. |
This function silently returns a vector of type character with the string representation of the pdf(s).
The length of the vector is the same with the length of the parameter val, i.e. one element for each value in val.
library(finitization) printFinitizedNegativeBinomialDensity(4, 4)library(finitization) printFinitizedNegativeBinomialDensity(4, 4)
printFinitizedPoissonDensity(n, val, latex) computes and prints the string
representation of the probability density function for the finitized Poisson distribution.
printFinitizedPoissonDensity(n, val = NULL, latex = FALSE)printFinitizedPoissonDensity(n, val = NULL, latex = FALSE)
n |
The finitization order. It should be an integer > 0. |
val |
The value of the variable for which the probability density function is printed. If NULL, this function computes the
string representation of the pdf for all possible values, i.e. |
latex |
If TRUE, a string representation of the pdf formatted in Latex format is printed, otherwise this function prints the string representation of the pdf as an R expression. |
This function silently returns a vector of type character with the string representation of the pdf(s).
The length of the vector is the same with the length of the parameter val, i.e. one element for each value in val.
library(finitization) printFinitizedPoissonDensity(4)library(finitization) printFinitizedPoissonDensity(4)
qbinom(n, p, N, prob, lower.tail = TRUE, log.p = FALSE) computes the quantile function for the finitized Binomial distribution.
qbinom(n, p, N, prob, lower.tail = TRUE, log.p = FALSE)qbinom(n, p, N, prob, lower.tail = TRUE, log.p = FALSE)
n |
The finitization order. An integer > 0. |
p |
The success probability for each trial (0 <= p <= 1). |
N |
The number of trials. |
prob |
A vector of probabilities (or log-probabilities if |
lower.tail |
Logical; if TRUE (default) the input probabilities are interpreted as |
log.p |
Logical; if TRUE, the probabilities in |
A numeric vector of quantiles corresponding to the input probabilities. For each probability, the quantile is defined as the smallest integer \(x\) (from 0 to n) such that the cumulative probability is at least the provided value.
library(finitization) qbinom(4, 0.5, 4, prob = c(0.1, 0.5, 0.9)) qbinom(4, 0.5, 4, prob = log(c(0.1, 0.5, 0.9)), lower.tail = TRUE, log.p = TRUE) qbinom(4, 0.5, 4, prob = c(0.1, 0.5, 0.9), lower.tail = FALSE)library(finitization) qbinom(4, 0.5, 4, prob = c(0.1, 0.5, 0.9)) qbinom(4, 0.5, 4, prob = log(c(0.1, 0.5, 0.9)), lower.tail = TRUE, log.p = TRUE) qbinom(4, 0.5, 4, prob = c(0.1, 0.5, 0.9), lower.tail = FALSE)
qlog(n, theta, p, lower.tail, log.p) computes the quantile function for the finitized Logarithmic distribution.
qlog(n, theta, p, lower.tail = TRUE, log.p = FALSE)qlog(n, theta, p, lower.tail = TRUE, log.p = FALSE)
n |
The finitization order. An integer > 0. |
theta |
The parameter of the finitized Logarithmic distribution. |
p |
A numeric vector of probabilities. For |
lower.tail |
Logical; if TRUE (default) the input probabilities are lower-tail probabilities, otherwise upper-tail probabilities. |
log.p |
Logical; if TRUE, the probabilities in |
A numeric vector of quantiles corresponding to the input probabilities.
library(finitization) qlog(4, 0.1, p = c(0.1, 0.1, 0.9)) qlog(4, 0.1, p = c(0.1, 0.1, 0.9), lower.tail = FALSE)library(finitization) qlog(4, 0.1, p = c(0.1, 0.1, 0.9)) qlog(4, 0.1, p = c(0.1, 0.1, 0.9), lower.tail = FALSE)
qnegbinomial(n, q, k, p, lower.tail = TRUE, log.p = FALSE) computes the quantile(s)
corresponding to the given probability(ies) for the finitized Negative Binomial distribution.
qnegbinom(n, q, k, p, lower.tail = TRUE, log.p = FALSE)qnegbinom(n, q, k, p, lower.tail = TRUE, log.p = FALSE)
n |
The finitization order. An integer > 0. |
q |
The success probability for each trial ( |
k |
The number of failures until the experiment is stopped, |
p |
A numeric vector of probabilities. For |
lower.tail |
Logical; if TRUE (default) the input probabilities are lower-tail probabilities, otherwise they are upper-tail probabilities. |
log.p |
Logical; if TRUE, the probabilities in |
A numeric vector of quantiles corresponding to the input probabilities. Each quantile is the smallest integer for which the cumulative probability is at least the given probability.
library(finitization) qnegbinom(n = 4, q = 0.12, k = 4, p = c(0.1, 0.5, 0.9)) qnegbinom(n = 4, q = 0.12, k = 4, p = c(0.1, 0.5, 0.9), lower.tail = FALSE)library(finitization) qnegbinom(n = 4, q = 0.12, k = 4, p = c(0.1, 0.5, 0.9)) qnegbinom(n = 4, q = 0.12, k = 4, p = c(0.1, 0.5, 0.9), lower.tail = FALSE)
qpois(n, theta, p, lower.tail, log.p) computes the quantile(s) corresponding to the given probability(ies)
for the finitized Poisson distribution.
qpois(n, theta, p, lower.tail = TRUE, log.p = FALSE)qpois(n, theta, p, lower.tail = TRUE, log.p = FALSE)
n |
The finitization order. An integer > 0. |
theta |
The parameter of the finitized Poisson distribution. |
p |
A numeric vector of probabilities. For |
lower.tail |
Logical; if TRUE (default) the input probabilities are lower-tail probabilities; otherwise, they are upper-tail. |
log.p |
Logical; if TRUE the probabilities in |
A numeric vector of quantiles corresponding to the input probabilities. Each quantile is defined as the
smallest integer for which the cumulative probability is at least the given probability.
# For a finitized Poisson distribution with n = 4 and theta = 0.5: qpois(n = 4, theta = 0.5, p = c(0.1, 0.5, 0.9)) qpois(n = 4, theta = 0.5, p = c(0.1, 0.5, 0.9), lower.tail = FALSE)# For a finitized Poisson distribution with n = 4 and theta = 0.5: qpois(n = 4, theta = 0.5, p = c(0.1, 0.5, 0.9)) qpois(n = 4, theta = 0.5, p = c(0.1, 0.5, 0.9), lower.tail = FALSE)
rbinom(n, p, N, no) generates random values according to the finitized Binomial distribution.
rbinom(n, p, N, no)rbinom(n, p, N, no)
n |
The finitization order. An integer > 1. |
p |
The success probability for each trial (0 <= p <= 1). |
N |
The number of trials. |
no |
The number of random values to be generated. |
An integer vector of length no, with random values drawn from the finitized Binomial distribution.
library(finitization) rbinom(2, 0.5, 2, 10)library(finitization) rbinom(2, 0.5, 2, 10)
rlog(n, theta, no) generates random values according to the finitized Logarithmic distribution.
rlog(n, theta, no)rlog(n, theta, no)
n |
The finitization order. It should be an integer > 1. |
theta |
The parameter of the Logarithmic distribution. |
no |
The number of random values to be generated. |
A vector of integers containing random values generated from the finitized Logarithmic distribution.
library(finitization) rlog(2, 0.25, 10)library(finitization) rlog(2, 0.25, 10)
rnegbinom(n, q, k, no) generates random values according to the finitized Binomial distribution with parameters q,k.
rnegbinom(n, q, k, no)rnegbinom(n, q, k, no)
n |
The finitization order. It should be an integer > 1. |
q |
The parameter of the finitized Negative Binomial distribution - the success probability for each trial. |
k |
The number of failures until the experiment is stopped, |
no |
The number of random values to be generated. |
rpois returns a vector of type integer containing random values generated according to the finitized Negative
Binomial distribution. The number of values is given by the parameter no.
library(finitization) rnegbinom(2, 0.15, 2, 10)library(finitization) rnegbinom(2, 0.15, 2, 10)
rpois(n, theta, no) generates random values according to the finitized Poisson distribution with parameter theta.
rpois(n, theta, no)rpois(n, theta, no)
n |
The finitization order. It should be an integer > 1. |
theta |
The parameter of the Poisson distribution. |
no |
The number of random values to be generated. |
rpois returns a vector of type integer containing random values generated according to the finitized Poisson distribution.
The number of values is given by the parameter no.
library(finitization) rpois(2, 0.5, 10)library(finitization) rpois(2, 0.5, 10)