Package 'ztpln'

Title: Zero-Truncated Poisson Lognormal Distribution
Description: Functions for obtaining the density, random variates and maximum likelihood estimates of the Zero-truncated Poisson lognormal distribution and their mixture distribution.
Authors: Masatoshi Katabuchi
Maintainer: Masatoshi Katabuchi <[email protected]>
License: MIT + file LICENSE
Version: 0.1.2.9000
Built: 2025-03-03 04:19:11 UTC
Source: https://github.com/mattocci27/ztpln

Help Index


The zero-truncated compund poisson-lognormal distributions

Description

Density function and random generation for Zero-Trauncated Poisson Lognormal distribution with parameters mu and sd sig.

Usage

dztpln(x, mu, sig, log = FALSE, type1 = TRUE)

rztpln(n, mu, sig, type1 = TRUE)

Arguments

x

vector of (non-negative integer) quantiles.

mu

mean of lognormal distribution.

sig

standard deviation of lognormal distribution.

log

logical; if TRUE, probabilities p are given as log(p).

type1

logical; if TRUE, Use type 1 ztpln else use type 2.

n

number of random values to return.

Details

A compound Poisson-lognormal distribution is a Poisson probability distribution where its parameter λ\lambda is a random variable with lognormal distribution, that is to say logλlog\lambda are normally distributed with mean μ\mu and variance σ2\sigma^2 (Bulmer 1974). The zero-truncated Poisson-lognormal distribution can be derived from a zero-truncated Poisson distribution.

Type 1 ZTPLN truncates zero based on Poisson-lognormal distribution and type 2 ZTPLN truncates zero based on zero-truncated Poisson distribution. For mathematical details, please see vignette("ztpln")

Value

dztpln gives the (log) density and rztpln generates random variates.

References

Bulmer, M. G. 1974. On Fitting the Poisson Lognormal Distribution to Species-Abundance Data. Biometrics 30:101-110.

See Also

dztplnm

Examples

rztpln(n = 10, mu = 0, sig = 1, type1 = TRUE)
rztpln(n = 10, mu = 6, sig = 4, type1 = TRUE)
dztpln(x = 1:5, mu = 1, sig = 2)

The zero-truncated compund poisson-lognormal distributions mixture

Description

Density function and random generation for Zero-Truncated Poisson Lognormal distribution with parameters mu, sig, and theta.

Usage

dztplnm(x, mu, sig, theta, log = FALSE, type1 = TRUE)

rztplnm(n, mu, sig, theta, type1 = TRUE)

Arguments

x

vector of (non-negative integer) quantiles.

mu

vector of mean of lognormal distribution in sample.

sig

vector standard deviation of lognormal distribution in sample.

theta

vector of mixture weights

log

logical; if TRUE, probabilities p are given as log(p).

type1

logical; if TRUE, Use type 1 ztpln else use type 2.

n

number of random values to return.

Details

Type 1 ZTPLN truncates zero based on Poisson-lognormal distribution and type 2 ZTPLN truncates zero based on zero-truncated Poisson distribution. For mathematical details, please see vignette("ztpln")

Value

dztplnm gives the (log) density and rztplnm generates random variates. function, qpois gives the quantile function, and rpois generates random deviates.

See Also

dztpln

Examples

rztplnm(n = 100, mu = c(0, 5), sig = c(1, 2), theta = c(0.2, 0.8))
dztplnm(x = 1:100, mu = c(0, 5), sig = c(1, 2), theta = c(0.2, 0.8))
dztplnm(x = 1:100, mu = c(0, 5), sig = c(1, 2), theta = c(0.2, 0.8), type1 = FALSE)

MLE for the Zero-truncated Poisson Lognormal distribution

Description

ztplnMLE fits the Zero-truncated Poisson lognormal distribution to data and estimates parameters mean mu and standard deviation sig in the lognormal distribution

Usage

ztplnMLE(
  n,
  lower_mu = 0,
  upper_mu = log(max(n)),
  lower_sig = 0.001,
  upper_sig = 10,
  type1 = TRUE
)

Arguments

n

a integer vector of counts

lower_mu, upper_mu

numeric values of lower and upper bounds for mean of the variables's natrual logarithm.

lower_sig, upper_sig

numeric values of lower and upper bounds for standard deviatoin of the variables's natrual logarithm

type1

logical; if TRUE, Use type 1 ztpln else use type 2.

Details

The function searches the maximum likelihood estimates of mean mu and standard deviation sig using the optimization procedures in nlminb.

Value

convergence

An integer code. 0 indicates successful convergence.

iterations

Number of iterations performed.

message

A character string giving any additional information returned by the optimizer, or NULL. For details, see PORT documentation.

evaluation

Number of objective function and gradient function evaluations

mu

Maximum likelihood estimates of mu

sig

Maximum likelihood estimates of sig

loglik

loglikelihood

Examples

y <- rztpln(100, 3, 2)
ztplnMLE(y)

MLE for the Zero-truncated Poisson Lognormal mixture distribtuion

Description

ztplnmMLE fits the Zero-truncated Poisson lognormal mixture distribution to data and estimates parameters mean mu, standard deviation sig and mixture weight theta in the lognormal distribution.

Usage

ztplnmMLE(
  n,
  K = 2,
  lower_mu = rep(0, K),
  upper_mu = rep(log(max(n)), K),
  lower_sig = rep(0.001, K),
  upper_sig = rep(10, K),
  lower_theta = rep(0.001, K),
  upper_theta = rep(0.999, K),
  type1 = TRUE,
  message = FALSE
)

Arguments

n

a vector of counts

K

number of components

lower_mu, upper_mu

numeric values of lower and upper bounds for mean of the variables's natural logarithm.

lower_sig, upper_sig

numeric values of lower and upper bounds for standard deviation of the variables's natural logarithm

lower_theta, upper_theta

numeric values of lower and upper bounds for mixture weights.

type1

logical; if TRUE, Use type 1 ztpln else use type 2.

message

mean of lognormal distribution in sample 3.

Details

The function searches the maximum likelihood estimators of mean vector mu, standard deviation vector sig and mixture weight vector theta using the optimization procedures in nlminb.

Value

convergence

An integer code. 0 indicates successful convergence.

iterations

Number of iterations performed.

message

A character string giving any additional information returned by the optimizer, or NULL. For details, see PORT documentation.

evaluation

Number of objective function and gradient function evaluations

mu

Maximum likelihood estimates of mu

sig

Maximum likelihood estimates of sig

theta

Maximum likelihood estimates of theta

loglik

loglikelihood

Examples

y <- rztplnm(100, c(1, 10), c(2, 1), c(0.2, 0.8))
ztplnmMLE(y)