Package 'tpn'

Title: Truncated Positive Normal Model and Extensions
Description: Provide data generation and estimation tools for the truncated positive normal (tpn) model discussed in Gomez, Olmos, Varela and Bolfarine (2018) <doi:10.1007/s11766-018-3354-x>, the slash tpn distribution discussed in Gomez, Gallardo and Santoro (2021) <doi:10.3390/sym13112164>, the bimodal tpn distribution discussed in Gomez et al. (2022) <doi:10.3390/sym14040665> and the flexible tpn model.
Authors: Diego Gallardo [aut, cre], Hector J. Gomez [aut], Yolanda M. Gomez [aut]
Maintainer: Diego Gallardo <[email protected]>
License: GPL (>= 2)
Version: 1.8
Built: 2024-11-06 06:26:40 UTC
Source: CRAN

Help Index


Bimodal truncated positive normal

Description

Density, distribution function and random generation for the bimodal truncated positive normal (btpn) discussed in Gomez et al. (2022).

Usage

dbtpn(x, sigma, lambda, eta, log = FALSE)
pbtpn(x, sigma, lambda, eta, lower.tail=TRUE, log=FALSE)
rbtpn(n, sigma, lambda, eta)

Arguments

x

vector of quantiles

n

number of observations

sigma

scale parameter for the distribution

lambda

shape parameter for the distribution

eta

shape parameter for the distribution

log

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

lower.tail

logical; if TRUE (default), probabilities are P[X <= x] otherwise, P[X > x].

Details

Random generation is based on the stochastic representation of the model, i.e., the product between a tpn (see Gomez et al. 2018) and a dichotomous variable assuming values (1+ϵ)-(1+\epsilon) and 1ϵ1-\epsilon with probabilities (1+ϵ)/2(1+\epsilon)/2 and (1ϵ)/2(1-\epsilon)/2, respectively.

Value

dbtpn gives the density, pbtpn gives the distribution function and rbtpn generates random deviates.

The length of the result is determined by n for rbtpn, and is the maximum of the lengths of the numerical arguments for the other functions.

The numerical arguments other than n are recycled to the length of the result. Only the first elements of the logical arguments are used.

A variable have btpn distribution with parameters σ>0,λ\sigma>0, \lambda \in R and η\eta \in R if its probability density function can be written as

f(y;σ,λ,q)=ϕ(xσ(1+ϵ)+λ)2σΦ(λ),y<0,f(y; \sigma, \lambda, q) = \frac{\phi\left(\frac{x}{\sigma(1+\epsilon)}+\lambda\right)}{2\sigma\Phi(\lambda)}, y<0,

and

f(y;σ,λ,q)=ϕ(xσ(1ϵ)λ)2σΦ(λ),y0,f(y; \sigma, \lambda, q) = \frac{\phi\left(\frac{x}{\sigma(1-\epsilon)}-\lambda\right)}{2\sigma\Phi(\lambda)}, y\geq 0,

where ϵ=η/1+η2\epsilon=\eta/\sqrt{1+\eta^2} and ϕ()\phi(\cdot) and Φ()\Phi(\cdot) denote the probability density function and the cumulative distribution function for the standard normal distribution, respectively.

Author(s)

Gallardo, D.I., Gomez, H.J. and Gomez, Y.M.

References

Gomez, H.J., Caimanque, W., Gomez, Y.M., Magalhaes, T.M., Concha, M., Gallardo, D.I. (2022) Bimodal Truncation Positive Normal Distribution. Symmetry, 14, 665.

Gomez, H.J., Olmos, N.M., Varela, H., Bolfarine, H. (2018). Inference for a truncated positive normal distribution. Applied Mathemetical Journal of Chinese Universities, 33, 163-176.

Examples

dbtpn(c(1,2), sigma=1, lambda=-1, eta=2)
pbtpn(c(1,2), sigma=1, lambda=-1, eta=2)
rbtpn(n=10, sigma=1, lambda=-1, eta=2)

Choose a distribution in the flexible truncated positive class of models

Description

Provide model selection for a given data set in the flexible truncated positive class of models

Usage

choose.fts(y, criteria = "AIC")

Arguments

y

positive vector of responses

criteria

model criteria for the selection: AIC (default) or BIC.

Details

The function fits the truncated positive normal, truncated positive laplace, truncated positive Cauchy and truncated positive logistic models and select the model which provides the lower criteria (AIC or BIC).

Value

A list with the following components

AIC

a vector with the AIC for the different truncated positive fitted models: normal, laplace, cauchy and logistic.

selected

the selected model

estimate

the estimated for sigma and lambda and the respective standard errors (s.e.)

conv

the code related to the convergence for the optim function. 0 if the convergence was attached.

logLik

log-likelihood function evaluated in the estimated parameters.

AIC

Akaike's criterion.

BIC

Schwartz's criterion.

Author(s)

Gallardo, D.I., Gomez, H.J. and Gomez, Y.M.

References

Gomez, H.J., Gomez, H.W., Santoro, K.I., Venegas, O., Gallardo, D.I. (2022). A Family of Truncation Positive Distributions. Submitted.

Gomez, H.J., Olmos, N.M., Varela, H., Bolfarine, H. (2018). Inference for a truncated positive normal distribution. Applied Mathemetical Journal of Chinese Universities, 33, 163-176.

Examples

set.seed(2021)
y=rfts(n=100,sigma=10,lambda=1,dist="logis")
choose.fts(y)

Parameter estimation for the btpn model

Description

Perform the parameter estimation for the bimodal truncated positive normal (btpn) discussed in Gomez et al. (2022). Estimated errors are computed based on the hessian matrix.

Usage

est.btpn(y)

Arguments

y

the response vector. All the values must be positive.

Details

A variable have btpn distribution with parameters σ>0,λ\sigma>0, \lambda \in R and η\eta \in R if its probability density function can be written as

f(y;σ,λ,q)=ϕ(xσ(1+ϵ)+λ)2σΦ(λ),y<0,f(y; \sigma, \lambda, q) = \frac{\phi\left(\frac{x}{\sigma(1+\epsilon)}+\lambda\right)}{2\sigma\Phi(\lambda)}, y<0,

and

f(y;σ,λ,q)=ϕ(xσ(1ϵ)λ)2σΦ(λ),y0,f(y; \sigma, \lambda, q) = \frac{\phi\left(\frac{x}{\sigma(1-\epsilon)}-\lambda\right)}{2\sigma\Phi(\lambda)}, y\geq 0,

where ϵ=η/1+η2\epsilon=\eta/\sqrt{1+\eta^2} and ϕ()\phi(\cdot) and Φ()\Phi(\cdot) denote the probability density function and the cumulative distribution function for the standard normal distribution, respectively.

Value

A list with the following components

estimate

A matrix with the estimates and standard errors

iter

Iterations in which the convergence were attached.

logLik

log-likelihood function evaluated in the estimated parameters.

AIC

Akaike's criterion.

BIC

Schwartz's criterion.

Note

A warning is presented if the estimated hessian matrix is not invertible.

Author(s)

Gallardo, D.I., Gomez, H.J. and Gomez, Y.M.

References

Gomez, H.J., Caimanque, W., Gomez, Y.M., Magalhaes, T.M., Concha, M., Gallardo, D.I. (2022) Bimodal Truncation Positive Normal Distribution. Symmetry, 14, 665.

Examples

set.seed(2021)
y=rbtpn(n=100,sigma=10,lambda=1,eta=1.5)
est.btpn(y)

Parameter estimation for the ftp class of distributions

Description

Perform the parameter estimation for the Flexible truncated positive (fts) class discussed in Gomez et al. (2022) based on maximum likelihood estimation. Estimated errors are computed based on the hessian matrix.

Usage

est.fts(y, dist="norm")

Arguments

y

the response vector. All the values must be positive.

dist

standard symmetrical distribution. Avaliable options: norm (default), logis, cauchy and laplace.

Details

A variable has fts distribution with parameters σ>0\sigma>0 and λ\lambda \in R if its probability density function can be written as

f(y;σ,λ,q)=g0(yσλ)σG0(λ),y>0,f(y; \sigma, \lambda, q) = \frac{g_0(\frac{y}{\sigma}-\lambda)}{\sigma G_0(\lambda)}, y>0,

where g0()g_0(\cdot) and G0()G_0(\cdot) denote the pdf and cdf for the specified distribution. The case where g0()g_0(\cdot) and G0()G_0(\cdot) are from the standard normal model is known as the truncated positive normal model discussed in Gomez et al. (2018).

Value

A list with the following components

estimate

A matrix with the estimates and standard errors

dist

distribution specified

conv

the code related to the convergence for the optim function. 0 if the convergence was attached.

logLik

log-likelihood function evaluated in the estimated parameters.

AIC

Akaike's criterion.

BIC

Schwartz's criterion.

Note

A warning is presented if the estimated hessian matrix is not invertible.

Author(s)

Gallardo, D.I. and Gomez, H.J.

References

Gomez, H.J., Gomez, H.W., Santoro, K.I., Venegas, O., Gallardo, D.I. (2022). A Family of Truncation Positive Distributions. Submitted.

Gomez, H.J., Olmos, N.M., Varela, H., Bolfarine, H. (2018). Inference for a truncated positive normal distribution. Applied Mathemetical Journal of Chinese Universities, 33, 163-176.

Examples

set.seed(2021)
y=rfts(n=100,sigma=10,lambda=1,dist="logis")
est.fts(y,dist="logis")

Parameter estimation for the stpn model

Description

Perform the parameter estimation for the slash truncated positive normal (stpn) discussed in Gomez, Gallardo and Santoro (2021) based on the EM algorithm. Estimated errors are computed based on the Louis method to approximate the hessian matrix.

Usage

est.stpn(y, sigma0=NULL, lambda0=NULL, q0=NULL, prec = 0.001, 
     max.iter = 1000)

Arguments

y

the response vector. All the values must be positive.

sigma0, lambda0, q0

initial values for the EM algorithm for sigma, lambda and q. If they are omitted, by default sigma0 is defined as the root of the mean of the y^2, lambda as 0 and q as 3.

prec

the precision defined for each parameter. By default is 0.001.

max.iter

the maximum iterations for the EM algorithm. By default is 1000.

Details

A variable has stpn distribution with parameters σ>0,λ\sigma>0, \lambda \in R and q>0q>0 if its probability density function can be written as

f(y;σ,λ,q)=01t1/qσϕ(yt1/qσλ)dt,y>0,f(y; \sigma, \lambda, q) = \int_0^1 t^{1/q} \sigma \phi(y t^{1/q} \sigma-\lambda)dt, y>0,

where ϕ()\phi(\cdot) denotes the density function for the standard normal distribution.

Value

A list with the following components

estimate

A matrix with the estimates and standard errors

iter

Iterations in which the convergence were attached.

logLik

log-likelihood function evaluated in the estimated parameters.

AIC

Akaike's criterion.

BIC

Schwartz's criterion.

Note

A warning is presented if the estimated hessian matrix is not invertible.

Author(s)

Gallardo, D.I. and Gomez, H.J.

References

Gomez, H., Gallardo, D.I., Santoro, K. (2021) Slash Truncation Positive Normal Distribution: with application using the EM algorithm. Symmetry, 13, 2164.

Examples

set.seed(2021)
y=rstpn(n=100,sigma=10,lambda=1,q=2)
est.stpn(y)

Parameter estimation for the tpn

Description

Perform the parameter estimation for the truncated positive normal (tpn) discussed in Gomez et al. (2018) based on maximum likelihood estimation. Estimated errors are computed based on the hessian matrix.

Usage

est.tpn(y)

Arguments

y

the response vector. All the values must be positive.

Details

A variable have tpn distribution with parameters σ>0\sigma>0 and λ\lambda \in R if its probability density function can be written as

f(y;σ,λ,q)=ϕ(yσλ)σΦ(λ),y>0,f(y; \sigma, \lambda, q) = \frac{\phi\left(\frac{y}{\sigma}-\lambda\right)}{\sigma \Phi(\lambda)}, y>0,

where ϕ()\phi(\cdot) and Φ()\Phi(\cdot) denote the density and cumultative distribution functions for the standard normal distribution.

Value

A list with the following components

estimate

A matrix with the estimates and standard errors

logLik

log-likelihood function evaluated in the estimated parameters.

AIC

Akaike's criterion.

BIC

Schwartz's criterion.

Note

A warning is presented if the estimated hessian matrix is not invertible.

Author(s)

Gallardo, D.I. and Gomez, H.J.

References

Gomez, H.J., Olmos, N.M., Varela, H., Bolfarine, H. (2018). Inference for a truncated positive normal distribution. Applied Mathemetical Journal of Chinese Universities, 33, 163-176.

Examples

set.seed(2021)
y=rtpn(n=100,sigma=10,lambda=1)
est.tpn(y)

Parameter estimation for the utpn model

Description

Perform the parameter estimation for the unit truncated positive normal (utpn) type 1, 2, 3 or 4, parameterized in terms of the quantile based on maximum likelihood estimation. Estimated errors are computed based on the hessian matrix.

Usage

est.utpn(y, x=NULL, type=1, link="logit", q=0.5)

Arguments

y

the response vector. All the values must be positive.

x

the covariates vector.

type

to distinguish the type of the utpn model: 1 (default), 2, 3 or 4.

link

link function to be used for the covariates: logit (default).

q

quantile of the distribution to be modelled.

Value

A list with the following components

estimate

A matrix with the estimates and standard errors

logLik

log-likelihood function evaluated in the estimated parameters.

AIC

Akaike's criterion.

BIC

Schwartz's criterion.

Note

A warning is presented if the estimated hessian matrix is not invertible.

Author(s)

Gallardo, D.I.

References

Gomez, H.J., Olmos, N.M., Varela, H., Bolfarine, H. (2018). Inference for a truncated positive normal distribution. Applied Mathemetical Journal of Chinese Universities, 33, 163-176.

Examples

set.seed(2021)
y=rutpn(n=100,sigma=10,lambda=1)
est.utpn(y)

Flexible truncated positive normal

Description

Density, distribution function and random generation for the flexible truncated positive (ftp) class discussed in Gomez et al. (2022).

Usage

dfts(x, sigma, lambda, dist="norm", log = FALSE)
pfts(x, sigma, lambda, dist="norm", lower.tail=TRUE, log.p=FALSE)
qfts(p, sigma, lambda, dist="norm")
rfts(n, sigma, lambda, dist="norm")

Arguments

x

vector of quantiles

p

vector of probabilities

n

number of observations

sigma

scale parameter for the distribution

lambda

shape parameter for the distribution

dist

standard symmetrical distribution. Avaliable options: norm (default), logis, cauchy and laplace.

log, log.p

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

lower.tail

logical; if TRUE (default), probabilities are P[X <= x] otherwise, P[X > x].

Details

Random generation is based on the inverse transformation method.

Value

dfts gives the density, pfts gives the distribution function, qfts gives the quantile function and rfts generates random deviates.

The length of the result is determined by n for rbtpn, and is the maximum of the lengths of the numerical arguments for the other functions.

The numerical arguments other than n are recycled to the length of the result. Only the first elements of the logical arguments are used.

A variable have fts distribution with parameters σ>0\sigma>0 and λ\lambda \in R if its probability density function can be written as

f(y;σ,λ,q)=g0(yσλ)σG0(λ),y>0,f(y; \sigma, \lambda, q) = \frac{g_0(\frac{y}{\sigma}-\lambda)}{\sigma G_0(\lambda)}, y>0,

where g0()g_0(\cdot) and G0()G_0(\cdot) denote the pdf and cdf for the specified distribution. The case where g0()g_0(\cdot) and G0()G_0(\cdot) are from the standard normal model is known as the truncated positive normal model discussed in Gomez et al. (2018).

Author(s)

Gallardo, D.I., Gomez, H.J. and Gomez, Y.M.

References

Gomez, H.J., Gomez, H.W., Santoro, K.I., Venegas, O., Gallardo, D.I. (2022). A Family of Truncation Positive Distributions. Submitted.

Gomez, H.J., Olmos, N.M., Varela, H., Bolfarine, H. (2018). Inference for a truncated positive normal distribution. Applied Mathemetical Journal of Chinese Universities, 33, 163-176.

Examples

dfts(c(1,2), sigma=1, lambda=1, dist="logis")
pfts(c(1,2), sigma=1, lambda=1, dist="logis")
rfts(n=10, sigma=1, lambda=1, dist="logis")

Slash truncated positive normal

Description

Density, distribution function and random generation for the slash truncated positive normal (stpn) discussed in Gomez, Gallardo and Santoro (2021).

Usage

dstpn(x, sigma, lambda, q, log = FALSE)
pstpn(x, sigma, lambda, q, lower.tail=TRUE, log=FALSE)
rstpn(n, sigma, lambda, q)

Arguments

x

vector of quantiles

n

number of observations

sigma

scale parameter for the distribution

lambda

shape parameter for the distribution

q

shape parameter for the distribution

log

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

lower.tail

logical; if TRUE (default), probabilities are P[X <= x] otherwise, P[X > x].

Details

Random generation is based on the stochastic representation of the model, i.e., the quotient between a tpn (see Gomez et al. 2018) and a beta random variable.

Value

dstpn gives the density, pstpn gives the distribution function and rstpn generates random deviates.

The length of the result is determined by n for rstpn, and is the maximum of the lengths of the numerical arguments for the other functions.

The numerical arguments other than n are recycled to the length of the result. Only the first elements of the logical arguments are used.

A variable has stpn distribution with parameters σ>0,λ\sigma>0, \lambda \in R and q>0q>0 if its probability density function can be written as

f(y;σ,λ,q)=01t1/qσϕ(yt1/qσλ)dt,y>0,f(y; \sigma, \lambda, q) = \int_0^1 t^{1/q} \sigma \phi(y t^{1/q} \sigma-\lambda)dt, y>0,

where ϕ()\phi(\cdot) denotes the density function for the standard normal distribution.

Author(s)

Gallardo, D.I. and Gomez, H.J.

References

Gomez, H., Gallardo, D.I., Santoro, K. (2021) Slash Truncation Positive Normal Distribution: with application using the EM algorithm. Symmetry, 13, 2164.

Gomez, H.J., Olmos, N.M., Varela, H., Bolfarine, H. (2018). Inference for a truncated positive normal distribution. Applied Mathemetical Journal of Chinese Universities, 33, 163-176.

Examples

dstpn(c(1,2), sigma=1, lambda=-1, q=2)
pstpn(c(1,2), sigma=1, lambda=-1, q=2)
rstpn(n=10, sigma=1, lambda=-1, q=2)

Truncated positive normal

Description

Density, distribution function and random generation for the slash truncated positive normal (stpn) discussed in Gomez, Gallardo and Santoro (2021).

Usage

dtpn(x, sigma, lambda, log = FALSE)
ptpn(x, sigma, lambda, lower.tail=TRUE, log=FALSE)
rtpn(n, sigma, lambda)

Arguments

x

vector of quantiles

n

number of observations

sigma

scale parameter for the distribution

lambda

shape parameter for the distribution

log

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

lower.tail

logical; if TRUE (default), probabilities are P[X <= x] otherwise, P[X > x].

Details

Random generation is based on the inverse transformation method.

Value

dtpn gives the density, ptpn gives the distribution function and rtpn generates random deviates.

The length of the result is determined by n for rtpn, and is the maximum of the lengths of the numerical arguments for the other functions.

The numerical arguments other than n are recycled to the length of the result. Only the first elements of the logical arguments are used.

A variable have tpn distribution with parameters σ>0\sigma>0 and λ\lambda \in R if its probability density function can be written as

f(y;σ,λ,q)=ϕ(yσλ)σΦ(λ),y>0,f(y; \sigma, \lambda, q) = \frac{\phi\left(\frac{y}{\sigma}-\lambda\right)}{\sigma \Phi(\lambda)}, y>0,

where ϕ()\phi(\cdot) and Φ()\Phi(\cdot) denote the density and cumultative distribution functions for the standard normal distribution.

Author(s)

Gallardo, D.I. and Gomez, H.J.

References

Gomez, H.J., Olmos, N.M., Varela, H., Bolfarine, H. (2018). Inference for a truncated positive normal distribution. Applied Mathemetical Journal of Chinese Universities, 33, 163-176.

Examples

dtpn(c(1,2), sigma=1, lambda=-1)
ptpn(c(1,2), sigma=1, lambda=-1)
rtpn(n=10, sigma=1, lambda=-1)

Truncated positive normal

Description

Density, distribution function and random generation for the unit truncated positive normal (utpn) type 1 or 2 discussed in Gomez, Gallardo and Santoro (2021).

Usage

dutpn(x, sigma = 1, lambda = 0, type = 1, log = FALSE)
putpn(x, sigma = 1, lambda = 0, type = 1, lower.tail = TRUE, log = FALSE)
qutpn(p, sigma = 1, lambda = 0, type = 1)
rutpn(n, sigma = 1, lambda = 0, type = 1)

Arguments

x

vector of quantiles

n

number of observations

p

vector of probabilities

sigma

scale parameter for the distribution

lambda

shape parameter for the distribution

type

to distinguish the type of the utpn model: 1 (default) or 2.

log

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

lower.tail

logical; if TRUE (default), probabilities are P[X <= x] otherwise, P[X > x].

Details

Random generation is based on the inverse transformation method.

Value

dutpn gives the density, putpn gives the distribution function, qutpn provides the quantile function and rutpn generates random deviates.

The length of the result is determined by n for rtpn, and is the maximum of the lengths of the numerical arguments for the other functions.

The numerical arguments other than n are recycled to the length of the result. Only the first elements of the logical arguments are used.

A variable has utpn distribution with scale parameter σ>0\sigma>0 and shape parameter λ\lambda \in R if its probability density function can be written as

f(y;σ,λ)=ϕ(1yσyλ)σy2Φ(λ),y>0,(type 1),f(y; \sigma, \lambda) = \frac{\phi\left(\frac{1-y}{\sigma y}-\lambda\right)}{\sigma y^2\Phi(\lambda)}, y>0, \mbox{(type 1),}

f(y;σ,λ)=ϕ(yσ(1y)λ)σ(1y)2Φ(λ),y>0,(type 2),f(y; \sigma, \lambda) = \frac{\phi\left(\frac{y}{\sigma (1-y)}-\lambda\right)}{\sigma (1-y)^2\Phi(\lambda)}, y>0, \mbox{(type 2),}

f(y;σ,λ)=ϕ(log(y)σ+λ)σyΦ(λ),y>0,(type 3),f(y; \sigma, \lambda) = \frac{\phi\left(\frac{\log(y)}{\sigma}+\lambda\right)}{\sigma y\Phi(\lambda)}, y>0, \mbox{(type 3),}

f(y;σ,λ)=ϕ(log(1y)σ+λ)σ(1y)Φ(λ),y>0,(type 4),f(y; \sigma, \lambda) = \frac{\phi\left(\frac{\log(1-y)}{\sigma}+\lambda\right)}{\sigma (1-y)\Phi(\lambda)}, y>0, \mbox{(type 4),}

where ϕ()\phi(\cdot) and Φ()\Phi(\cdot) denote the density and cumulative distribution functions for the standard normal distribution.

Author(s)

Gallardo, D.I.

References

Gomez, H.J., Olmos, N.M., Varela, H., Bolfarine, H. (2018). Inference for a truncated positive normal distribution. Applied Mathemetical Journal of Chinese Universities, 33, 163-176.

Examples

dutpn(c(0.1,0.2), sigma=1, lambda=-1)
putpn(c(0.1,0.2), sigma=1, lambda=-1)
rutpn(n=10, sigma=1, lambda=-1)