pois: Extension of the Poisson Distribution

Poisson-extensionsR Documentation

Extension of the Poisson Distribution

Description

Score function, hessian, mean, and variance for the Poisson distribution with parameter lambda.

Usage

spois(x, lambda, parameter = "lambda", drop = TRUE)
hpois(x, lambda, parameter = "lambda", drop = TRUE)
mean_pois(lambda, drop =TRUE)
var_pois(lambda, drop =TRUE)

Arguments

x

vector of quantiles.

lambda

vector of (non-negative) means.

parameter

character. Derivatives are computed wrt this paramter. Note: Only "lambda" is implemented.

drop

logical. Should the result be a matrix (drop = FALSE) or should the dimension be dropped (drop = TRUE, the default)?

Details

The Poisson distribution has density

p(x) = \frac{\lambda^x e^{-\lambda}}{x!}

for x = 0, 1, 2, \ldots .

The score function is

s(\lambda) = \frac{x}{\lambda} - 1

The hessian is

h(\lambda) = - \frac{x}{\lambda^2}

Value

spois gives the score function, i.e., the 1st derivative of the log-density wrt lambda and hpois gives the hessian, i.e., the 2nd derivative of the log-density wrt lambda. mean and var give the mean and variance, respectively.

See Also

Poisson encompassing dpois, ppois, qpois and rpois.

Examples

## Simulate some data
set.seed(123)
y <- rpois(50, lambda = 3)

## Plot log-likelihood function
par(mfrow = c(1,3))
ll <- function(x) {sum(dpois(y, x, log = TRUE))}
curve(sapply(x, ll), 1, 5, xlab = expression(lambda), ylab = "",
      main = "Log-likelihood")
abline(v = 3, lty = 3)

## Plot score function
curve(sapply(x, function(x) sum(spois(y, x))), 1, 5,
      xlab = expression(lambda), ylab = "", main = "Score")
abline(h = 0, lty = 3)
abline(v = 3, lty = 3)

## Plot hessian
curve( sapply(x, function(x) sum(hpois(y, x))), 1, 5,
      xlab = expression(lambda), ylab = "", main = "Hessian")
abline(v = 3, lty = 3)

countreg documentation built on Dec. 4, 2023, 3:09 a.m.