Package 'MixedPoisson'

Title: Mixed Poisson Models
Description: The estimation of the parameters in mixed Poisson models.
Authors: Alicja Wolny-Dominiak and Michal Trzesiok
Maintainer: Alicja Wolny-Dominiak <[email protected]>
License: GPL-2
Version: 2.0
Built: 2024-12-14 06:35:27 UTC
Source: CRAN

Help Index


Mixed Poisson Models

Description

The package provides functions, which support to fit parameters of different mixed Poisson models using the Expectation-Maximization (EM) algorithm of estimation, cf. (Ghitany et al., 2012, pp. 6848). In the model the assumptions are: conditional NθN|\theta is of distribution NθPOIS(λθ)N|\theta \sim POIS(\lambda\theta), parameter θ\theta is a random variable distributed according to the density function fθ()f_{\theta}(\cdot), E[θ]=1E[\theta]=1 and λ=exp(xiβ)\lambda=\exp(\mathbf{x}_{i}'\mathbf{\boldsymbol \beta}) – the regression component. The E-step is carried out through the numerical integration using Laquerre quadrature. The M-step estimates the parameters β\beta using GLM Poisson with pseudo values from E-step and mixing parameters using optimize function.

Details

Package: MixedPoisson
Type: Package
Version: 1.0
Date: 2015-07-13
License: GPL-2

Author(s)

Alicja Wolny-Dominiak and Michal Trzesiok

Maintainer: <[email protected]>

References

Karlis, D. (2005). EM algorithm for mixed Poisson and other discrete distributions. Astin Bulletin, 35(01), 3-24. Ghitany, M. E., Karlis, D., Al-Mutairi, D. K., & Al-Awadhi, F. A. (2012). An EM algorithm for multivariate mixed Poisson regression models and its application. Applied Mathematical Sciences, 6(137), 6843-6856.


Estimation of delta parameter of inverse-Gaussian distribution

Description

The function estimates the value of the parameter delta using optimize\texttt{optimize}.

Usage

est.delta(t)

Arguments

t

the vector of values

Details

The form of the distribution is as in the function ll.invGauss\texttt{ll.invGauss}

Value

nu

the estimates of ν\nu

ll.delta.max

the value of loglikehood

Author(s)

Michal Trzesiok

Examples

est.delta(t=c(3,8))

Estimation of gamma parameter of Gamma distribution

Description

The function estimates the value of the parameter gamma using optimize\texttt{optimize}.

Usage

est.gamma(t)

Arguments

t

the vector of values

Details

The form of the distribution is as in the function ll.gamma\texttt{ll.gamma}

Value

gamma

the estimates of γ\gamma

ll.gamma.max

the value of loglikehood

Author(s)

Michal Trzesiok

Examples

est.gamma(t=c(3,8))

Estimation of nu parameter of log-normal distribution

Description

The function estimates the value of the parameter nu using optimize\texttt{optimize}.

Usage

est.nu(t)

Arguments

t

the vector of values

Details

The form of the distribution is as in the function ll.lognorm\texttt{ll.lognorm}

Value

nu

the estimates of ν\nu

ll.nu.max

the value of loglikehood

Author(s)

Michal Trzesiok

Examples

est.nu(t=c(3,8))

Gamma density

Description

The function returns the vector of values of density function for of Gamma distribution with one parameter γ\gamma.

Usage

Gamma.density(theta, gamma.par)

Arguments

theta

the vector of values

gamma.par

the parameter of Gamma distribution

Details

The pdf of Gamma is of the form fθ(θ)=γγΓ(γ)θγ1exp(γθ)f_\theta(\theta)=\frac{\gamma^\gamma}{\Gamma(\gamma)}\theta^{\gamma-1}\exp(-\gamma\theta)

Value

Gamma.density(theta, nu)

the density – the vector of values

Author(s)

Michal Trzesiok

Examples

Gamma.density(c(2,3,5,4,6,7,4), 5)

inverse-Gaussian Density

Description

The function returns the vector of values of density function for of inverse-Gaussian distribution with one parameter δ\delta.

Usage

invGauss.density(theta, delta)

Arguments

theta

the vector of values

delta

the parameter of inverse-Gaussian distribution

Details

The pdf of inverse-Gaussian is of the form fθ(θ)=δ2πexp(δ2)θ32exp(δ22(1θ+θ))f_\theta(\theta)=\frac{\delta}{2\pi}\exp(\delta^2)\theta^{-\frac{3}{2}} \exp(-\frac{\delta^2}{2}(\frac{1}{\theta}+\theta))

Value

invGauss.density(theta, delta)

the density – the vector of values

Author(s)

Michal Trzesiok

Examples

invGauss.density(c(2,3,5,4,6,7,6), 5)

Estimation of Lambda in M-step – Expectation-Maximization (EM) algorithm

Description

The function fits the GLM Poisson with given offset.

Usage

lambda_m_step(variable, X, offset)

Arguments

variable

the vector of numbers

X

model matrix of the form X=model.matrix( regressor)X=model.matrix(~regressor). In the model without regressor the XX sould be defined as X=as.matrix(rep(1,length(variable)))X=as.matrix(rep(1, length(variable)))

offset

offset in GLM Poisson

Details

It fits the GLM Poisson, where variable1variable \sim 1 and the ofsset is given as the vector of the variable's length. The results are used in M-step of EM algorithm, cf. [Karlis, 2012] pp. 6850.

Value

lambda

λ^=β^X\hat \lambda=\hat \beta X

beta

regressor parameters

glm

output of glm\texttt{glm}

Author(s)

Alicja Wolny–Dominiak, Michal Trzesiok

Examples

set.seed(1234)
variable=rpois(50,4)
X=as.matrix(rep(1, length(variable)))
t=pseudo_values(variable, mixing=c("invGauss"), lambda=4, delta=1, n=100)
lambda_m_step(variable, X, offset=t$pseudo_values)

Estimation of starting lambda in Expectation-Maximization (EM) algorithm

Description

The function fits the GLM Poisson without regressors.

Usage

lambda_start(variable, X)

Arguments

variable

the vector of numbers

X

model matrix of the form X=model.matrix( regressor)X=model.matrix(~regressor). In the model without regressor the XX sould be defined as X=as.matrix(rep(1,length(variable)))X=as.matrix(rep(1, length(variable)))

Details

It fits the GLM Poisson, where variable1variable \sim 1. The results are taken as the starting value of EM algorithm.

Value

lambda

λ^=β^X\hat \lambda=\hat \beta X

beta

regressor parameters

glm

output of glm\texttt{glm}

Author(s)

Alicja Wolny–Dominiak, Michal Trzesiok

Examples

set.seed(1234)
variable=rpois(50,4)
X=as.matrix(rep(1, length(variable)))
t=pseudo_values(variable, mixing=c("invGauss"), lambda=4, delta=1, n=100)
lambda_m_step(variable, X, offset=t$pseudo_values)

Gamma Log-likelihood

Description

The function returns the value of log-likelihood function for of Gamma distribution with one parameter γ\gamma.

Usage

ll.gamma(gamma.par, t)

Arguments

gamma.par

γ\gamma parameter

t

the vector of values

Details

The pdf of Gamma is of the form fθ(θ)=γγΓ(γ)θγ1exp(γθ)f_\theta(\theta)=\frac{\gamma^\gamma}{\Gamma(\gamma)}\theta^{\gamma-1}\exp(-\gamma\theta)

Value

ll.gamma

the value

Author(s)

Michal Trzesiok

Examples

ll.gamma(1, c(3,8))

Inverse-Gaussian Log-likelihood

Description

The function returns the value of log-likelihood function for of inverse-Gaussian distribution with one parameter δ\delta.

Usage

ll.invGauss(delta, t)

Arguments

delta

δ\delta parameter

t

the vector of values

Details

The pdf of inverse-Gaussian is of the form fθ(θ)=δ2πexp(δ2)θ32exp(δ22(1θ+θ))f_\theta(\theta)=\frac{\delta}{2\pi}\exp(\delta^2)\theta^{-\frac{3}{2}} \exp(-\frac{\delta^2}{2}(\frac{1}{\theta}+\theta))

Value

ll.invGauss

the value

Author(s)

Michal Trzesiok

Examples

ll.invGauss(1, c(3,8))

Log-normal Log-likelihood

Description

The function returns the value of log-likelihood function of log-normal distribution with one parameter ν\nu.

Usage

ll.lognorm(nu, t)

Arguments

nu

ν\nu parameter

t

the vector of values

Details

The pdf of log-normal is of the form fθ(θ)=12πνθexp[(log(θ)+ν22)22ν2]f_\theta(\theta)=\frac{1}{\sqrt{2\pi\nu\theta}}\exp[-\frac{(\log(\theta)+\frac{\nu^2}{2})^2}{2\nu^2}]

Value

ll.lognorm

the value

Author(s)

Michal Trzesiok

Examples

ll.lognorm(1, c(3,8))

Log-normal Density

Description

The function returns the vector of values of density function for of log-normal distribution with one parameter ν\nu.

Usage

lognorm.density(theta, nu)

Arguments

theta

the vector of values

nu

the parameter of log-normal distribution

Details

The pdf of log-normal is of the form fθ(θ)=12πνθexp[(log(θ)+ν22)22ν2]f_\theta(\theta)=\frac{1}{\sqrt{2\pi\nu\theta}}\exp[-\frac{(\log(\theta)+\frac{\nu^2}{2})^2}{2\nu^2}]

Value

lognorm.density(theta, nu)

the density – the vector of values

Author(s)

Michal Trzesiok

Examples

lognorm.density(c(2,3,5,4,6,7,6), 5)

Poisson-Gamma Distribution (Negative-Binomial)

Description

The function fits a mixed Poisson distribution, in which the random parameter follows Gamma distribution (the negative-binomial distribution). As teh method of estimation Expectation-maximization algorithm is used. In M-step the analytical formulas taken from [Karlis, 2005] are applied.

Usage

pg.dist(variable, alpha.start, beta.start, epsylon)

Arguments

variable

The count variable.

alpha.start

The starting value of the parameter alpha. Default to 1.

beta.start

The starting value of the parameter beta. Default to 0.3

epsylon

Default to epsylon = 10^(-8)

Details

This function provides estimated parameters of the model NλPoisson(λ)N|\lambda \sim Poisson(\lambda) where λ\lambda parameter is also a random variable follows Gamma distribution with hiperparameters α,β\alpha, \beta. The pdf of Gamma is of the form fλ(λ)=λα1exp(βλ)βλΓ(α)f_\lambda(\lambda)=\frac{\lambda^{\alpha-1}\exp(-\beta\lambda)\beta^\lambda}{\Gamma(\alpha)}.

Value

alpha

the parameter of mixing Gamma distribution

beta

the parameter of mixing Gamma distribution

theta

the value 1/beta

n.iter

the number of steps in EM algorithm

References

Karlis, D. (2005). EM algorithm for mixed Poisson and other discrete distributions. Astin bulletin, 35(01), 3-24.

Examples

library(MASS)
pGamma1 = pg.dist(variable=quine$Days)
print(pGamma1)

Poisson-Lindley Distribution

Description

The function fits a mixed Poisson distribution, in which the random parameter follows Lindley distribution. As teh method of estimation Expectation-maximization algorithm is used.

Usage

pl.dist(variable, p.start, epsylon)

Arguments

variable

The count variable.

p.start

The starting value of p parameter. Default to 0.1.

epsylon

Default to epsylon = 10^(-8)

Details

This function provides estimated parameters of the model NλPoisson(λ)N|\lambda \sim Poisson(\lambda) where λ\lambda parameter is also a random variable follows Lindley distribution with hiperparameter pp. The pdf of Lindley is of the form fλ(λ)=p2p+1(λ+1)exp(λp)f_\lambda(\lambda)=\frac{p^2}{p+1}(\lambda+1)\exp(-\lambda p).

Value

p

the parameter of mixing Lindley distribution

n.iter

the number of steps in EM algorithm

References

Karlis, D. (2005). EM algorithm for mixed Poisson and other discrete distributions. Astin bulletin, 35(01), 3-24.

Examples

library(MASS)
pLindley = pl.dist(variable=quine$Days)
print(pLindley)

Pseudo values – Expectation-Maximization (EM) algorithm

Description

The function returns the pseudo values tit_i defined as the conditional expectation E[θik1,...,kn]E[\theta_i|k_1,...,k_n], where k1,...,knk_1,...,k_n are realizations of the count variable N.

Usage

pseudo_values(variable, mixing, lambda, gamma.par, nu, delta, n)

Arguments

variable

the vector of numbers

mixing

the name of mixing distribution – "Gamma", "lognorm", "invGauss"

lambda

λ\lambda parameter in mixed Poisson model

gamma.par

γ\gamma parameter in Gamma mixing distribution

nu

ν\nu parameter in log-normal mixing distribution

delta

δ\delta parameter in inverse-Gaussian mixing distribution

n

The integer value for the Laguerre quadrature. Default to 100

Details

The function calculates the vector of pseudo values ti=E[θik1,...,kn]t_i=E[\theta_i|k_1,...,k_n] in E-step of EM algorithm. It applies the numerical integration using laguerre.quadraturelaguerre.quadrature in the nominator and the denominator of the formula

The proper parameter γ\gamma, ν\nu, δ\delta should be chosen according to the mixing distribution.

Value

pseudo_values

pseudo values t1,...,tnt_1,...,t_n

nominator

nominator in the formula

denominator

denominator in the formula

Author(s)

Alicja Wolny–Dominiak, Michal Trzesiok

Examples

variable=rpois(30,4)
pseudo_values(variable, mixing="Gamma", lambda=4, gamma.par=0.7, n=100)