Poisson-extensions | R Documentation |
Score function, hessian, mean, and variance
for the Poisson distribution
with parameter lambda
.
spois(x, lambda, parameter = "lambda", drop = TRUE)
hpois(x, lambda, parameter = "lambda", drop = TRUE)
mean_pois(lambda, drop =TRUE)
var_pois(lambda, drop =TRUE)
x |
vector of quantiles. |
lambda |
vector of (non-negative) means. |
parameter |
character. Derivatives are computed wrt this
paramter. Note: Only |
drop |
logical. Should the result be a matrix ( |
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}
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.
Poisson encompassing dpois
, ppois
,
qpois
and rpois
.
## 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.