Package 'genlogis'

Title: Generalized Logistic Distribution
Description: Provides basic distribution functions for a generalized logistic distribution proposed by Rathie and Swamee (2006) <https://www.rroij.com/open-access/on-new-generalized-logistic-distributions-and-applicationsbarreto-fhs-mota-jma-and-rathie-pn-.pdf>. It also has an interactive 'RStudio' plot for better guessing dynamically of initial values for ease of included optimization and simulating.
Authors: Eduardo Hellas [aut, cre], Eduardo Monteiro [aut, ctb]
Maintainer: Eduardo Hellas <[email protected]>
License: GPL-3
Version: 1.0.2
Built: 2025-01-26 03:40:25 UTC
Source: https://github.com/pinduzera/genlogis

Help Index


The Generalized logistic distribution

Description

Density, distribution function, quantile function and random generation a generalized logistic distribution.

Usage

pgenlog(q, a = sqrt(2/pi), b = 0.5, p = 2, mu = 0, lower.tail = TRUE)

dgenlog(x, a = sqrt(2/pi), b = 0.5, p = 2, mu = 0)

qgenlog(k, a = sqrt(2/pi), b = 0.5, p = 2, mu = 0, lower.tail = TRUE)

rgenlog(n, a = sqrt(2/pi), b = 0.5, p = 2, mu = 0)

Arguments

a, b, p

parameters 0\ge 0, with restrictions.*

mu

mu parameter

lower.tail

logical; if TRUE (default), probabilities are P[Xx]P[X \le x] otherwise, P[X>x]P[X > x].

x, q

vector of quantiles.

k

vector of probabilities.

n

number of observations. If length(n) > 1, the length is taken to be the number required

Details

The used distribution for this package is given by:

f(x)=((a+b(1+p)(xmup))exp((xmu)(a+b(xmup))))/((exp((xmu)(a+b(xmup)))+1)2)f(x) = ((a + b*(1+p)*(|x-mu|^p))*exp(-(x-mu)*(a+b*(|x-mu|^p)))) / ((exp(-(x-mu)*(a + b* (|x-mu|^p)))+1)^2)

The default values for a, b, p and mu produces a function with mean 0 and variance close to 1.

*Restrictions:

If p equals to 0, b or a must be 0 otherwise there is identifiability problem.

The distribution is not defined for a and b equal to 0 simultaneously.

Value

dgenlog gives the density, pgenlog gives the distribution function, qgenlog gives the quantile function, and rgenlog generates random deviates.

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

References

Rathie, P. N. and Swamee, P. K (2006) On a new invertible generalized logistic distribution approximation to normal distribution, Technical Research Report in Statistics, 07/2006, Dept. of Statistics, Univ. of Brasilia, Brasilia, Brazil.

Examples

pgenlog(0.5) 
curve(dgenlog(x), xlim = c(-3,3)) 

rgenlog(100) 

qgenlog(0.95)

The Generalized logistic distribution with skewness

Description

Density, distribution function, quantile function and random generation a generalized logistic distribution with skewness.

Usage

pgenlog_sk(
  q,
  a = sqrt(2/pi),
  b = 0.5,
  p = 2,
  mu = 0,
  skew = 0.5,
  lower.tail = TRUE
)

dgenlog_sk(x, a = sqrt(2/pi), b = 0.5, p = 2, mu = 0, skew = 0.5)

qgenlog_sk(
  k,
  a = sqrt(2/pi),
  b = 0.5,
  p = 2,
  mu = 0,
  skew = 0.5,
  lower.tail = TRUE
)

rgenlog_sk(n, a = sqrt(2/pi), b = 0.5, p = 2, mu = 0, skew = 0.5)

Arguments

a, b, p

parameters 0\le 0, with restrictions.*

mu

mu parameter

skew

skewness parameter limited to the interval (-1, 1)

lower.tail

logical; if TRUE (default), probabilities are P[Xx]P[X \le x] otherwise, P[X>x]P[X > x].

x, q

vector of quantiles.

k

vector of probabilities.

n

number of observations. If length(n) > 1, the length is taken to be the number required

Details

The used distribution for this package is given by:

f(x)=2((a+b(1+p)(abs(xmu)p))exp((xmu)(a+b(abs(xmu)p))))/((exp((xmu)(a+b(abs(xmu)p)))+1)2)((exp((skew(xmu))(a+b(abs(skew(xmu))p)))+1)(1))f(x) = 2*((a + b*(1+p)*(abs(x-mu)^p))*exp(-(x-mu)*(a+b*(abs(x-mu)^p))))/ ((exp(-(x-mu)*(a + b* (abs(x-mu)^p)))+1)^2) * ((exp(-(skew*(x-mu))*(a+b*(abs(skew*(x-mu))^p)))+1)^(-1))

The default values for a, b, p and mu produces a function with mean 0 and variance close to 1.

*Restrictions:

If p equals to 0, b or a must be 0 otherwise there is identifiability problem.

The distribution is not defined for a and b equal to 0 simultaneously.

Value

dgenlog_sk gives the density, pgenlog_sk gives the distribution function, qgenlog_sk gives the quantile function, and rgenlog_sk generates random deviates.

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

References

Rathie, P. N. and Swamee, P. K (2006) On a new invertible generalized logistic distribution approximation to normal distribution, Technical Research Report in Statistics, 07/2006, Dept. of Statistics, Univ. of Brasilia, Brasilia, Brazil.

Azzalini, A. (1985) A class of distributions which includes the normal ones. Scandinavian Journal of Statistics.

Examples

pgenlog_sk(0.5) 
curve(dgenlog_sk(x), xlim = c(-3,3)) 

rgenlog_sk(100) 

qgenlog_sk(0.95)

Optimization for a generalized logistic distribution

Description

Maximum likehood estimation of parameters for a generalized logistic distribution.

Usage

genlog_mle(parameters, data, hessian = F, alpha = 0.05)

Arguments

parameters

Initial values for the parameters to be optimized over in the following order c(a, b, p, mu), mu can be omitted and will be set to 0.

data

This is the the data to be utilized for the estimation.

hessian

logical value that returns hessian, also returns the parameters estimation's confidence interval.

alpha

Type I error given to calculate confidence intervals, used when hessian = T.

Details

Maximum likehood estimation of parameters for the distribution proposed in this package.
This function is an application of constrOptim as a particular case needed for this distribution using the method "BFGS".
For more information of the output check help(constrOptim).

The used distribution for this package is given by:

f(x)=((a+b(1+p)(abs(xmu)p))exp((xmu)(a+b(xmup))))/((exp((xmu)(a+b(xmup)))+1)2)f(x) = ((a + b*(1+p)*(abs(x-mu)^p))*exp(-(x-mu)*(a+b*(|x-mu|^p)))) / ((exp(-(x-mu)*(a + b* (|x-mu|^p)))+1)^2)

help(dgenlog) for parameters restrictions.

Value

Return a list of components as constrOptim \(for more information, check this function\) with some extras:

par The best set of parameters found.

value The value of the loglikelihood function corresponding to par.

counts A two-element integer vector giving the number of calls to the likelihood function and BFGS respectively. This excludes those calls needed to compute the Hessian, and any calls to likelihood function to compute a finite-difference approximation to the gradient.

convergence An integer code. 0 indicates successful completion, 1 indicates that the iteration limit maxit had been reached. For more errors help(constrOptim).

message A character string giving any additional information returned by the optimizer, or NULL.

outer.iterations gives the number of outer iterations (calls to optim).

barrier.value giving the value of the barrier function at the optimum.

For hessian = T add:

hessian A symmetric matrix giving an estimate of the (negative) Hessian at the solution found. Note that this is the Hessian of the unconstrained problem even if the box constraints are active.

bounds Return the best parameters found and the upper and lower bounds for the estimation.

References

Rathie, P. N. and Swamee, P. K. (2006) On a new invertible generalized logistic distribution approximation to normal distribution, Technical Research Report in Statistics, 07/2006, Dept. of Statistics, Univ. of Brasilia, Brasilia, Brazil.

Byrd, R. H., Lu, P., Nocedal, J. and Zhu, C. (1995) A limited memory algorithm for bound constrained optimization. SIAM J. Scientific Computing, 16, 1190-1208.

Examples

## Using generic parameter starting values
datas <- rgenlog(10000, 1.5,2,2, 0)
genlog_mle(c(.5,1.6, 1.5, 0),datas)

## Select parameters starting values with genlog_slider

datas <- rgenlog(10000, 1.5,2,2, 0)

if (manipulate::isAvailable()) {
  genlog_slider(datas, return_var = 'parameters') ## choose parameters
} else {
  parameters <- c(1.345, 2, 2, -0.00510)
}

genlog_mle(parameters,datas)

Optimization for a generalized logistic distribution with skewness

Description

Maximum likehood estimation of parameters for a generalized logistic distribution with skewness.

Usage

genlog_mle_sk(parameters, data, hessian = F, alpha = 0.05)

Arguments

parameters

Initial values for the parameters to be optimized over in the following order c(a, b, p, mu, skew).

data

This is the the data to be utilized for the estimation.

hessian

logical value that returns hessian, also returns the parameters estimation's confidence interval.

alpha

Type I error given to calculate confidence intervals, used when hessian = T.

Details

Maximum likehood estimation of parameters for the distribution proposed in this package.
This function is an application of constrOptim as a particular case needed for this distribution using the method "BFGS".
For more information of the output check help(constrOptim).

The used distribution for this package is given by:

f(x)=2((a+b(1+p)(abs(xmu)p))exp((xmu)(a+b(abs(xmu)p))))/((exp((xmu)(a+b(abs(xmu)p)))+1)2)((exp((skew(xmu))(a+b(abs(skew(xmu))p)))+1)(1))f(x) = 2*((a + b*(1+p)*(abs(x-mu)^p))*exp(-(x-mu)*(a+b*(abs(x-mu)^p))))/ ((exp(-(x-mu)*(a + b* (abs(x-mu)^p)))+1)^2) * ((exp(-(skew*(x-mu))*(a+b*(abs(skew*(x-mu))^p)))+1)^(-1))

help(dgenlog_sk) for parameters restrictions.

Value

Return a list of components as constrOptim \(for more information, check this function\) with some extras:

par The best set of parameters found.

value The value of the loglikelihood function corresponding to par.

counts A two-element integer vector giving the number of calls to the likelihood function and L-BFGS-B respectively. This excludes those calls needed to compute the Hessian, and any calls to likelihood function to compute a finite-difference approximation to the gradient.

convergence An integer code. 0 indicates successful completion, 1 indicates that the iteration limit maxit had been reached. For more errors help(constrOptim).

message A character string giving any additional information returned by the optimizer, or NULL.

outer.iterations gives the number of outer iterations (calls to optim).

barrier.value giving the value of the barrier function at the optimum.

For hessian = T add:

hessian A symmetric matrix giving an estimate of the (negative) Hessian at the solution found. Note that this is the Hessian of the unconstrained problem even if the box constraints are active.

bounds Return the best parameters found and the upper and lower bounds for the estimation.

References

Rathie, P. N. and Swamee, P. K. (2006) On a new invertible generalized logistic distribution approximation to normal distribution, Technical Research Report in Statistics, 07/2006, Dept. of Statistics, Univ. of Brasilia, Brasilia, Brazil.

Azzalini, A. (1985) A class of distributions which includes the normal ones. Scandinavian Journal of Statistics.

Byrd, R. H., Lu, P., Nocedal, J. and Zhu, C. (1995) A limited memory algorithm for bound constrained optimization. SIAM J. Scientific Computing, 16, 1190-1208.

Examples

## Using generic parameter starting values
datas <- rgenlog_sk(10000, 0.3,0.9,1.5, 0, 0.9)
genlog_mle_sk(c(0.3,0.9,1.5, 0, 0.9),datas)

## Select parameters starting values with genlog_slider

datas <- rgenlog(10000, 1.5,2,2, 0)

if (manipulate::isAvailable()) {
  genlog_slider(datas, return_var = 'parameters', skew = T) ## choose parameters
 } else {
 parameters <- c( 1, 1.5, 1.3, 0.5, -.4)
 }

genlog_mle_sk(parameters, datas)

Simulating the Generalized logistic distribution

Description

Creating a simulation of the generalized logistic distribution maximum likelihood estimation of the parameters with parallelized processing code using the foreach package.

Usage

genlog_simu(real.par, init.par, sample.size = 100,
            k = 1000, seed = 555, threads = 1, progress.bar = T)

Arguments

real.par

the real parameters value of the distribution wich the random sample will be taken. It has to be a vector of length 4, the parameters are the values of c(a, b, p, mu) as listed in rgenlog, mu can be omitted and will be set to 0. There are no default values.

init.par

Initial values for the parameters to be optimized over in the following order c(a, b, p, mu). Can be an object returned by genlog_slider. There are no default values.

sample.size

the sample size to be taken in each k simulation.

k

the number of simulations.

seed

seed to be given to set.seed() function during the sampling process

threads

the numbers of CPU threads to be used for parallel computing. If the threads number is higher than the available the maximum allowed will be used.

progress.bar

show progress bar for each thread during simulations, default value TRUE.

Details

The used distribution for this package is given by:

f(x)=((a+b(1+p)(abs(xmu)p))exp((xmu)(a+b(xmup))))/((exp((xmu)(a+b(xmup)))+1)2)f(x) = ((a + b*(1+p)*(abs(x-mu)^p))*exp(-(x-mu)*(a+b*(|x-mu|^p)))) / ((exp(-(x-mu)*(a + b* (|x-mu|^p)))+1)^2)

For more about the distribution use help(dgenlog).

Value

It returns a data.frame with k rows (each simulation) and 7 columns with the following information:
a, b, p and mu are estimations using maximum likelihood estimation, for more info help(genlogis_mle)
sample.size The sample size used for each k simulation.
convergence The estimation's convergence status.

References

Rathie, P. N. and Swamee, P. K. (2006) On a new invertible generalized logistic distribution approximation to normal distribution, Technical Research Report in Statistics, 07/2006, Dept. of Statistics, Univ. of Brasilia, Brasilia, Brazil.

Examples

genlog_simu(real.par = c(0.3, 0.9, 1.5, 0.0), init.par = c(0.9, 0.3, 0.2, 0.0), 
            sample.size = 100, k = 50, threads = 2, seed = 200)

Simulating the Generalized logistic distribution with skewness

Description

Creating a simulation of the generalized logistic distribution with skewness maximum likelihood estimation of the parameters with parallelized processing code using the foreach package.

Usage

genlog_simu_sk(real.par, init.par, sample.size = 100,
            k = 1000, seed = 555, threads = 1, progress.bar = T)

Arguments

real.par

the real parameters value of the distribution wich the random sample will be taken. It has to be a vector of length 5, the parameters are the values of c(a, b, p, mu) as listed in rgenlog, mu can be omitted and will be set to 0. There are no default values.

init.par

Initial values for the parameters to be optimized over in the following order c(a, b, p, mu, skew). Can be an object returned by genlog_slider. There are no default values.

sample.size

the sample size to be taken in each k simulation.

k

the number of simulations.

seed

seed to be given to set.seed() function during the sampling process

threads

the numbers of CPU threads to be used for parallel computing. If the threads number is higher than the available the maximum allowed will be used.

progress.bar

show progress bar for each thread during simulations, default value TRUE.

Details

The used distribution for this package is given by:

f(x)=2((a+b(1+p)(abs(xmu)p))exp((xmu)(a+b(abs(xmu)p))))/((exp((xmu)(a+b(abs(xmu)p)))+1)2)((exp((skew(xmu))(a+b(abs(skew(xmu))p)))+1)(1))f(x) = 2*((a + b*(1+p)*(abs(x-mu)^p))*exp(-(x-mu)*(a+b*(abs(x-mu)^p))))/ ((exp(-(x-mu)*(a + b* (abs(x-mu)^p)))+1)^2) * ((exp(-(skew*(x-mu))*(a+b*(abs(skew*(x-mu))^p)))+1)^(-1))

Value

It returns a data.frame with k rows (each simulation) and 7 columns with the following information:
a, b, p and mu are estimations using maximum likelihood estimation, for more info help(genlogis_mle)
sample.size The sample size used for each k simulation.
convergence The estimation's convergence status.

References

Rathie, P. N. and Swamee, P. K (2006) On a new invertible generalized logistic distribution approximation to normal distribution, Technical Research Report in Statistics, 07/2006, Dept. of Statistics, Univ. of Brasilia, Brasilia, Brazil.

Azzalini, A. (1985) A class of distributions which includes the normal ones. Scandinavian Journal of Statistics.

Examples

genlog_simu_sk(real.par = c(0.3, 0.9, 1.5, 0.0, .9), init.par = c(0.9, 0.3, 0.2, 0.0, .9), 
            sample.size = 100, k = 50, threads = 2, seed = 200)

Slider for generalized logistic

Description

Make a generalized logistic distribution slider to compare histogram with theoretical distribution

Usage

genlog_slider(data, return_var = NULL, mu_range = 10, skew = F)

Arguments

data

vector of data to compare.

return_var

a char string to name where parameters are assigned

mu_range

a number to setup the minimum and maximum range value of the mu parameter

skew

logical, if TRUE, a model with skewness should be used..

Details

There is a small gear in the top left of the graphic where you can slide the parameters @param a,b,p,mu. The used distribution for this package is given by:

f(x)=((a+b(1+p)(abs(xmu)p))exp((xmu)(a+b(xmup))))/((exp((xmu)(a+b(xmup)))+1)2)f(x) = ((a + b*(1+p)*(abs(x-mu)^p))*exp(-(x-mu)*(a+b*(|x-mu|^p)))) / ((exp(-(x-mu)*(a + b* (|x-mu|^p)))+1)^2)

If the density function is not printed it is not defined for these parameters.

For skew = T the model used is

The used distribution for is given by:

f(x)=2((a+b(1+p)(abs(xmu)p))exp((xmu)(a+b(abs(xmu)p))))/((exp((xmu)(a+b(abs(xmu)p)))+1)2)((exp((skew(xmu))(a+b(abs(skew(xmu))p)))+1)(1))f(x) = 2*((a + b*(1+p)*(abs(x-mu)^p))*exp(-(x-mu)*(a+b*(abs(x-mu)^p))))/ ((exp(-(x-mu)*(a + b* (abs(x-mu)^p)))+1)^2) * ((exp(-(skew*(x-mu))*(a+b*(abs(skew*(x-mu))^p)))+1)^(-1))

#' for more information about the model (help(dgenlog_sk)) If the density function is not printed it is not defined for these parameters.

help(dgenlog) for parameters restrictions.

This function requires RStudio to run.

Value

The function plots a interactive graphic in RStudio Viewer panel.
Also, the parameters a, b, p and mu can be returned to return_var if asked in the graphic.

References

Rathie, P. N. and Swamee, P. K (2006) On a new invertible generalized logistic distribution approximation to normal distribution, Technical Research Report in Statistics, 07/2006, Dept. of Statistics, Univ. of Brasilia, Brasilia, Brazil.

Azzalini, A. (1985) A class of distributions which includes the normal ones. Scandinavian Journal of Statistics.

Examples

## Not run: 
datas <- rgenlog(1000)
if (manipulate::isAvailable()) {
  genlog_slider(datas, return_var = 'parameters')
 }

## End(Not run)