Skip to contents

The Poisson distribution is a discrete probability distribution that models the number of events occurring in a fixed interval of time or space, given that the events occur with a constant rate \(\lambda > 0\) and independently of the time since the last event.

Usage

Pois(lambda = 1)

# S4 method for class 'Pois,numeric'
d(distr, x, log = FALSE)

# S4 method for class 'Pois,numeric'
p(distr, q, lower.tail = TRUE, log.p = FALSE)

# S4 method for class 'Pois,numeric'
qn(distr, p, lower.tail = TRUE, log.p = FALSE)

# S4 method for class 'Pois,numeric'
r(distr, n)

# S4 method for class 'Pois'
mean(x)

# S4 method for class 'Pois'
median(x)

# S4 method for class 'Pois'
mode(x)

# S4 method for class 'Pois'
var(x)

# S4 method for class 'Pois'
sd(x)

# S4 method for class 'Pois'
skew(x)

# S4 method for class 'Pois'
kurt(x)

# S4 method for class 'Pois'
entro(x)

# S4 method for class 'Pois'
finf(x)

llpois(x, lambda)

# S4 method for class 'Pois,numeric'
ll(distr, x)

epois(x, type = "mle", ...)

# S4 method for class 'Pois,numeric'
mle(distr, x, na.rm = FALSE)

# S4 method for class 'Pois,numeric'
me(distr, x, na.rm = FALSE)

vpois(lambda, type = "mle")

# S4 method for class 'Pois'
avar_mle(distr)

# S4 method for class 'Pois'
avar_me(distr)

Arguments

lambda

numeric. The distribution parameter.

distr

an object of class Pois.

x

For the density function, x is a numeric vector of quantiles. For the moments functions, x is an object of class Pois. For the log-likelihood and the estimation functions, x is the sample of observations.

log, log.p

logical. Should the logarithm of the probability be returned?

q

numeric. Vector of quantiles.

lower.tail

logical. If TRUE (default), probabilities are \(P(X \leq x)\), otherwise \(P(X > x)\).

p

numeric. Vector of probabilities.

n

number of observations. If length(n) > 1, the length is taken to be the number required.

type

character, case ignored. The estimator type (mle or me).

...

extra arguments.

na.rm

logical. Should the NA values be removed?

Value

Each type of function returns a different type of object:

  • Distribution Functions: When supplied with one argument (distr), the d(), p(), q(), r(), ll() functions return the density, cumulative probability, quantile, random sample generator, and log-likelihood functions, respectively. When supplied with both arguments (distr and x), they evaluate the aforementioned functions directly.

  • Moments: Returns a numeric, either vector or matrix depending on the moment and the distribution. The moments() function returns a list with all the available methods.

  • Estimation: Returns a list, the estimators of the unknown parameters. Note that in distribution families like the binomial, multinomial, and negative binomial, the size is not returned, since it is considered known.

  • Variance: Returns a named matrix. The asymptotic covariance matrix of the estimator.

Details

The probability mass function (PMF) of the Poisson distribution is: $$ P(X = k) = \frac{\lambda^k e^{-\lambda}}{k!}, \quad k \in \mathbb{N}_0. $$

See also

Functions from the stats package: dpois(), ppois(), qpois(), rpois()

Examples

# -----------------------------------------------------
# Pois Distribution Example
# -----------------------------------------------------

# Create the distribution
lambda <- 5
D <- Pois(lambda)

# ------------------
# dpqr Functions
# ------------------

d(D, 0:10) # density function
#>  [1] 0.006737947 0.033689735 0.084224337 0.140373896 0.175467370 0.175467370
#>  [7] 0.146222808 0.104444863 0.065278039 0.036265577 0.018132789
p(D, 0:10) # distribution function
#>  [1] 0.006737947 0.040427682 0.124652019 0.265025915 0.440493285 0.615960655
#>  [7] 0.762183463 0.866628326 0.931906365 0.968171943 0.986304731
qn(D, c(0.4, 0.8)) # inverse distribution function
#> [1] 4 7
x <- r(D, 100) # random generator function

# alternative way to use the function
df <- d(D) ; df(x) # df is a function itself
#>   [1] 0.084224337 0.104444863 0.065278039 0.175467370 0.104444863 0.065278039
#>   [7] 0.104444863 0.175467370 0.084224337 0.104444863 0.036265577 0.140373896
#>  [13] 0.175467370 0.175467370 0.104444863 0.036265577 0.065278039 0.006737947
#>  [19] 0.084224337 0.175467370 0.175467370 0.084224337 0.104444863 0.175467370
#>  [25] 0.104444863 0.140373896 0.104444863 0.065278039 0.104444863 0.140373896
#>  [31] 0.065278039 0.175467370 0.175467370 0.175467370 0.175467370 0.175467370
#>  [37] 0.175467370 0.146222808 0.140373896 0.006737947 0.065278039 0.175467370
#>  [43] 0.065278039 0.175467370 0.036265577 0.104444863 0.140373896 0.175467370
#>  [49] 0.175467370 0.175467370 0.175467370 0.104444863 0.065278039 0.084224337
#>  [55] 0.018132789 0.036265577 0.140373896 0.146222808 0.084224337 0.140373896
#>  [61] 0.175467370 0.104444863 0.175467370 0.036265577 0.084224337 0.036265577
#>  [67] 0.104444863 0.175467370 0.146222808 0.084224337 0.008242177 0.175467370
#>  [73] 0.104444863 0.104444863 0.146222808 0.140373896 0.104444863 0.175467370
#>  [79] 0.175467370 0.140373896 0.146222808 0.104444863 0.146222808 0.175467370
#>  [85] 0.084224337 0.175467370 0.175467370 0.084224337 0.175467370 0.175467370
#>  [91] 0.175467370 0.084224337 0.175467370 0.146222808 0.175467370 0.065278039
#>  [97] 0.175467370 0.175467370 0.175467370 0.104444863

# ------------------
# Moments
# ------------------

mean(D) # Expectation
#> [1] 5
median(D) # Median
#> Warning: The median of a Pois(l) distribution is given by the
#>                     inequality: l - ln2 <= median < l + 1/3. The lower bound is
#>                     returned.
#> [1] 4.306853
mode(D) # Mode
#> [1] 5
var(D) # Variance
#> [1] 5
sd(D) # Standard Deviation
#> [1] 2.236068
skew(D) # Skewness
#> [1] 0.4472136
kurt(D) # Excess Kurtosis
#> [1] 0.2
entro(D) # Entropy
#> Warning: The entropy given is an approximation in the O(1 / l ^ 4) order.
#> [1] 2.204902
finf(D) # Fisher Information Matrix
#> [1] 0.2

# List of all available moments
mom <- moments(D)
#> Warning: The median of a Pois(l) distribution is given by the
#>                     inequality: l - ln2 <= median < l + 1/3. The lower bound is
#>                     returned.
#> Warning: The entropy given is an approximation in the O(1 / l ^ 4) order.
mom$mean # expectation
#> [1] 5

# ------------------
# Point Estimation
# ------------------

ll(D, x)
#> [1] -224.9327
llpois(x, lambda)
#> [1] -224.9327

epois(x, type = "mle")
#> $lambda
#> [1] 5.27
#> 
epois(x, type = "me")
#> $lambda
#> [1] 5.27
#> 

mle(D, x)
#> $lambda
#> [1] 5.27
#> 
me(D, x)
#> $lambda
#> [1] 5.27
#> 
e(D, x, type = "mle")
#> $lambda
#> [1] 5.27
#> 

mle("pois", x) # the distr argument can be a character
#> $lambda
#> [1] 5.27
#> 

# ------------------
# Estimator Variance
# ------------------

vpois(lambda, type = "mle")
#> lambda 
#>      5 
vpois(lambda, type = "me")
#> lambda 
#>      5 

avar_mle(D)
#> lambda 
#>      5 
avar_me(D)
#> lambda 
#>      5 

v(D, type = "mle")
#> lambda 
#>      5