| Title: | Discrete Statistical Distributions |
|---|---|
| Description: | Implementation of new discrete statistical distributions. Each distribution includes the traditional functions as well as an additional function called the family function, which can be used to estimate parameters within the 'gamlss' framework. |
| Authors: | Freddy Hernandez-Barajas [aut, cre] (ORCID: <https://orcid.org/0000-0001-7459-3329>), Fernando Marmolejo-Ramos [aut] (ORCID: <https://orcid.org/0000-0003-4680-1287>), Olga Usuga-Manco [aut] (ORCID: <https://orcid.org/0000-0003-3062-1820>), Jamiu Olumoh [aut] (ORCID: <https://orcid.org/0000-0002-7371-3920>), Osho Ajayi [aut] |
| Maintainer: | Freddy Hernandez-Barajas <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 1.1.2 |
| Built: | 2026-05-19 14:04:39 UTC |
| Source: | https://github.com/fhernanb/discretedists |
Sum of One-Dimensional Functions
add(f, lower, upper, ..., abs.tol = .Machine$double.eps)add(f, lower, upper, ..., abs.tol = .Machine$double.eps)
f |
an R function taking a numeric first argument and returning a numeric vector of the same length. |
lower |
the lower limit of sum. Can be infinite. |
upper |
the upper limit of sum. Can be infinite. |
... |
additional arguments to be passed to f. |
abs.tol |
absolute accuracy requested. |
This function returns the sum value.
Freddy Hernandez, [email protected]
# Poisson expected value add(f=function(x, lambda) x*dpois(x, lambda), lower=0, upper=Inf, lambda=7.5) # Binomial expected value add(f=function(x, size, prob) x*dbinom(x, size, prob), lower=0, upper=20, size=20, prob=0.5) # Examples with infinite series add(f=function(x) 0.5^x, lower=0, upper=100) # Ans=2 add(f=function(x) (1/3)^(x-1), lower=1, upper=Inf) # Ans=1.5 add(f=function(x) 4/(x^2+3*x+2), lower=0, upper=Inf, abs.tol=0.001) # Ans=4.0 add(f=function(x) 1/(x*(log(x)^2)), lower=2, upper=Inf, abs.tol=0.000001) # Ans=2.02 add(f=function(x) 3*0.7^(x-1), lower=1, upper=Inf) # Ans=10 add(f=function(x, a, b) a*b^(x-1), lower=1, upper=Inf, a=3, b=0.7) # Ans=10 add(f=function(x, a=3, b=0.7) a*b^(x-1), lower=1, upper=Inf) # Ans=10# Poisson expected value add(f=function(x, lambda) x*dpois(x, lambda), lower=0, upper=Inf, lambda=7.5) # Binomial expected value add(f=function(x, size, prob) x*dbinom(x, size, prob), lower=0, upper=20, size=20, prob=0.5) # Examples with infinite series add(f=function(x) 0.5^x, lower=0, upper=100) # Ans=2 add(f=function(x) (1/3)^(x-1), lower=1, upper=Inf) # Ans=1.5 add(f=function(x) 4/(x^2+3*x+2), lower=0, upper=Inf, abs.tol=0.001) # Ans=4.0 add(f=function(x) 1/(x*(log(x)^2)), lower=2, upper=Inf, abs.tol=0.000001) # Ans=2.02 add(f=function(x) 3*0.7^(x-1), lower=1, upper=Inf) # Ans=10 add(f=function(x, a, b) a*b^(x-1), lower=1, upper=Inf, a=3, b=0.7) # Ans=10 add(f=function(x, a=3, b=0.7) a*b^(x-1), lower=1, upper=Inf) # Ans=10
The function BerG() defines the
Bernoulli-geometric distribution,
a two parameter distribution,
for a gamlss.family object to be used in GAMLSS
fitting using the function gamlss().
BerG(mu.link = "log", sigma.link = "log")BerG(mu.link = "log", sigma.link = "log")
mu.link |
defines the mu.link, with "log" link as the default for the mu parameter. |
sigma.link |
defines the sigma.link, with "log" link as the default for the sigma. |
The BerG distribution with parameters and
has a support 0, 1, 2, ... and mass function given by
if ,
if ,
with , and .
Returns a gamlss.family object which can be used
to fit a BerG distribution
in the gamlss() function.
Hermes Marques, [email protected]
Bourguignon, M., & de Medeiros, R. M. (2022). A simple and useful regression model for fitting count data. Test, 31(3), 790-827.
# Example 1 # Generating some random values with # known mu and sigma y <- rBerG(n=500, mu=0.75, sigma=0.5) # Fitting the model library(gamlss) mod1 <- gamlss(y~1, family=BerG, control=gamlss.control(n.cyc=500, trace=FALSE)) # Extracting the fitted values for mu and sigma exp(coef(mod1, what="mu")) exp(coef(mod1, what="sigma")) # Example 2 # Generating random values under some model # A function to simulate a data set with Y ~ BerG gendat <- function(n) { x1 <- runif(n) x2 <- runif(n) x3 <- runif(n) x4 <- runif(n) mu <- exp(1 + 1.2*x1 + 0.2*x2) sigma <- exp(2 + 1.5*x3 + 1.5*x4) y <- rBerG(n=n, mu=mu, sigma=sigma) data.frame(y=y, x1=x1, x2=x2, x3=x3, x4=x4) } set.seed(16494786) datos <- gendat(n=500) mod2 <- gamlss(y~x1+x2, sigma.fo=~x3+x4, family=BerG, data=datos, control=gamlss.control(n.cyc=500, trace=TRUE)) summary(mod2) # Example using the dataset grazing from the bergreg package # https://github.com/rdmatheus/bergreg # This example corresponds to example 5.1 # presented by Bourguignon & Medeiros (2022) # A simple and useful regression model for fitting count data data("grazing") hist(grazing$birds) mod3 <- gamlss(birds ~ when + grazed, sigma.fo=~1, family=BerG, data=grazing, control=gamlss.control(n.cyc=500, trace=TRUE)) summary(mod3)# Example 1 # Generating some random values with # known mu and sigma y <- rBerG(n=500, mu=0.75, sigma=0.5) # Fitting the model library(gamlss) mod1 <- gamlss(y~1, family=BerG, control=gamlss.control(n.cyc=500, trace=FALSE)) # Extracting the fitted values for mu and sigma exp(coef(mod1, what="mu")) exp(coef(mod1, what="sigma")) # Example 2 # Generating random values under some model # A function to simulate a data set with Y ~ BerG gendat <- function(n) { x1 <- runif(n) x2 <- runif(n) x3 <- runif(n) x4 <- runif(n) mu <- exp(1 + 1.2*x1 + 0.2*x2) sigma <- exp(2 + 1.5*x3 + 1.5*x4) y <- rBerG(n=n, mu=mu, sigma=sigma) data.frame(y=y, x1=x1, x2=x2, x3=x3, x4=x4) } set.seed(16494786) datos <- gendat(n=500) mod2 <- gamlss(y~x1+x2, sigma.fo=~x3+x4, family=BerG, data=datos, control=gamlss.control(n.cyc=500, trace=TRUE)) summary(mod2) # Example using the dataset grazing from the bergreg package # https://github.com/rdmatheus/bergreg # This example corresponds to example 5.1 # presented by Bourguignon & Medeiros (2022) # A simple and useful regression model for fitting count data data("grazing") hist(grazing$birds) mod3 <- gamlss(birds ~ when + grazed, sigma.fo=~1, family=BerG, data=grazing, control=gamlss.control(n.cyc=500, trace=TRUE)) summary(mod3)
The function COMPO() defines the
Conway-Maxwell-Poisson distribution,
a two parameter distribution,
for a gamlss.family object to be used in GAMLSS
fitting using the function gamlss().
COMPO(mu.link = "log", sigma.link = "log")COMPO(mu.link = "log", sigma.link = "log")
mu.link |
defines the mu.link, with "log" link as the default for the mu parameter. |
sigma.link |
defines the sigma.link, with "log" link as the default for the sigma. |
The COMPO distribution with parameters and
has a support 0, 1, 2, ... and mass function given by
with , and
.
The proposed functions here are based on the functions from the COMPoissonReg package.
Returns a gamlss.family object which can be used
to fit a COMPO distribution
in the gamlss() function.
Freddy Hernandez, [email protected]
Shmueli, G., Minka, T. P., Kadane, J. B., Borle, S., & Boatwright, P. (2005). A useful distribution for fitting discrete data: revival of the Conway–Maxwell–Poisson distribution. Journal of the Royal Statistical Society Series C: Applied Statistics, 54(1), 127-142.
# Example 1 # Generating some random values with # known mu and sigma ## Not run: set.seed(12) y <- rCOMPO(n=100, mu=10, sigma=3) # Fitting the model library(gamlss) mod1 <- gamlss(y~1, sigma.fo=~1, family=COMPO, control=gamlss.control(n.cyc=500, trace=TRUE)) # Extracting the fitted values for mu and sigma # using the inverse link function exp(coef(mod1, what="mu")) exp(coef(mod1, what="sigma")) ## End(Not run) # Example 2 # Generating random values under some model ## Not run: # A function to simulate a data set with Y ~ COMPO gendat <- function(n) { x1 <- runif(n) x2 <- runif(n) mu <- exp(2 + 1 * x1) # 12 approximately sigma <- exp(2 - 2 * x2) # 2.71 approximately y <- rCOMPO(n=n, mu=mu, sigma=sigma) data.frame(y=y, x1=x1, x2=x2) } set.seed(123) dat <- gendat(n=100) # Fitting the model mod2 <- NULL mod2 <- gamlss(y~x1, sigma.fo=~x2, family=COMPO, data=dat, control=gamlss.control(n.cyc=500, trace=TRUE)) summary(mod2) ## End(Not run) # Example 3 # Using the data from Shmueli et al. (2005) page 134 # The dataset consists of quarterly sales of a well-known brand of a # particular article of clothing at stores of a large national retailer. ## Not run: values <- 0:30 freq <- c(514, 503, 457, 423, 326, 233, 195, 139, 101, 77, 56, 40, 37, 22, 9, 7, 10, 9, 3, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 1) y <- rep(x=values, times=freq) mod3 <- gamlss(y~1, sigma.fo=~1, family=COMPO, control=gamlss.control(n.cyc=500, trace=TRUE)) exp(coef(mod3, what="mu")) exp(coef(mod3, what="sigma")) estim_mu_sigma_COMPO(y) library(COMPoissonReg) fit <- glm.cmp(y ~ 1) res <- exp(fit$opt.res$par) res ## End(Not run) # Example 4 # Using the data from Shmueli et al. (2005) page 134 # The dataset contains lengths of words (numbers of syllables) # in a Hungarian dictionary ## Not run: # Slovak dictionary y <- rep(x=1:5, times=c(7, 33, 49, 22, 6)) # Hungarian dictionary y <- rep(x=1:9, times=c(1421, 12333, 20711, 15590, 5544, 1510, 289, 60, 1)) mod4 <- gamlss(y~1, sigma.fo=~1, family=COMPO, control=gamlss.control(n.cyc=500, trace=TRUE)) exp(coef(mod4, what="mu")) exp(coef(mod4, what="sigma")) estim_mu_sigma_COMPO(y) library(COMPoissonReg) fit <- glm.cmp(y ~ 1) res <- exp(fit$opt.res$par) res ## End(Not run)# Example 1 # Generating some random values with # known mu and sigma ## Not run: set.seed(12) y <- rCOMPO(n=100, mu=10, sigma=3) # Fitting the model library(gamlss) mod1 <- gamlss(y~1, sigma.fo=~1, family=COMPO, control=gamlss.control(n.cyc=500, trace=TRUE)) # Extracting the fitted values for mu and sigma # using the inverse link function exp(coef(mod1, what="mu")) exp(coef(mod1, what="sigma")) ## End(Not run) # Example 2 # Generating random values under some model ## Not run: # A function to simulate a data set with Y ~ COMPO gendat <- function(n) { x1 <- runif(n) x2 <- runif(n) mu <- exp(2 + 1 * x1) # 12 approximately sigma <- exp(2 - 2 * x2) # 2.71 approximately y <- rCOMPO(n=n, mu=mu, sigma=sigma) data.frame(y=y, x1=x1, x2=x2) } set.seed(123) dat <- gendat(n=100) # Fitting the model mod2 <- NULL mod2 <- gamlss(y~x1, sigma.fo=~x2, family=COMPO, data=dat, control=gamlss.control(n.cyc=500, trace=TRUE)) summary(mod2) ## End(Not run) # Example 3 # Using the data from Shmueli et al. (2005) page 134 # The dataset consists of quarterly sales of a well-known brand of a # particular article of clothing at stores of a large national retailer. ## Not run: values <- 0:30 freq <- c(514, 503, 457, 423, 326, 233, 195, 139, 101, 77, 56, 40, 37, 22, 9, 7, 10, 9, 3, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 1) y <- rep(x=values, times=freq) mod3 <- gamlss(y~1, sigma.fo=~1, family=COMPO, control=gamlss.control(n.cyc=500, trace=TRUE)) exp(coef(mod3, what="mu")) exp(coef(mod3, what="sigma")) estim_mu_sigma_COMPO(y) library(COMPoissonReg) fit <- glm.cmp(y ~ 1) res <- exp(fit$opt.res$par) res ## End(Not run) # Example 4 # Using the data from Shmueli et al. (2005) page 134 # The dataset contains lengths of words (numbers of syllables) # in a Hungarian dictionary ## Not run: # Slovak dictionary y <- rep(x=1:5, times=c(7, 33, 49, 22, 6)) # Hungarian dictionary y <- rep(x=1:9, times=c(1421, 12333, 20711, 15590, 5544, 1510, 289, 60, 1)) mod4 <- gamlss(y~1, sigma.fo=~1, family=COMPO, control=gamlss.control(n.cyc=500, trace=TRUE)) exp(coef(mod4, what="mu")) exp(coef(mod4, what="sigma")) estim_mu_sigma_COMPO(y) library(COMPoissonReg) fit <- glm.cmp(y ~ 1) res <- exp(fit$opt.res$par) res ## End(Not run)
The function COMPO2() defines the
Conway-Maxwell-Poisson distribution
a two parameter distribution,
for a gamlss.family object to be used in GAMLSS
fitting using the function gamlss().
This parameterization was
proposed by Ribeiro et al. (2020) and the main
characteristic is that .
COMPO2(mu.link = "log", sigma.link = "identity")COMPO2(mu.link = "log", sigma.link = "identity")
mu.link |
defines the mu.link, with "log" link as the default for the mu parameter. |
sigma.link |
defines the sigma.link, with "identity" link as the default for the sigma. |
The COMPO2 distribution with parameters and
has a support 0, 1, 2, ... and mass function given by
with , and
.
The proposed functions here are based on the functions from the COMPoissonReg package.
Returns a gamlss.family object which can be used
to fit a COMPO2 distribution
in the gamlss() function.
Freddy Hernandez, [email protected]
Ribeiro Jr, Eduardo E., et al. "Reparametrization of COM–Poisson regression models with applications in the analysis of experimental data." Statistical Modelling 20.5 (2020): 443-466.
# Example 1 # Generating some random values with # known mu and sigma y <- rCOMPO2(n=500, mu=10, sigma=-1) # Fitting the model library(gamlss) mod1 <- gamlss(y~1, sigma.fo=~1, family=COMPO2, control=gamlss.control(n.cyc=500, trace=TRUE)) # Extracting the fitted values for mu and sigma # using the inverse link function exp(coef(mod1, what="mu")) coef(mod1, what="sigma") # Example 2 # Generating random values under some model ## Not run: # A function to simulate a data set with Y ~ COMPO2 gendat <- function(n) { x1 <- runif(n) x2 <- runif(n) mu <- exp(2 + 1 * x1) # 12 approximately sigma <- 1 - 2 * x2 # 0 approximately y <- rCOMPO2(n=n, mu=mu, sigma=sigma) data.frame(y=y, x1=x1, x2=x2) } set.seed(123) dat <- gendat(n=200) # Fitting the model mod2 <- NULL mod2 <- gamlss(y~x1, sigma.fo=~x2, family=COMPO2, data=dat) summary(mod2) ## End(Not run)# Example 1 # Generating some random values with # known mu and sigma y <- rCOMPO2(n=500, mu=10, sigma=-1) # Fitting the model library(gamlss) mod1 <- gamlss(y~1, sigma.fo=~1, family=COMPO2, control=gamlss.control(n.cyc=500, trace=TRUE)) # Extracting the fitted values for mu and sigma # using the inverse link function exp(coef(mod1, what="mu")) coef(mod1, what="sigma") # Example 2 # Generating random values under some model ## Not run: # A function to simulate a data set with Y ~ COMPO2 gendat <- function(n) { x1 <- runif(n) x2 <- runif(n) mu <- exp(2 + 1 * x1) # 12 approximately sigma <- 1 - 2 * x2 # 0 approximately y <- rCOMPO2(n=n, mu=mu, sigma=sigma) data.frame(y=y, x1=x1, x2=x2) } set.seed(123) dat <- gendat(n=200) # Fitting the model mod2 <- NULL mod2 <- gamlss(y~x1, sigma.fo=~x2, family=COMPO2, data=dat) summary(mod2) ## End(Not run)
These functions define the density, distribution function, quantile
function and random generation for the Bernoulli-geometric distribution
with parameters and .
dBerG(x, mu, sigma, log = FALSE) pBerG(q, mu, sigma, lower.tail = TRUE, log.p = FALSE) rBerG(n, mu, sigma) qBerG(p, mu, sigma, lower.tail = TRUE, log.p = FALSE)dBerG(x, mu, sigma, log = FALSE) pBerG(q, mu, sigma, lower.tail = TRUE, log.p = FALSE) rBerG(n, mu, sigma) qBerG(p, mu, sigma, lower.tail = TRUE, log.p = FALSE)
x, q
|
vector of (non-negative integer) quantiles. |
mu |
vector of the mu parameter. |
sigma |
vector of the sigma parameter. |
log, log.p
|
logical; if TRUE, probabilities p are given as log(p). |
lower.tail |
logical; if TRUE (default), probabilities are |
n |
number of random values to return. |
p |
vector of probabilities. |
The BerG distribution with parameters and
has a support 0, 1, 2, ... and mass function given by
if ,
if ,
with , and .
dBerG gives the density, pBerG gives the distribution
function, qBerG gives the quantile function, rBerG
generates random deviates.
Hermes Marques, [email protected]
Bourguignon, M., & de Medeiros, R. M. (2022). A simple and useful regression model for fitting count data. Test, 31(3), 790-827.
BerG.
# Example 1 # Plotting the mass function for different parameter values x_max <- 20 probs1 <- dBerG(x=0:x_max, mu=0.7, sigma=0.5) probs2 <- dBerG(x=0:x_max, mu=0.3, sigma=1) probs3 <- dBerG(x=0:x_max, mu=2, sigma=3) # To plot the first k values plot(x=0:x_max, y=probs1, type="o", lwd=2, col="dodgerblue", las=1, ylab="P(X=x)", xlab="X", main="Probability for BerG", ylim=c(0, 0.80)) points(x=0:x_max, y=probs2, type="o", lwd=2, col="tomato") points(x=0:x_max, y=probs3, type="o", lwd=2, col="green4") legend("topright", col=c("dodgerblue", "tomato", "green4"), lwd=3, legend=c("mu=0.7, sigma=0.5", "mu=0.3, sigma=1", "mu=2, sigma=3")) # Example 2 # Checking if the cumulative curves converge to 1 #plot1 x_max <- 10 plot_discrete_cdf(x=0:x_max, fx=dBerG(x=0:x_max, mu=1, sigma=2), col="dodgerblue", main="CDF for BerG", lwd=3) legend("bottomright", legend="mu=1, sigma=2", col="dodgerblue", lty=1, lwd=2, cex=0.8) #plot2 plot_discrete_cdf(x=0:x_max, fx=dBerG(x=0:x_max, mu=3, sigma=3), col="tomato", main="CDF for BerG", lwd=3) legend("bottomright", legend="mu=3, sigma=3", col="tomato", lty=1, lwd=2, cex=0.8) #plot3 plot_discrete_cdf(x=0:x_max, fx=dBerG(x=0:x_max, mu=5, sigma=5), col="green4", main="CDF for BerG", lwd=3) legend("bottomright", legend="mu=5, sigma=5", col="green4", lty=1, lwd=2, cex=0.8) # Example 3 # Comparing the random generator output with # the theoretical probabilities x_max <- 15 probs1 <- dBerG(x=0:x_max, mu=0.5, sigma=5) names(probs1) <- 0:x_max x <- rBerG(n=1000, mu=0.5, sigma=5) probs2 <- prop.table(table(x)) cn <- union(names(probs1), names(probs2)) height <- rbind(probs1[cn], probs2[cn]) mp <- barplot(height, beside=TRUE, names.arg=cn, col=c("dodgerblue3","firebrick3"), las=1, xlab="X", ylab="Proportion") legend("topright", legend=c("Theoretical", "Simulated"), bty="n", lwd=3, col=c("dodgerblue3","firebrick3"), lty=1) # Example 4 # Checking the quantile function mu <- 1 sigma <- 2 p <- seq(from=0, to=1, by=0.01) qxx <- qBerG(p=p, mu=mu, sigma=sigma, lower.tail=TRUE, log.p=FALSE) plot(p, qxx, type="s", lwd=2, col="green3", ylab="quantiles", main="Quantiles of DBerG(mu=1, sigma=2)")# Example 1 # Plotting the mass function for different parameter values x_max <- 20 probs1 <- dBerG(x=0:x_max, mu=0.7, sigma=0.5) probs2 <- dBerG(x=0:x_max, mu=0.3, sigma=1) probs3 <- dBerG(x=0:x_max, mu=2, sigma=3) # To plot the first k values plot(x=0:x_max, y=probs1, type="o", lwd=2, col="dodgerblue", las=1, ylab="P(X=x)", xlab="X", main="Probability for BerG", ylim=c(0, 0.80)) points(x=0:x_max, y=probs2, type="o", lwd=2, col="tomato") points(x=0:x_max, y=probs3, type="o", lwd=2, col="green4") legend("topright", col=c("dodgerblue", "tomato", "green4"), lwd=3, legend=c("mu=0.7, sigma=0.5", "mu=0.3, sigma=1", "mu=2, sigma=3")) # Example 2 # Checking if the cumulative curves converge to 1 #plot1 x_max <- 10 plot_discrete_cdf(x=0:x_max, fx=dBerG(x=0:x_max, mu=1, sigma=2), col="dodgerblue", main="CDF for BerG", lwd=3) legend("bottomright", legend="mu=1, sigma=2", col="dodgerblue", lty=1, lwd=2, cex=0.8) #plot2 plot_discrete_cdf(x=0:x_max, fx=dBerG(x=0:x_max, mu=3, sigma=3), col="tomato", main="CDF for BerG", lwd=3) legend("bottomright", legend="mu=3, sigma=3", col="tomato", lty=1, lwd=2, cex=0.8) #plot3 plot_discrete_cdf(x=0:x_max, fx=dBerG(x=0:x_max, mu=5, sigma=5), col="green4", main="CDF for BerG", lwd=3) legend("bottomright", legend="mu=5, sigma=5", col="green4", lty=1, lwd=2, cex=0.8) # Example 3 # Comparing the random generator output with # the theoretical probabilities x_max <- 15 probs1 <- dBerG(x=0:x_max, mu=0.5, sigma=5) names(probs1) <- 0:x_max x <- rBerG(n=1000, mu=0.5, sigma=5) probs2 <- prop.table(table(x)) cn <- union(names(probs1), names(probs2)) height <- rbind(probs1[cn], probs2[cn]) mp <- barplot(height, beside=TRUE, names.arg=cn, col=c("dodgerblue3","firebrick3"), las=1, xlab="X", ylab="Proportion") legend("topright", legend=c("Theoretical", "Simulated"), bty="n", lwd=3, col=c("dodgerblue3","firebrick3"), lty=1) # Example 4 # Checking the quantile function mu <- 1 sigma <- 2 p <- seq(from=0, to=1, by=0.01) qxx <- qBerG(p=p, mu=mu, sigma=sigma, lower.tail=TRUE, log.p=FALSE) plot(p, qxx, type="s", lwd=2, col="green3", ylab="quantiles", main="Quantiles of DBerG(mu=1, sigma=2)")
The function DBH() defines the
Discrete Burr Hatke distribution
a single parameter distribution,
for a gamlss.family object to be used in GAMLSS
fitting using the function gamlss().
DBH(mu.link = "logit")DBH(mu.link = "logit")
mu.link |
defines the mu.link, with "logit" link as the default for the mu parameter. Other links are "probit" and "cloglog"'(complementary log-log) |
The Discrete Burr-Hatke distribution with parameter has a support
0, 1, 2, ... and its probability mass function (pmf) is given by
The pmf is log-convex for all values of , where
is an increasing function in for all values of the parameter .
Note: in this implementation we changed the original parameters for ,
we did it to implement this distribution within gamlss framework.
Returns a gamlss.family object which can be used
to fit a Discrete Burr-Hatke distribution
in the gamlss() function.
Valentina Hurtado Sepulveda, [email protected]
El-Morshedy, M., Eliwa, M. S., & Altun, E. (2020). Discrete Burr-Hatke distribution with properties, estimation methods and regression model. IEEE access, 8, 74359-74370.
dDBH.
# Example 1 # Generating some random values with # known mu y <- rDBH(n=1000, mu=0.74) library(gamlss) mod1 <- gamlss(y~1, family=DBH, control=gamlss.control(n.cyc=500, trace=FALSE)) # Extracting the fitted values for mu # using the inverse logit function inv_logit <- function(x) exp(x) / (1+exp(x)) inv_logit(coef(mod1, parameter="mu")) # Example 2 # Generating random values under some model # A function to simulate a data set with Y ~ DBH gendat <- function(n) { x1 <- runif(n) mu <- inv_logit(-3 + 5 * x1) y <- rDBH(n=n, mu=mu) data.frame(y=y, x1=x1) } datos <- gendat(n=150) mod2 <- NULL mod2 <- gamlss(y~x1, family=DBH, data=datos, control=gamlss.control(n.cyc=500, trace=FALSE)) summary(mod2) # Example 3 # Number of carious teeth among the four deciduous molars. # Taken from EL-MORSHEDY (2020) page 74364. y <- rep(0:4, times=c(64, 17, 10, 6, 3)) mod3 <- gamlss(y~1, family=DBH, control=gamlss.control(n.cyc=500, trace=FALSE)) # Extracting the fitted values for mu # using the inverse link function inv_logit <- function(x) 1/(1 + exp(-x)) inv_logit(coef(mod3, what="mu")) # Example 4 # Counts of cysts of kidneys using steroids. # Taken from EL-MORSHEDY (2020) page 74365. y <- rep(0:11, times=c(65, 14, 10, 6, 4, 2, 2, 2, 1, 1, 1, 2)) mod4 <- gamlss(y~1, family=DBH, control=gamlss.control(n.cyc=500, trace=FALSE)) # Extracting the fitted values for mu # using the inverse link function inv_logit <- function(x) 1/(1 + exp(-x)) inv_logit(coef(mod4, what="mu"))# Example 1 # Generating some random values with # known mu y <- rDBH(n=1000, mu=0.74) library(gamlss) mod1 <- gamlss(y~1, family=DBH, control=gamlss.control(n.cyc=500, trace=FALSE)) # Extracting the fitted values for mu # using the inverse logit function inv_logit <- function(x) exp(x) / (1+exp(x)) inv_logit(coef(mod1, parameter="mu")) # Example 2 # Generating random values under some model # A function to simulate a data set with Y ~ DBH gendat <- function(n) { x1 <- runif(n) mu <- inv_logit(-3 + 5 * x1) y <- rDBH(n=n, mu=mu) data.frame(y=y, x1=x1) } datos <- gendat(n=150) mod2 <- NULL mod2 <- gamlss(y~x1, family=DBH, data=datos, control=gamlss.control(n.cyc=500, trace=FALSE)) summary(mod2) # Example 3 # Number of carious teeth among the four deciduous molars. # Taken from EL-MORSHEDY (2020) page 74364. y <- rep(0:4, times=c(64, 17, 10, 6, 3)) mod3 <- gamlss(y~1, family=DBH, control=gamlss.control(n.cyc=500, trace=FALSE)) # Extracting the fitted values for mu # using the inverse link function inv_logit <- function(x) 1/(1 + exp(-x)) inv_logit(coef(mod3, what="mu")) # Example 4 # Counts of cysts of kidneys using steroids. # Taken from EL-MORSHEDY (2020) page 74365. y <- rep(0:11, times=c(65, 14, 10, 6, 4, 2, 2, 2, 1, 1, 1, 2)) mod4 <- gamlss(y~1, family=DBH, control=gamlss.control(n.cyc=500, trace=FALSE)) # Extracting the fitted values for mu # using the inverse link function inv_logit <- function(x) 1/(1 + exp(-x)) inv_logit(coef(mod4, what="mu"))
These functions define the density, distribution function, quantile
function and random generation for the
Conway-Maxwell-Poisson distribution
with parameters and .
dCOMPO(x, mu, sigma, log = FALSE) pCOMPO(q, mu, sigma, lower.tail = TRUE, log.p = FALSE) qCOMPO(p, mu, sigma, lower.tail = TRUE, log.p = FALSE) rCOMPO(n, mu, sigma)dCOMPO(x, mu, sigma, log = FALSE) pCOMPO(q, mu, sigma, lower.tail = TRUE, log.p = FALSE) qCOMPO(p, mu, sigma, lower.tail = TRUE, log.p = FALSE) rCOMPO(n, mu, sigma)
x, q
|
vector of (non-negative integer) quantiles. |
mu |
vector of the mu parameter. |
sigma |
vector of the sigma parameter. |
log, log.p
|
logical; if TRUE, probabilities p are given as log(p). |
lower.tail |
logical; if TRUE (default), probabilities are
|
p |
vector of probabilities. |
n |
number of random values to return. |
The COMPO distribution with parameters and
has a support 0, 1, 2, ... and mass function given by
with , and
.
The proposed functions here are based on the functions from the COMPoissonReg package.
dCOMPO gives the density, pCOMPO gives the distribution
function, qCOMPO gives the quantile function, rCOMPO
generates random deviates.
Freddy Hernandez, [email protected]
Shmueli, G., Minka, T. P., Kadane, J. B., Borle, S., & Boatwright, P. (2005). A useful distribution for fitting discrete data: revival of the Conway–Maxwell–Poisson distribution. Journal of the Royal Statistical Society Series C: Applied Statistics, 54(1), 127-142.
# Example 1 # Plotting the mass function for different parameter values x_max <- 20 probs1 <- dCOMPO(x=0:x_max, mu=2, sigma=0.5) probs2 <- dCOMPO(x=0:x_max, mu=8, sigma=1.0) probs3 <- dCOMPO(x=0:x_max, mu=15, sigma=1.5) # To plot the first k values plot(x=0:x_max, y=probs1, type="o", lwd=2, col="dodgerblue", las=1, ylab="P(X=x)", xlab="X", main="Probability for COMPO", ylim=c(0, 0.30)) points(x=0:x_max, y=probs2, type="o", lwd=2, col="tomato") points(x=0:x_max, y=probs3, type="o", lwd=2, col="green4") legend("topright", col=c("dodgerblue", "tomato", "green4"), lwd=3, legend=c("mu=2, sigma=0.5", "mu=8, sigma=1.0", "mu=15, sigma=1.5")) # Example 2 # Checking if the cumulative curves converge to 1 x_max <- 20 cumulative_probs1 <- pCOMPO(q=0:x_max, mu=2, sigma=0.5) cumulative_probs2 <- pCOMPO(q=0:x_max, mu=8, sigma=1.0) cumulative_probs3 <- pCOMPO(q=0:x_max, mu=15, sigma=1.5) plot(x=0:x_max, y=cumulative_probs1, col="dodgerblue", type="o", las=1, ylim=c(0, 1), main="Cumulative probability for COMPO", xlab="X", ylab="Probability") points(x=0:x_max, y=cumulative_probs2, type="o", col="tomato") points(x=0:x_max, y=cumulative_probs3, type="o", col="green4") legend("bottomright", col=c("dodgerblue", "tomato", "green4"), lwd=3, legend=c("mu=2, sigma=0.5", "mu=8, sigma=1.0", "mu=15, sigma=1.5")) # Example 3 # Comparing the random generator output with # the theoretical probabilities x_max <- 50 probs1 <- dCOMPO(x=0:x_max, mu=5, sigma=0.5) names(probs1) <- 0:x_max x <- rCOMPO(n=1000, mu=5, sigma=0.5) probs2 <- prop.table(table(x)) cn <- union(names(probs1), names(probs2)) height <- rbind(probs1[cn], probs2[cn]) mp <- barplot(height, beside = TRUE, names.arg = cn, col=c("dodgerblue3","firebrick3"), las=1, xlab="X", ylab="Proportion") legend("topright", legend=c("Theoretical", "Simulated"), bty="n", lwd=3, col=c("dodgerblue3","firebrick3"), lty=1) # Example 4 # Checking the quantile function mu <- 3 sigma <- 1.5 p <- seq(from=0.01, to=0.99, by=0.01) qxx <- qCOMPO(p=p, mu=mu, sigma=sigma, lower.tail=TRUE, log.p=FALSE) plot(p, qxx, type="s", lwd=2, col="green3", ylab="quantiles", main="Quantiles of COMPO(mu = 3, sigma = 1.5)")# Example 1 # Plotting the mass function for different parameter values x_max <- 20 probs1 <- dCOMPO(x=0:x_max, mu=2, sigma=0.5) probs2 <- dCOMPO(x=0:x_max, mu=8, sigma=1.0) probs3 <- dCOMPO(x=0:x_max, mu=15, sigma=1.5) # To plot the first k values plot(x=0:x_max, y=probs1, type="o", lwd=2, col="dodgerblue", las=1, ylab="P(X=x)", xlab="X", main="Probability for COMPO", ylim=c(0, 0.30)) points(x=0:x_max, y=probs2, type="o", lwd=2, col="tomato") points(x=0:x_max, y=probs3, type="o", lwd=2, col="green4") legend("topright", col=c("dodgerblue", "tomato", "green4"), lwd=3, legend=c("mu=2, sigma=0.5", "mu=8, sigma=1.0", "mu=15, sigma=1.5")) # Example 2 # Checking if the cumulative curves converge to 1 x_max <- 20 cumulative_probs1 <- pCOMPO(q=0:x_max, mu=2, sigma=0.5) cumulative_probs2 <- pCOMPO(q=0:x_max, mu=8, sigma=1.0) cumulative_probs3 <- pCOMPO(q=0:x_max, mu=15, sigma=1.5) plot(x=0:x_max, y=cumulative_probs1, col="dodgerblue", type="o", las=1, ylim=c(0, 1), main="Cumulative probability for COMPO", xlab="X", ylab="Probability") points(x=0:x_max, y=cumulative_probs2, type="o", col="tomato") points(x=0:x_max, y=cumulative_probs3, type="o", col="green4") legend("bottomright", col=c("dodgerblue", "tomato", "green4"), lwd=3, legend=c("mu=2, sigma=0.5", "mu=8, sigma=1.0", "mu=15, sigma=1.5")) # Example 3 # Comparing the random generator output with # the theoretical probabilities x_max <- 50 probs1 <- dCOMPO(x=0:x_max, mu=5, sigma=0.5) names(probs1) <- 0:x_max x <- rCOMPO(n=1000, mu=5, sigma=0.5) probs2 <- prop.table(table(x)) cn <- union(names(probs1), names(probs2)) height <- rbind(probs1[cn], probs2[cn]) mp <- barplot(height, beside = TRUE, names.arg = cn, col=c("dodgerblue3","firebrick3"), las=1, xlab="X", ylab="Proportion") legend("topright", legend=c("Theoretical", "Simulated"), bty="n", lwd=3, col=c("dodgerblue3","firebrick3"), lty=1) # Example 4 # Checking the quantile function mu <- 3 sigma <- 1.5 p <- seq(from=0.01, to=0.99, by=0.01) qxx <- qCOMPO(p=p, mu=mu, sigma=sigma, lower.tail=TRUE, log.p=FALSE) plot(p, qxx, type="s", lwd=2, col="green3", ylab="quantiles", main="Quantiles of COMPO(mu = 3, sigma = 1.5)")
These functions define the density, distribution function, quantile
function and random generation for the
Comway-Maxwell-Poisson distribution
with parameters and .
This parameterization was
proposed by Ribeiro et al. (2020) and the main
characteristic is that .
dCOMPO2(x, mu, sigma, log = FALSE) pCOMPO2(q, mu, sigma, lower.tail = TRUE, log.p = FALSE) qCOMPO2(p, mu, sigma, lower.tail = TRUE, log.p = FALSE) rCOMPO2(n, mu, sigma)dCOMPO2(x, mu, sigma, log = FALSE) pCOMPO2(q, mu, sigma, lower.tail = TRUE, log.p = FALSE) qCOMPO2(p, mu, sigma, lower.tail = TRUE, log.p = FALSE) rCOMPO2(n, mu, sigma)
x, q
|
vector of (non-negative integer) quantiles. |
mu |
vector of the mu parameter. |
sigma |
vector of the sigma parameter. |
log, log.p
|
logical; if TRUE, probabilities p are given as log(p). |
lower.tail |
logical; if TRUE (default), probabilities are
|
p |
vector of probabilities. |
n |
number of random values to return. |
The COMPO2 distribution with parameters and
has a support 0, 1, 2, ... and mass function given by
with , and
.
The proposed functions here are based on the functions from the COMPoissonReg package.
dCOMPO2 gives the density, pCOMPO2 gives the distribution
function, qCOMPO2 gives the quantile function, rCOMPO2
generates random deviates.
Freddy Hernandez, [email protected]
Ribeiro Jr, Eduardo E., et al. "Reparametrization of COM–Poisson regression models with applications in the analysis of experimental data." Statistical Modelling 20.5 (2020): 443-466.
# Example 1 # Plotting the mass function for different parameter values x_max <- 20 probs1 <- dCOMPO2(x=0:x_max, mu=2, sigma=-0.7) probs2 <- dCOMPO2(x=0:x_max, mu=8, sigma=0) probs3 <- dCOMPO2(x=0:x_max, mu=15, sigma=0.7) # To plot the first k values plot(x=0:x_max, y=probs1, type="o", lwd=2, col="dodgerblue", las=1, ylab="P(X=x)", xlab="X", main="Probability for COMPO2", ylim=c(0, 0.30)) points(x=0:x_max, y=probs2, type="o", lwd=2, col="tomato") points(x=0:x_max, y=probs3, type="o", lwd=2, col="green4") legend("topright", col=c("dodgerblue", "tomato", "green4"), lwd=3, legend=c("mu=2, sigma=-0.7", "mu=8, sigma=0", "mu=15, sigma=0.7")) # Example 2 # Checking if the cumulative curves converge to 1 x_max <- 20 cumulative_probs1 <- pCOMPO2(q=0:x_max, mu=2, sigma=-0.7) cumulative_probs2 <- pCOMPO2(q=0:x_max, mu=8, sigma=0) cumulative_probs3 <- pCOMPO2(q=0:x_max, mu=15, sigma=0.7) plot(x=0:x_max, y=cumulative_probs1, col="dodgerblue", type="o", las=1, ylim=c(0, 1), main="Cumulative probability for COMPO2", xlab="X", ylab="Probability") points(x=0:x_max, y=cumulative_probs2, type="o", col="tomato") points(x=0:x_max, y=cumulative_probs3, type="o", col="green4") legend("bottomright", col=c("dodgerblue", "tomato", "green4"), lwd=3, legend=c("mu=2, sigma=-0.7", "mu=8, sigma=0", "mu=15, sigma=0.7")) # Example 3 # Comparing the random generator output with # the theoretical probabilities x_max <- 15 probs1 <- dCOMPO2(x=0:x_max, mu=5, sigma=0.5) names(probs1) <- 0:x_max x <- rCOMPO2(n=1000, mu=5, sigma=0.5) probs2 <- prop.table(table(x)) cn <- union(names(probs1), names(probs2)) height <- rbind(probs1[cn], probs2[cn]) mp <- barplot(height, beside = TRUE, names.arg = cn, col=c("dodgerblue3","firebrick3"), las=1, xlab="X", ylab="Proportion") legend("topright", legend=c("Theoretical", "Simulated"), bty="n", lwd=3, col=c("dodgerblue3","firebrick3"), lty=1) # Example 4 # Checking the quantile function mu <- 3 sigma <- 0.15 p <- seq(from=0.01, to=0.99, by=0.01) qxx <- qCOMPO2(p=p, mu=mu, sigma=sigma, lower.tail=TRUE, log.p=FALSE) plot(p, qxx, type="s", lwd=2, col="green3", ylab="quantiles", main="Quantiles of COMPO2(mu = 3, sigma = 0.15)")# Example 1 # Plotting the mass function for different parameter values x_max <- 20 probs1 <- dCOMPO2(x=0:x_max, mu=2, sigma=-0.7) probs2 <- dCOMPO2(x=0:x_max, mu=8, sigma=0) probs3 <- dCOMPO2(x=0:x_max, mu=15, sigma=0.7) # To plot the first k values plot(x=0:x_max, y=probs1, type="o", lwd=2, col="dodgerblue", las=1, ylab="P(X=x)", xlab="X", main="Probability for COMPO2", ylim=c(0, 0.30)) points(x=0:x_max, y=probs2, type="o", lwd=2, col="tomato") points(x=0:x_max, y=probs3, type="o", lwd=2, col="green4") legend("topright", col=c("dodgerblue", "tomato", "green4"), lwd=3, legend=c("mu=2, sigma=-0.7", "mu=8, sigma=0", "mu=15, sigma=0.7")) # Example 2 # Checking if the cumulative curves converge to 1 x_max <- 20 cumulative_probs1 <- pCOMPO2(q=0:x_max, mu=2, sigma=-0.7) cumulative_probs2 <- pCOMPO2(q=0:x_max, mu=8, sigma=0) cumulative_probs3 <- pCOMPO2(q=0:x_max, mu=15, sigma=0.7) plot(x=0:x_max, y=cumulative_probs1, col="dodgerblue", type="o", las=1, ylim=c(0, 1), main="Cumulative probability for COMPO2", xlab="X", ylab="Probability") points(x=0:x_max, y=cumulative_probs2, type="o", col="tomato") points(x=0:x_max, y=cumulative_probs3, type="o", col="green4") legend("bottomright", col=c("dodgerblue", "tomato", "green4"), lwd=3, legend=c("mu=2, sigma=-0.7", "mu=8, sigma=0", "mu=15, sigma=0.7")) # Example 3 # Comparing the random generator output with # the theoretical probabilities x_max <- 15 probs1 <- dCOMPO2(x=0:x_max, mu=5, sigma=0.5) names(probs1) <- 0:x_max x <- rCOMPO2(n=1000, mu=5, sigma=0.5) probs2 <- prop.table(table(x)) cn <- union(names(probs1), names(probs2)) height <- rbind(probs1[cn], probs2[cn]) mp <- barplot(height, beside = TRUE, names.arg = cn, col=c("dodgerblue3","firebrick3"), las=1, xlab="X", ylab="Proportion") legend("topright", legend=c("Theoretical", "Simulated"), bty="n", lwd=3, col=c("dodgerblue3","firebrick3"), lty=1) # Example 4 # Checking the quantile function mu <- 3 sigma <- 0.15 p <- seq(from=0.01, to=0.99, by=0.01) qxx <- qCOMPO2(p=p, mu=mu, sigma=sigma, lower.tail=TRUE, log.p=FALSE) plot(p, qxx, type="s", lwd=2, col="green3", ylab="quantiles", main="Quantiles of COMPO2(mu = 3, sigma = 0.15)")
These functions define the density, distribution function, quantile
function and random generation for the Discrete Burr Hatke distribution
with parameter .
dDBH(x, mu, log = FALSE) pDBH(q, mu, lower.tail = TRUE, log.p = FALSE) qDBH(p, mu = 1, lower.tail = TRUE, log.p = FALSE) rDBH(n, mu = 1)dDBH(x, mu, log = FALSE) pDBH(q, mu, lower.tail = TRUE, log.p = FALSE) qDBH(p, mu = 1, lower.tail = TRUE, log.p = FALSE) rDBH(n, mu = 1)
x, q
|
vector of (non-negative integer) quantiles. |
mu |
vector of the mu parameter. |
log, log.p
|
logical; if TRUE, probabilities p are given as log(p). |
lower.tail |
logical; if TRUE (default), probabilities are |
p |
vector of probabilities. |
n |
number of random values to return |
The Discrete Burr-Hatke distribution with parameters has a support
0, 1, 2, ... and density given by
The pmf is log-convex for all values of , where
is an increasing function in for all values of the parameter .
Note: in this implementation we changed the original parameters for ,
we did it to implement this distribution within gamlss framework.
dDBH gives the density, pDBH gives the distribution
function, qDBH gives the quantile function, rDBH
generates random deviates.
Valentina Hurtado Sepulveda, [email protected]
El-Morshedy, M., Eliwa, M. S., & Altun, E. (2020). Discrete Burr-Hatke distribution with properties, estimation methods and regression model. IEEE access, 8, 74359-74370.
DBH.
# Example 1 # Plotting the mass function for different parameter values plot(x=0:5, y=dDBH(x=0:5, mu=0.1), type="h", lwd=2, col="dodgerblue", las=1, ylab="P(X=x)", xlab="X", ylim=c(0, 1), main="Probability mu=0.1") plot(x=0:10, y=dDBH(x=0:10, mu=0.5), type="h", lwd=2, col="tomato", las=1, ylab="P(X=x)", xlab="X", ylim=c(0, 1), main="Probability mu=0.5") plot(x=0:15, y=dDBH(x=0:15, mu=0.9), type="h", lwd=2, col="green4", las=1, ylab="P(X=x)", xlab="X", ylim=c(0, 1), main="Probability mu=0.9") # Example 2 # Checking if the cumulative curves converge to 1 x_max <- 15 cumulative_probs1 <- pDBH(q=0:x_max, mu=0.1) cumulative_probs2 <- pDBH(q=0:x_max, mu=0.5) cumulative_probs3 <- pDBH(q=0:x_max, mu=0.9) plot(x=0:x_max, y=cumulative_probs1, col="dodgerblue", type="o", las=1, ylim=c(0, 1), main="Cumulative probability for Burr-Hatke", xlab="X", ylab="Probability") points(x=0:x_max, y=cumulative_probs2, type="o", col="tomato") points(x=0:x_max, y=cumulative_probs3, type="o", col="green4") legend("bottomright", col=c("dodgerblue", "tomato", "green4"), lwd=3, legend=c("mu=0.1", "mu=0.5", "mu=0.9")) # Example 3 # Comparing the random generator output with # the theoretical probabilities mu <- 0.4 x_max <- 10 probs1 <- dDBH(x=0:x_max, mu=mu) names(probs1) <- 0:x_max x <- rDBH(n=1000, mu=mu) probs2 <- prop.table(table(x)) cn <- union(names(probs1), names(probs2)) height <- rbind(probs1[cn], probs2[cn]) mp <- barplot(height, beside = TRUE, names.arg = cn, col=c("dodgerblue3","firebrick3"), las=1, xlab="X", ylab="Proportion") legend("topright", legend=c("Theoretical", "Simulated"), bty="n", lwd=3, col=c("dodgerblue3","firebrick3"), lty=1) # Example 4 # Checking the quantile function mu <- 0.97 p <- seq(from=0, to=1, by = 0.01) qxx <- qDBH(p, mu, lower.tail = TRUE, log.p = FALSE) plot(p, qxx, type="s", lwd=2, col="green3", ylab="quantiles", main="Quantiles of BH(mu=0.97)")# Example 1 # Plotting the mass function for different parameter values plot(x=0:5, y=dDBH(x=0:5, mu=0.1), type="h", lwd=2, col="dodgerblue", las=1, ylab="P(X=x)", xlab="X", ylim=c(0, 1), main="Probability mu=0.1") plot(x=0:10, y=dDBH(x=0:10, mu=0.5), type="h", lwd=2, col="tomato", las=1, ylab="P(X=x)", xlab="X", ylim=c(0, 1), main="Probability mu=0.5") plot(x=0:15, y=dDBH(x=0:15, mu=0.9), type="h", lwd=2, col="green4", las=1, ylab="P(X=x)", xlab="X", ylim=c(0, 1), main="Probability mu=0.9") # Example 2 # Checking if the cumulative curves converge to 1 x_max <- 15 cumulative_probs1 <- pDBH(q=0:x_max, mu=0.1) cumulative_probs2 <- pDBH(q=0:x_max, mu=0.5) cumulative_probs3 <- pDBH(q=0:x_max, mu=0.9) plot(x=0:x_max, y=cumulative_probs1, col="dodgerblue", type="o", las=1, ylim=c(0, 1), main="Cumulative probability for Burr-Hatke", xlab="X", ylab="Probability") points(x=0:x_max, y=cumulative_probs2, type="o", col="tomato") points(x=0:x_max, y=cumulative_probs3, type="o", col="green4") legend("bottomright", col=c("dodgerblue", "tomato", "green4"), lwd=3, legend=c("mu=0.1", "mu=0.5", "mu=0.9")) # Example 3 # Comparing the random generator output with # the theoretical probabilities mu <- 0.4 x_max <- 10 probs1 <- dDBH(x=0:x_max, mu=mu) names(probs1) <- 0:x_max x <- rDBH(n=1000, mu=mu) probs2 <- prop.table(table(x)) cn <- union(names(probs1), names(probs2)) height <- rbind(probs1[cn], probs2[cn]) mp <- barplot(height, beside = TRUE, names.arg = cn, col=c("dodgerblue3","firebrick3"), las=1, xlab="X", ylab="Proportion") legend("topright", legend=c("Theoretical", "Simulated"), bty="n", lwd=3, col=c("dodgerblue3","firebrick3"), lty=1) # Example 4 # Checking the quantile function mu <- 0.97 p <- seq(from=0, to=1, by = 0.01) qxx <- qDBH(p, mu, lower.tail = TRUE, log.p = FALSE) plot(p, qxx, type="s", lwd=2, col="green3", ylab="quantiles", main="Quantiles of BH(mu=0.97)")
These functions define the density, distribution function, quantile
function and random generation for the Discrete generalized exponential distribution
a second type with parameters and .
dDGEII(x, mu = 0.5, sigma = 1.5, log = FALSE) pDGEII(q, mu = 0.5, sigma = 1.5, lower.tail = TRUE, log.p = FALSE) rDGEII(n, mu = 0.5, sigma = 1.5) qDGEII(p, mu = 0.5, sigma = 1.5, lower.tail = TRUE, log.p = FALSE)dDGEII(x, mu = 0.5, sigma = 1.5, log = FALSE) pDGEII(q, mu = 0.5, sigma = 1.5, lower.tail = TRUE, log.p = FALSE) rDGEII(n, mu = 0.5, sigma = 1.5) qDGEII(p, mu = 0.5, sigma = 1.5, lower.tail = TRUE, log.p = FALSE)
x, q
|
vector of (non-negative integer) quantiles. |
mu |
vector of the mu parameter. |
sigma |
vector of the sigma parameter. |
log, log.p
|
logical; if TRUE, probabilities p are given as log(p). |
lower.tail |
logical; if TRUE (default), probabilities are |
n |
number of random values to return. |
p |
vector of probabilities. |
The DGEII distribution with parameters and
has a support 0, 1, 2, ... and mass function given by
with and . If , the DGEII distribution
reduces to the geometric distribution with success probability .
Note: in this implementation we changed the original parameters
to and to ,
we did it to implement this distribution within gamlss framework.
dDGEII gives the density, pDGEII gives the distribution
function, qDGEII gives the quantile function, rDGEII
generates random deviates.
Valentina Hurtado Sepulveda, [email protected]
Nekoukhou, V., Alamatsaz, M. H., & Bidram, H. (2013). Discrete generalized exponential distribution of a second type. Statistics, 47(4), 876-887.
# Example 1 # Plotting the mass function for different parameter values x_max <- 40 probs1 <- dDGEII(x=0:x_max, mu=0.1, sigma=5) probs2 <- dDGEII(x=0:x_max, mu=0.5, sigma=5) probs3 <- dDGEII(x=0:x_max, mu=0.9, sigma=5) # To plot the first k values plot(x=0:x_max, y=probs1, type="o", lwd=2, col="dodgerblue", las=1, ylab="P(X=x)", xlab="X", main="Probability for DGEII", ylim=c(0, 0.60)) points(x=0:x_max, y=probs2, type="o", lwd=2, col="tomato") points(x=0:x_max, y=probs3, type="o", lwd=2, col="green4") legend("topright", col=c("dodgerblue", "tomato", "green4"), lwd=3, legend=c("mu=0.1, sigma=5", "mu=0.5, sigma=5", "mu=0.9, sigma=5")) # Example 2 # Checking if the cumulative curves converge to 1 #plot1 x_max <- 10 plot_discrete_cdf(x=0:x_max, fx=dDGEII(x=0:x_max, mu=0.3, sigma=15), col="dodgerblue", main="CDF for DGEII", lwd=3) legend("bottomright", legend="mu=0.3, sigma=15", col="dodgerblue", lty=1, lwd=2, cex=0.8) #plot2 plot_discrete_cdf(x=0:x_max, fx=dDGEII(x=0:x_max, mu=0.5, sigma=30), col="tomato", main="CDF for DGEII", lwd=3) legend("bottomright", legend="mu=0.5, sigma=30", col="tomato", lty=1, lwd=2, cex=0.8) #plot3 plot_discrete_cdf(x=0:x_max, fx=dDGEII(x=0:x_max, mu=0.5, sigma=50), col="green4", main="CDF for DGEII", lwd=3) legend("bottomright", legend="mu=0.5, sigma=50", col="green4", lty=1, lwd=2, cex=0.8) # Example 3 # Comparing the random generator output with # the theoretical probabilities x_max <- 15 probs1 <- dDGEII(x=0:x_max, mu=0.5, sigma=5) names(probs1) <- 0:x_max x <- rDGEII(n=1000, mu=0.5, sigma=5) probs2 <- prop.table(table(x)) cn <- union(names(probs1), names(probs2)) height <- rbind(probs1[cn], probs2[cn]) mp <- barplot(height, beside=TRUE, names.arg=cn, col=c("dodgerblue3","firebrick3"), las=1, xlab="X", ylab="Proportion") legend("topright", legend=c("Theoretical", "Simulated"), bty="n", lwd=3, col=c("dodgerblue3","firebrick3"), lty=1) # Example 4 # Checking the quantile function mu <- 0.5 sigma <- 5 p <- seq(from=0, to=1, by=0.01) qxx <- qDGEII(p=p, mu=mu, sigma=sigma, lower.tail=TRUE, log.p=FALSE) plot(p, qxx, type="s", lwd=2, col="green3", ylab="quantiles", main="Quantiles of DDGEII(mu=0.5, sigma=5)")# Example 1 # Plotting the mass function for different parameter values x_max <- 40 probs1 <- dDGEII(x=0:x_max, mu=0.1, sigma=5) probs2 <- dDGEII(x=0:x_max, mu=0.5, sigma=5) probs3 <- dDGEII(x=0:x_max, mu=0.9, sigma=5) # To plot the first k values plot(x=0:x_max, y=probs1, type="o", lwd=2, col="dodgerblue", las=1, ylab="P(X=x)", xlab="X", main="Probability for DGEII", ylim=c(0, 0.60)) points(x=0:x_max, y=probs2, type="o", lwd=2, col="tomato") points(x=0:x_max, y=probs3, type="o", lwd=2, col="green4") legend("topright", col=c("dodgerblue", "tomato", "green4"), lwd=3, legend=c("mu=0.1, sigma=5", "mu=0.5, sigma=5", "mu=0.9, sigma=5")) # Example 2 # Checking if the cumulative curves converge to 1 #plot1 x_max <- 10 plot_discrete_cdf(x=0:x_max, fx=dDGEII(x=0:x_max, mu=0.3, sigma=15), col="dodgerblue", main="CDF for DGEII", lwd=3) legend("bottomright", legend="mu=0.3, sigma=15", col="dodgerblue", lty=1, lwd=2, cex=0.8) #plot2 plot_discrete_cdf(x=0:x_max, fx=dDGEII(x=0:x_max, mu=0.5, sigma=30), col="tomato", main="CDF for DGEII", lwd=3) legend("bottomright", legend="mu=0.5, sigma=30", col="tomato", lty=1, lwd=2, cex=0.8) #plot3 plot_discrete_cdf(x=0:x_max, fx=dDGEII(x=0:x_max, mu=0.5, sigma=50), col="green4", main="CDF for DGEII", lwd=3) legend("bottomright", legend="mu=0.5, sigma=50", col="green4", lty=1, lwd=2, cex=0.8) # Example 3 # Comparing the random generator output with # the theoretical probabilities x_max <- 15 probs1 <- dDGEII(x=0:x_max, mu=0.5, sigma=5) names(probs1) <- 0:x_max x <- rDGEII(n=1000, mu=0.5, sigma=5) probs2 <- prop.table(table(x)) cn <- union(names(probs1), names(probs2)) height <- rbind(probs1[cn], probs2[cn]) mp <- barplot(height, beside=TRUE, names.arg=cn, col=c("dodgerblue3","firebrick3"), las=1, xlab="X", ylab="Proportion") legend("topright", legend=c("Theoretical", "Simulated"), bty="n", lwd=3, col=c("dodgerblue3","firebrick3"), lty=1) # Example 4 # Checking the quantile function mu <- 0.5 sigma <- 5 p <- seq(from=0, to=1, by=0.01) qxx <- qDGEII(p=p, mu=mu, sigma=sigma, lower.tail=TRUE, log.p=FALSE) plot(p, qxx, type="s", lwd=2, col="green3", ylab="quantiles", main="Quantiles of DDGEII(mu=0.5, sigma=5)")
These functions define the density, distribution function, quantile
function and random generation for the discrete Inverted Kumaraswamy, DIKUM(), distribution
with parameters and .
dDIKUM(x, mu = 1, sigma = 5, log = FALSE) pDIKUM(q, mu = 1, sigma = 5, lower.tail = TRUE, log.p = FALSE) rDIKUM(n, mu = 1, sigma = 5) qDIKUM(p, mu = 1, sigma = 5, lower.tail = TRUE, log.p = FALSE)dDIKUM(x, mu = 1, sigma = 5, log = FALSE) pDIKUM(q, mu = 1, sigma = 5, lower.tail = TRUE, log.p = FALSE) rDIKUM(n, mu = 1, sigma = 5) qDIKUM(p, mu = 1, sigma = 5, lower.tail = TRUE, log.p = FALSE)
x, q
|
vector of (non-negative integer) quantiles. |
mu |
vector of the mu parameter. |
sigma |
vector of the sigma parameter. |
log, log.p
|
logical; if TRUE, probabilities p are given as log(p). |
lower.tail |
logical; if TRUE (default), probabilities are |
n |
number of random values to return. |
p |
vector of probabilities. |
The discrete Inverted Kumaraswamy distribution with parameters and
has a support 0, 1, 2, ... and density given by
with and .
Note: in this implementation we changed the original parameters and
for and respectively, we did it to implement this distribution within gamlss framework.
dDIKUM gives the density, pDIKUM gives the distribution
function, qDIKUM gives the quantile function, rDIKUM
generates random deviates.
Daniel Felipe Villa Rengifo, [email protected]
El-Helbawy, A. A., Hegazy, M. A., Al-Dayian, G. R., & Abd EL-Kader, R. E. (2022). A discrete analog of the inverted Kumaraswamy distribution: properties and estimation with application to COVID-19 data. Pakistan Journal of Statistics and Operation Research, 18(1), 297-328.
# Example 1 # Plotting the mass function for different parameter values x_max <- 30 probs1 <- dDIKUM(x=0:x_max, mu=1, sigma=5) probs2 <- dDIKUM(x=0:x_max, mu=1, sigma=20) probs3 <- dDIKUM(x=0:x_max, mu=1, sigma=50) # To plot the first k values plot(x=0:x_max, y=probs1, type="o", lwd=2, col="dodgerblue", las=1, ylab="P(X=x)", xlab="X", main="Probability for Inverted Kumaraswamy Distribution", ylim=c(0, 0.12)) points(x=0:x_max, y=probs2, type="o", lwd=2, col="tomato") points(x=0:x_max, y=probs3, type="o", lwd=2, col="green4") legend("topright", col=c("dodgerblue", "tomato", "green4"), lwd=3, legend=c("mu=1, sigma=5", "mu=1, sigma=20", "mu=1, sigma=50")) # Example 2 # Checking if the cumulative curves converge to 1 x_max <- 500 cumulative_probs1 <- pDIKUM(q=0:x_max, mu=1, sigma=5) cumulative_probs2 <- pDIKUM(q=0:x_max, mu=1, sigma=20) cumulative_probs3 <- pDIKUM(q=0:x_max, mu=1, sigma=50) plot(x=0:x_max, y=cumulative_probs1, col="dodgerblue", type="o", las=1, ylim=c(0, 1), main="Cumulative probability for Inverted Kumaraswamy Distribution", xlab="X", ylab="Probability") points(x=0:x_max, y=cumulative_probs2, type="o", col="tomato") points(x=0:x_max, y=cumulative_probs3, type="o", col="green4") legend("bottomright", col=c("dodgerblue", "tomato", "green4"), lwd=3, legend=c("mu=1, sigma=5", "mu=1, sigma=20", "mu=1, sigma=50")) # Example 3 # Comparing the random generator output with # the theoretical probabilities x_max <- 20 probs1 <- dDIKUM(x=0:x_max, mu=3, sigma=20) names(probs1) <- 0:x_max x <- rDIKUM(n=1000, mu=3, sigma=20) probs2 <- prop.table(table(x)) cn <- union(names(probs1), names(probs2)) height <- rbind(probs1[cn], probs2[cn]) nombres <- cn mp <- barplot(height, beside = TRUE, names.arg = nombres, col=c("dodgerblue3","firebrick3"), las=1, xlab="X", ylab="Proportion") legend("topright", legend=c("Theoretical", "Simulated"), bty="n", lwd=3, col=c("dodgerblue3","firebrick3"), lty=1) # Example 4 # Checking the quantile function mu <- 1 sigma <- 5 p <- seq(from=0.01, to=0.99, by=0.1) qxx <- qDIKUM(p=p, mu=mu, sigma=sigma, lower.tail=TRUE, log.p=FALSE) plot(p, qxx, type="s", lwd=2, col="green3", ylab="quantiles", main="Quantiles of HP(mu = sigma = 3)")# Example 1 # Plotting the mass function for different parameter values x_max <- 30 probs1 <- dDIKUM(x=0:x_max, mu=1, sigma=5) probs2 <- dDIKUM(x=0:x_max, mu=1, sigma=20) probs3 <- dDIKUM(x=0:x_max, mu=1, sigma=50) # To plot the first k values plot(x=0:x_max, y=probs1, type="o", lwd=2, col="dodgerblue", las=1, ylab="P(X=x)", xlab="X", main="Probability for Inverted Kumaraswamy Distribution", ylim=c(0, 0.12)) points(x=0:x_max, y=probs2, type="o", lwd=2, col="tomato") points(x=0:x_max, y=probs3, type="o", lwd=2, col="green4") legend("topright", col=c("dodgerblue", "tomato", "green4"), lwd=3, legend=c("mu=1, sigma=5", "mu=1, sigma=20", "mu=1, sigma=50")) # Example 2 # Checking if the cumulative curves converge to 1 x_max <- 500 cumulative_probs1 <- pDIKUM(q=0:x_max, mu=1, sigma=5) cumulative_probs2 <- pDIKUM(q=0:x_max, mu=1, sigma=20) cumulative_probs3 <- pDIKUM(q=0:x_max, mu=1, sigma=50) plot(x=0:x_max, y=cumulative_probs1, col="dodgerblue", type="o", las=1, ylim=c(0, 1), main="Cumulative probability for Inverted Kumaraswamy Distribution", xlab="X", ylab="Probability") points(x=0:x_max, y=cumulative_probs2, type="o", col="tomato") points(x=0:x_max, y=cumulative_probs3, type="o", col="green4") legend("bottomright", col=c("dodgerblue", "tomato", "green4"), lwd=3, legend=c("mu=1, sigma=5", "mu=1, sigma=20", "mu=1, sigma=50")) # Example 3 # Comparing the random generator output with # the theoretical probabilities x_max <- 20 probs1 <- dDIKUM(x=0:x_max, mu=3, sigma=20) names(probs1) <- 0:x_max x <- rDIKUM(n=1000, mu=3, sigma=20) probs2 <- prop.table(table(x)) cn <- union(names(probs1), names(probs2)) height <- rbind(probs1[cn], probs2[cn]) nombres <- cn mp <- barplot(height, beside = TRUE, names.arg = nombres, col=c("dodgerblue3","firebrick3"), las=1, xlab="X", ylab="Proportion") legend("topright", legend=c("Theoretical", "Simulated"), bty="n", lwd=3, col=c("dodgerblue3","firebrick3"), lty=1) # Example 4 # Checking the quantile function mu <- 1 sigma <- 5 p <- seq(from=0.01, to=0.99, by=0.1) qxx <- qDIKUM(p=p, mu=mu, sigma=sigma, lower.tail=TRUE, log.p=FALSE) plot(p, qxx, type="s", lwd=2, col="green3", ylab="quantiles", main="Quantiles of HP(mu = sigma = 3)")
These functions define the density, distribution function, quantile
function and random generation for the Discrete Lindley distribution
with parameter .
dDLD(x, mu, log = FALSE) pDLD(q, mu, lower.tail = TRUE, log.p = FALSE) qDLD(p, mu, lower.tail = TRUE, log.p = FALSE) rDLD(n, mu = 0.5)dDLD(x, mu, log = FALSE) pDLD(q, mu, lower.tail = TRUE, log.p = FALSE) qDLD(p, mu, lower.tail = TRUE, log.p = FALSE) rDLD(n, mu = 0.5)
x, q
|
vector of (non-negative integer) quantiles. |
mu |
vector of positive values of this parameter. |
log, log.p
|
logical; if TRUE, probabilities p are given as log(p). |
lower.tail |
logical; if TRUE (default), probabilities are |
p |
vector of probabilities. |
n |
number of random values to return. |
The Discrete Lindley distribution with parameters has a support
0, 1, 2, ... and density given by
Note: in this implementation we changed the original parameters for ,
we did it to implement this distribution within gamlss framework.
dDLD gives the density, pDLD gives the distribution
function, qDLD gives the quantile function, rDLD
generates random deviates.
Yojan Andrés Alcaraz Pérez, [email protected]
Bakouch, H. S., Jazi, M. A., & Nadarajah, S. (2014). A new discrete distribution. Statistics, 48(1), 200-240.
DLD.
# Example 1 # Plotting the mass function for different parameter values plot(x=0:25, y=dDLD(x=0:25, mu=0.2), type="h", lwd=2, col="dodgerblue", las=1, ylab="P(X=x)", xlab="X", ylim=c(0, 0.1), main="Probability mu=0.2") plot(x=0:15, y=dDLD(x=0:15, mu=0.5), type="h", lwd=2, col="tomato", las=1, ylab="P(X=x)", xlab="X", ylim=c(0, 0.25), main="Probability mu=0.5") plot(x=0:8, y=dDLD(x=0:8, mu=1), type="h", lwd=2, col="green4", las=1, ylab="P(X=x)", xlab="X", ylim=c(0, 0.5), main="Probability mu=1") plot(x=0:5, y=dDLD(x=0:5, mu=2), type="h", lwd=2, col="red", las=1, ylab="P(X=x)", xlab="X", ylim=c(0, 1), main="Probability mu=2") # Example 2 # Checking if the cumulative curves converge to 1 x_max <- 10 cumulative_probs1 <- pDLD(q=0:x_max, mu=0.2) cumulative_probs2 <- pDLD(q=0:x_max, mu=0.5) cumulative_probs3 <- pDLD(q=0:x_max, mu=1) cumulative_probs4 <- pDLD(q=0:x_max, mu=2) plot(x=0:x_max, y=cumulative_probs1, col="dodgerblue", type="o", las=1, ylim=c(0, 1), main="Cumulative probability for Lindley", xlab="X", ylab="Probability") points(x=0:x_max, y=cumulative_probs2, type="o", col="tomato") points(x=0:x_max, y=cumulative_probs3, type="o", col="green4") points(x=0:x_max, y=cumulative_probs4, type="o", col="magenta") legend("bottomright", col=c("dodgerblue", "tomato", "green4", "magenta"), lwd=3, legend=c("mu=0.2", "mu=0.5", "mu=1", "mu=2")) # Example 3 # Comparing the random generator output with # the theoretical probabilities mu <- 0.6 x <- rDLD(n = 1000, mu = mu) x_max <- max(x) probs1 <- dDLD(x = 0:x_max, mu = mu) names(probs1) <- 0:x_max probs2 <- prop.table(table(x)) cn <- union(names(probs1), names(probs2)) height <- rbind(probs1[cn], probs2[cn]) mp <- barplot(height, beside = TRUE, names.arg = cn, col=c("dodgerblue3","firebrick3"), las=1, xlab="X", ylab="Proportion") legend("topright", legend=c("Theoretical", "Simulated"), bty="n", lwd=3, col=c("dodgerblue3","firebrick3"), lty=1) # Example 4 # Checking the quantile function mu <- 0.9 p <- seq(from=0, to=1, by=0.01) qxx <- qDLD(p, mu, lower.tail = TRUE, log.p = FALSE) plot(p, qxx, type="S", lwd=2, col="green3", ylab="quantiles", main="Quantiles of DL(mu=0.9)")# Example 1 # Plotting the mass function for different parameter values plot(x=0:25, y=dDLD(x=0:25, mu=0.2), type="h", lwd=2, col="dodgerblue", las=1, ylab="P(X=x)", xlab="X", ylim=c(0, 0.1), main="Probability mu=0.2") plot(x=0:15, y=dDLD(x=0:15, mu=0.5), type="h", lwd=2, col="tomato", las=1, ylab="P(X=x)", xlab="X", ylim=c(0, 0.25), main="Probability mu=0.5") plot(x=0:8, y=dDLD(x=0:8, mu=1), type="h", lwd=2, col="green4", las=1, ylab="P(X=x)", xlab="X", ylim=c(0, 0.5), main="Probability mu=1") plot(x=0:5, y=dDLD(x=0:5, mu=2), type="h", lwd=2, col="red", las=1, ylab="P(X=x)", xlab="X", ylim=c(0, 1), main="Probability mu=2") # Example 2 # Checking if the cumulative curves converge to 1 x_max <- 10 cumulative_probs1 <- pDLD(q=0:x_max, mu=0.2) cumulative_probs2 <- pDLD(q=0:x_max, mu=0.5) cumulative_probs3 <- pDLD(q=0:x_max, mu=1) cumulative_probs4 <- pDLD(q=0:x_max, mu=2) plot(x=0:x_max, y=cumulative_probs1, col="dodgerblue", type="o", las=1, ylim=c(0, 1), main="Cumulative probability for Lindley", xlab="X", ylab="Probability") points(x=0:x_max, y=cumulative_probs2, type="o", col="tomato") points(x=0:x_max, y=cumulative_probs3, type="o", col="green4") points(x=0:x_max, y=cumulative_probs4, type="o", col="magenta") legend("bottomright", col=c("dodgerblue", "tomato", "green4", "magenta"), lwd=3, legend=c("mu=0.2", "mu=0.5", "mu=1", "mu=2")) # Example 3 # Comparing the random generator output with # the theoretical probabilities mu <- 0.6 x <- rDLD(n = 1000, mu = mu) x_max <- max(x) probs1 <- dDLD(x = 0:x_max, mu = mu) names(probs1) <- 0:x_max probs2 <- prop.table(table(x)) cn <- union(names(probs1), names(probs2)) height <- rbind(probs1[cn], probs2[cn]) mp <- barplot(height, beside = TRUE, names.arg = cn, col=c("dodgerblue3","firebrick3"), las=1, xlab="X", ylab="Proportion") legend("topright", legend=c("Theoretical", "Simulated"), bty="n", lwd=3, col=c("dodgerblue3","firebrick3"), lty=1) # Example 4 # Checking the quantile function mu <- 0.9 p <- seq(from=0, to=1, by=0.01) qxx <- qDLD(p, mu, lower.tail = TRUE, log.p = FALSE) plot(p, qxx, type="S", lwd=2, col="green3", ylab="quantiles", main="Quantiles of DL(mu=0.9)")
These functions define the density, distribution function, quantile
function and random generation for the Discrete Marshall–Olkin Length Biased
Exponential DMOLBE distribution
with parameters and .
dDMOLBE(x, mu = 1, sigma = 1, log = FALSE) pDMOLBE(q, mu = 1, sigma = 1, lower.tail = TRUE, log.p = FALSE) rDMOLBE(n, mu = 1, sigma = 1) qDMOLBE(p, mu = 1, sigma = 1, lower.tail = TRUE, log.p = FALSE)dDMOLBE(x, mu = 1, sigma = 1, log = FALSE) pDMOLBE(q, mu = 1, sigma = 1, lower.tail = TRUE, log.p = FALSE) rDMOLBE(n, mu = 1, sigma = 1) qDMOLBE(p, mu = 1, sigma = 1, lower.tail = TRUE, log.p = FALSE)
x, q
|
vector of (non-negative integer) quantiles. |
mu |
vector of the mu parameter. |
sigma |
vector of the sigma parameter. |
log, log.p
|
logical; if TRUE, probabilities p are given as log(p). |
lower.tail |
logical; if TRUE (default), probabilities are |
n |
number of random values to return. |
p |
vector of probabilities. |
The DMOLBE distribution with parameters and
has a support 0, 1, 2, ... and mass function given by
with and
dDMOLBE gives the density, pDMOLBE gives the distribution
function, qDMOLBE gives the quantile function, rDMOLBE
generates random deviates.
Olga Usuga, [email protected]
Aljohani, H. M., Ahsan-ul-Haq, M., Zafar, J., Almetwally, E. M., Alghamdi, A. S., Hussam, E., & Muse, A. H. (2023). Analysis of Covid-19 data using discrete Marshall–Olkinin length biased exponential: Bayesian and frequentist approach. Scientific Reports, 13(1), 12243.
# Example 1 # Plotting the mass function for different parameter values x_max <- 20 probs1 <- dDMOLBE(x=0:x_max, mu=0.5, sigma=0.5) probs2 <- dDMOLBE(x=0:x_max, mu=5, sigma=0.5) probs3 <- dDMOLBE(x=0:x_max, mu=1, sigma=2) # To plot the first k values plot(x=0:x_max, y=probs1, type="o", lwd=2, col="dodgerblue", las=1, ylab="P(X=x)", xlab="X", main="Probability for DMOLBE", ylim=c(0, 0.80)) points(x=0:x_max, y=probs2, type="o", lwd=2, col="tomato") points(x=0:x_max, y=probs3, type="o", lwd=2, col="green4") legend("topright", col=c("dodgerblue", "tomato", "green4"), lwd=3, legend=c("mu=0.5, sigma=0.5", "mu=5, sigma=0.5", "mu=1, sigma=2")) # Example 2 # Checking if the cumulative curves converge to 1 x_max <- 20 cumulative_probs1 <- pDMOLBE(q=0:x_max, mu=0.5, sigma=0.5) cumulative_probs2 <- pDMOLBE(q=0:x_max, mu=5, sigma=0.5) cumulative_probs3 <- pDMOLBE(q=0:x_max, mu=1, sigma=2) plot(x=0:x_max, y=cumulative_probs1, col="dodgerblue", type="o", las=1, ylim=c(0, 1), main="Cumulative probability for DMOLBE", xlab="X", ylab="Probability") points(x=0:x_max, y=cumulative_probs2, type="o", col="tomato") points(x=0:x_max, y=cumulative_probs3, type="o", col="green4") legend("bottomright", col=c("dodgerblue", "tomato", "green4"), lwd=3, legend=c("mu=0.5, sigma=0.5", "mu=5, sigma=0.5", "mu=1, sigma=2")) # Example 3 # Comparing the random generator output with # the theoretical probabilities x_max <- 50 probs1 <- dDMOLBE(x=0:x_max, mu=5, sigma=0.5) names(probs1) <- 0:x_max x <- rDMOLBE(n=1000, mu=5, sigma=0.5) probs2 <- prop.table(table(x)) cn <- union(names(probs1), names(probs2)) height <- rbind(probs1[cn], probs2[cn]) mp <- barplot(height, beside = TRUE, names.arg = cn, col=c("dodgerblue3","firebrick3"), las=1, xlab="X", ylab="Proportion") legend("topright", legend=c("Theoretical", "Simulated"), bty="n", lwd=3, col=c("dodgerblue3","firebrick3"), lty=1) # Example 4 # Checking the quantile function mu <- 3 sigma <-3 p <- seq(from=0, to=1, by=0.01) qxx <- qDMOLBE(p=p, mu=mu, sigma=sigma, lower.tail=TRUE, log.p=FALSE) plot(p, qxx, type="s", lwd=2, col="green3", ylab="quantiles", main="Quantiles of DMOLBE(mu = 3, sigma = 3)")# Example 1 # Plotting the mass function for different parameter values x_max <- 20 probs1 <- dDMOLBE(x=0:x_max, mu=0.5, sigma=0.5) probs2 <- dDMOLBE(x=0:x_max, mu=5, sigma=0.5) probs3 <- dDMOLBE(x=0:x_max, mu=1, sigma=2) # To plot the first k values plot(x=0:x_max, y=probs1, type="o", lwd=2, col="dodgerblue", las=1, ylab="P(X=x)", xlab="X", main="Probability for DMOLBE", ylim=c(0, 0.80)) points(x=0:x_max, y=probs2, type="o", lwd=2, col="tomato") points(x=0:x_max, y=probs3, type="o", lwd=2, col="green4") legend("topright", col=c("dodgerblue", "tomato", "green4"), lwd=3, legend=c("mu=0.5, sigma=0.5", "mu=5, sigma=0.5", "mu=1, sigma=2")) # Example 2 # Checking if the cumulative curves converge to 1 x_max <- 20 cumulative_probs1 <- pDMOLBE(q=0:x_max, mu=0.5, sigma=0.5) cumulative_probs2 <- pDMOLBE(q=0:x_max, mu=5, sigma=0.5) cumulative_probs3 <- pDMOLBE(q=0:x_max, mu=1, sigma=2) plot(x=0:x_max, y=cumulative_probs1, col="dodgerblue", type="o", las=1, ylim=c(0, 1), main="Cumulative probability for DMOLBE", xlab="X", ylab="Probability") points(x=0:x_max, y=cumulative_probs2, type="o", col="tomato") points(x=0:x_max, y=cumulative_probs3, type="o", col="green4") legend("bottomright", col=c("dodgerblue", "tomato", "green4"), lwd=3, legend=c("mu=0.5, sigma=0.5", "mu=5, sigma=0.5", "mu=1, sigma=2")) # Example 3 # Comparing the random generator output with # the theoretical probabilities x_max <- 50 probs1 <- dDMOLBE(x=0:x_max, mu=5, sigma=0.5) names(probs1) <- 0:x_max x <- rDMOLBE(n=1000, mu=5, sigma=0.5) probs2 <- prop.table(table(x)) cn <- union(names(probs1), names(probs2)) height <- rbind(probs1[cn], probs2[cn]) mp <- barplot(height, beside = TRUE, names.arg = cn, col=c("dodgerblue3","firebrick3"), las=1, xlab="X", ylab="Proportion") legend("topright", legend=c("Theoretical", "Simulated"), bty="n", lwd=3, col=c("dodgerblue3","firebrick3"), lty=1) # Example 4 # Checking the quantile function mu <- 3 sigma <-3 p <- seq(from=0, to=1, by=0.01) qxx <- qDMOLBE(p=p, mu=mu, sigma=sigma, lower.tail=TRUE, log.p=FALSE) plot(p, qxx, type="s", lwd=2, col="green3", ylab="quantiles", main="Quantiles of DMOLBE(mu = 3, sigma = 3)")
These functions define the density, distribution function, quantile
function and random generation for the Discrete Perks, DPERKS(),
distribution
with parameters and .
dDPERKS(x, mu = 0.5, sigma = 0.5, log = FALSE) pDPERKS(q, mu = 0.5, sigma = 0.5, lower.tail = TRUE, log.p = FALSE) rDPERKS(n, mu = 0.5, sigma = 0.5) qDPERKS(p, mu = 0.5, sigma = 0.5, lower.tail = TRUE, log.p = FALSE)dDPERKS(x, mu = 0.5, sigma = 0.5, log = FALSE) pDPERKS(q, mu = 0.5, sigma = 0.5, lower.tail = TRUE, log.p = FALSE) rDPERKS(n, mu = 0.5, sigma = 0.5) qDPERKS(p, mu = 0.5, sigma = 0.5, lower.tail = TRUE, log.p = FALSE)
x, q
|
vector of (non-negative integer) quantiles. |
mu |
vector of the mu parameter. |
sigma |
vector of the sigma parameter. |
log, log.p
|
logical; if TRUE, probabilities p are given as log(p). |
lower.tail |
logical; if TRUE (default), probabilities are |
n |
number of random values to return. |
p |
vector of probabilities. |
The discrete Perks distribution with parameters and
has a support 0, 1, 2, ... and density given by
Note: in this implementation we changed the original parameters
for and for ,
we did it to implement this distribution within gamlss framework.
dDPERKS gives the density, pDPERKS gives the distribution
function, qDPERKS gives the quantile function, rDPERKS
generates random deviates.
Veronica Seguro Varela, [email protected]
Tyagi, A., Choudhary, N., & Singh, B. (2020). A new discrete distribution: Theory and applications to discrete failure lifetime and count data. J. Appl. Probab. Statist, 15, 117-143.
# Example 1 # Plotting the mass function for different parameter values x_max <- 25 probs1 <- dDPERKS(x=0:x_max, mu=0.001, sigma=0.52) probs2 <- dDPERKS(x=0:x_max, mu=0.001, sigma=0.85) probs3 <- dDPERKS(x=0:x_max, mu=0.001, sigma=1.5) # To plot the first k values plot(x=0:x_max, y=probs1, type="o", lwd=2, col="green4", las=1, ylab="P(X=x)", xlab="X", main="Probability for DPERKS", ylim=c(0, 0.40)) points(x=0:x_max, y=probs2, type="o", lwd=2, col="tomato") points(x=0:x_max, y=probs3, type="o", lwd=2, col="black") legend("topright", col=c("green4", "tomato", "black"), lwd=3, legend=c("mu=0.001, sigma=0.52 ", "mu=0.001, sigma=0.85", "mu=0.001, sigma=1.5")) # Example 2 # Checking if the cumulative curves converge to 1 x_max <- 25 cumulative_probs1 <- pDPERKS(q=0:x_max, mu=0.001, sigma=0.52) cumulative_probs2 <- pDPERKS(q=0:x_max, mu=0.001, sigma=0.85) cumulative_probs3 <- pDPERKS(q=0:x_max, mu=0.001, sigma=1.5) plot(x=0:x_max, y=cumulative_probs1, col="green4", type="o", las=1, ylim=c(0, 1), main="Cumulative probability for DPERKS", xlab="X", ylab="Probability") points(x=0:x_max, y=cumulative_probs2, type="o", col="tomato") points(x=0:x_max, y=cumulative_probs3, type="o", col="black") legend("bottomright", col=c("green4", "tomato", "black"), lwd=3, legend=c("mu=0.001, sigma=0.52 ", "mu=0.001, sigma=0.85", "mu=0.001, sigma=1.5")) # Example 3 # Comparing the random generator output with the theoretical probabilities x_max <- 20 mu <- 2.5 sigma <- 0.4 probs1 <- dDPERKS(x=0:x_max, mu=mu, sigma=sigma) names(probs1) <- 0:x_max x <- rDPERKS(n=10000, mu=mu, sigma=sigma) probs2 <- prop.table(table(x)) cn <- union(names(probs1), names(probs2)) height <- rbind(probs1[cn], probs2[cn]) nombres <- cn mp <- barplot(height, beside = TRUE, names.arg = nombres, col=c("dodgerblue3","firebrick3"), las=1, xlab="X", ylab="Proportion") legend("topright", legend=c("Theoretical", "Simulated"), bty="n", lwd=3, col=c("dodgerblue3","firebrick3"), lty=1) # Example 4 # Checking the quantile function mu <- 0.2 sigma <- 0.2 p <- seq(from=0, to=1, by=0.01) qxx <- qDPERKS(p=p, mu=mu, sigma=sigma, lower.tail=TRUE, log.p=FALSE) plot(p, qxx, type="s", lwd=2, col="green3", ylab="quantiles", main="Quantiles of DPERKS(mu = sigma = 0.2)")# Example 1 # Plotting the mass function for different parameter values x_max <- 25 probs1 <- dDPERKS(x=0:x_max, mu=0.001, sigma=0.52) probs2 <- dDPERKS(x=0:x_max, mu=0.001, sigma=0.85) probs3 <- dDPERKS(x=0:x_max, mu=0.001, sigma=1.5) # To plot the first k values plot(x=0:x_max, y=probs1, type="o", lwd=2, col="green4", las=1, ylab="P(X=x)", xlab="X", main="Probability for DPERKS", ylim=c(0, 0.40)) points(x=0:x_max, y=probs2, type="o", lwd=2, col="tomato") points(x=0:x_max, y=probs3, type="o", lwd=2, col="black") legend("topright", col=c("green4", "tomato", "black"), lwd=3, legend=c("mu=0.001, sigma=0.52 ", "mu=0.001, sigma=0.85", "mu=0.001, sigma=1.5")) # Example 2 # Checking if the cumulative curves converge to 1 x_max <- 25 cumulative_probs1 <- pDPERKS(q=0:x_max, mu=0.001, sigma=0.52) cumulative_probs2 <- pDPERKS(q=0:x_max, mu=0.001, sigma=0.85) cumulative_probs3 <- pDPERKS(q=0:x_max, mu=0.001, sigma=1.5) plot(x=0:x_max, y=cumulative_probs1, col="green4", type="o", las=1, ylim=c(0, 1), main="Cumulative probability for DPERKS", xlab="X", ylab="Probability") points(x=0:x_max, y=cumulative_probs2, type="o", col="tomato") points(x=0:x_max, y=cumulative_probs3, type="o", col="black") legend("bottomright", col=c("green4", "tomato", "black"), lwd=3, legend=c("mu=0.001, sigma=0.52 ", "mu=0.001, sigma=0.85", "mu=0.001, sigma=1.5")) # Example 3 # Comparing the random generator output with the theoretical probabilities x_max <- 20 mu <- 2.5 sigma <- 0.4 probs1 <- dDPERKS(x=0:x_max, mu=mu, sigma=sigma) names(probs1) <- 0:x_max x <- rDPERKS(n=10000, mu=mu, sigma=sigma) probs2 <- prop.table(table(x)) cn <- union(names(probs1), names(probs2)) height <- rbind(probs1[cn], probs2[cn]) nombres <- cn mp <- barplot(height, beside = TRUE, names.arg = nombres, col=c("dodgerblue3","firebrick3"), las=1, xlab="X", ylab="Proportion") legend("topright", legend=c("Theoretical", "Simulated"), bty="n", lwd=3, col=c("dodgerblue3","firebrick3"), lty=1) # Example 4 # Checking the quantile function mu <- 0.2 sigma <- 0.2 p <- seq(from=0, to=1, by=0.01) qxx <- qDPERKS(p=p, mu=mu, sigma=sigma, lower.tail=TRUE, log.p=FALSE) plot(p, qxx, type="s", lwd=2, col="green3", ylab="quantiles", main="Quantiles of DPERKS(mu = sigma = 0.2)")
These functions define the density, distribution function, quantile
function and random generation for the
discrete power-Ailamujia distribution
with parameters and .
dDsPA(x, mu, sigma, log = FALSE) pDsPA(q, mu, sigma, lower.tail = TRUE, log.p = FALSE) qDsPA(p, mu = 1, sigma = 1, lower.tail = TRUE, log.p = FALSE) rDsPA(n, mu, sigma)dDsPA(x, mu, sigma, log = FALSE) pDsPA(q, mu, sigma, lower.tail = TRUE, log.p = FALSE) qDsPA(p, mu = 1, sigma = 1, lower.tail = TRUE, log.p = FALSE) rDsPA(n, mu, sigma)
x, q
|
vector of (non-negative integer) quantiles. |
mu |
vector of the mu parameter. |
sigma |
vector of the sigma parameter. |
log, log.p
|
logical; if TRUE, probabilities p are given as log(p). |
lower.tail |
logical; if TRUE (default), probabilities are |
p |
vector of probabilities. |
n |
number of random values to return. |
The DsPA distribution with parameters and has a support
0, 1, 2, ...
Note:in this implementation we changed the original parameters
and for and respectively,
we did it to implement this distribution within gamlss framework.
dDsPA gives the density, pDsPA gives the distribution
function, qDsPA gives the quantile function.
Maria Camila Mena Romana, [email protected]
Alghamdi, A. S., Ahsan-ul-Haq, M., Babar, A., Aljohani, H. M., Afify, A. Z., & Cell, Q. E. (2022). The discrete power-Ailamujia distribution: properties, inference, and applications. AIMS Math, 7(5), 8344-8360.
DsPA.
# Example 1 # Plotting the mass function for different parameter values x_max <- 30 probs1 <- dDsPA(x=0:x_max, mu=1.2, sigma=0.5) probs2 <- dDsPA(x=0:x_max, mu=1.2, sigma=0.7) probs3 <- dDsPA(x=0:x_max, mu=1.2, sigma=0.9) # To plot the first k values plot(x=0:x_max, y=probs1, type="o", lwd=2, col="dodgerblue", las=1, ylab="P(X=x)", xlab="X", main="Probability for DsPA", ylim=c(0, 0.40)) points(x=0:x_max, y=probs2, type="o", lwd=2, col="tomato") points(x=0:x_max, y=probs3, type="o", lwd=2, col="green4") legend("topright", col=c("dodgerblue", "tomato", "green4"), lwd=3, legend=c("mu=1.2, sigma=0.5", "mu=1.2, sigma=0.7", "mu=1.2, sigma=0.9")) # Example 2 # Checking if the cumulative curves converge to 1 x_max <- 15 cumulative_probs1 <- pDsPA(q=0:x_max, mu=1.2, sigma=0.5) cumulative_probs2 <- pDsPA(q=0:x_max, mu=1.2, sigma=0.7) cumulative_probs3 <- pDsPA(q=0:x_max, mu=1.2, sigma=0.9) plot(x=0:x_max, y=cumulative_probs1, col="dodgerblue", type="o", las=1, ylim=c(0, 1), main="Cumulative probability for DsPA", xlab="X", ylab="Probability") points(x=0:x_max, y=cumulative_probs2, type="o", col="tomato") points(x=0:x_max, y=cumulative_probs3, type="o", col="green4") legend("bottomright", col=c("dodgerblue", "tomato", "green4"), lwd=3, legend=c("mu=1.2, sigma=0.5", "mu=1.2, sigma=0.7", "mu=1.2, sigma=0.9")) # Example 3 # Comparing the random generator output with # the theoretical probabilities x_max <- 50 probs1 <- dDsPA(x=0:x_max, mu=1.2, sigma=0.9) names(probs1) <- 0:x_max x <- rDsPA(n=1000, mu=1.2, sigma=0.9) probs2 <- prop.table(table(x)) cn <- union(names(probs1), names(probs2)) height <- rbind(probs1[cn], probs2[cn]) mp <- barplot(height, beside=TRUE, names.arg=cn, col=c("dodgerblue3","firebrick3"), las=1, xlab="X", ylab="Proportion") legend("topright", legend=c("Theoretical", "Simulated"), bty="n", lwd=3, col=c("dodgerblue3","firebrick3"), lty=1) # Example 4 # Checking the quantile function mu <- 1.2 sigma <- 0.9 p <- seq(from=0, to=1, by=0.01) qxx <- qDsPA(p=p, mu=mu, sigma=sigma, lower.tail=TRUE, log.p=FALSE) plot(p, qxx, type="s", lwd=2, col="green3", ylab="quantiles", main="Quantiles of DsPA(mu=1.2, sigma=0.9)")# Example 1 # Plotting the mass function for different parameter values x_max <- 30 probs1 <- dDsPA(x=0:x_max, mu=1.2, sigma=0.5) probs2 <- dDsPA(x=0:x_max, mu=1.2, sigma=0.7) probs3 <- dDsPA(x=0:x_max, mu=1.2, sigma=0.9) # To plot the first k values plot(x=0:x_max, y=probs1, type="o", lwd=2, col="dodgerblue", las=1, ylab="P(X=x)", xlab="X", main="Probability for DsPA", ylim=c(0, 0.40)) points(x=0:x_max, y=probs2, type="o", lwd=2, col="tomato") points(x=0:x_max, y=probs3, type="o", lwd=2, col="green4") legend("topright", col=c("dodgerblue", "tomato", "green4"), lwd=3, legend=c("mu=1.2, sigma=0.5", "mu=1.2, sigma=0.7", "mu=1.2, sigma=0.9")) # Example 2 # Checking if the cumulative curves converge to 1 x_max <- 15 cumulative_probs1 <- pDsPA(q=0:x_max, mu=1.2, sigma=0.5) cumulative_probs2 <- pDsPA(q=0:x_max, mu=1.2, sigma=0.7) cumulative_probs3 <- pDsPA(q=0:x_max, mu=1.2, sigma=0.9) plot(x=0:x_max, y=cumulative_probs1, col="dodgerblue", type="o", las=1, ylim=c(0, 1), main="Cumulative probability for DsPA", xlab="X", ylab="Probability") points(x=0:x_max, y=cumulative_probs2, type="o", col="tomato") points(x=0:x_max, y=cumulative_probs3, type="o", col="green4") legend("bottomright", col=c("dodgerblue", "tomato", "green4"), lwd=3, legend=c("mu=1.2, sigma=0.5", "mu=1.2, sigma=0.7", "mu=1.2, sigma=0.9")) # Example 3 # Comparing the random generator output with # the theoretical probabilities x_max <- 50 probs1 <- dDsPA(x=0:x_max, mu=1.2, sigma=0.9) names(probs1) <- 0:x_max x <- rDsPA(n=1000, mu=1.2, sigma=0.9) probs2 <- prop.table(table(x)) cn <- union(names(probs1), names(probs2)) height <- rbind(probs1[cn], probs2[cn]) mp <- barplot(height, beside=TRUE, names.arg=cn, col=c("dodgerblue3","firebrick3"), las=1, xlab="X", ylab="Proportion") legend("topright", legend=c("Theoretical", "Simulated"), bty="n", lwd=3, col=c("dodgerblue3","firebrick3"), lty=1) # Example 4 # Checking the quantile function mu <- 1.2 sigma <- 0.9 p <- seq(from=0, to=1, by=0.01) qxx <- qDsPA(p=p, mu=mu, sigma=sigma, lower.tail=TRUE, log.p=FALSE) plot(p, qxx, type="s", lwd=2, col="green3", ylab="quantiles", main="Quantiles of DsPA(mu=1.2, sigma=0.9)")
The function DGEII() defines the
Discrete generalized exponential distribution of a Second type
a two parameter distribution,
for a gamlss.family object to be used in GAMLSS
fitting using the function gamlss().
DGEII(mu.link = "logit", sigma.link = "log")DGEII(mu.link = "logit", sigma.link = "log")
mu.link |
defines the mu.link, with "logit" link as the default for the mu parameter. Other links are "probit" and "cloglog"'(complementary log-log). |
sigma.link |
defines the sigma.link, with "log" link as the default for the sigma. |
The DGEII distribution with parameters and
has a support 0, 1, 2, ... and mass function given by
with and . If , the DGEII distribution
reduces to the geometric distribution with success probability .
Note: in this implementation we changed the original parameters
to and to ,
we did it to implement this distribution within gamlss framework.
Returns a gamlss.family object which can be used
to fit a DGEII distribution
in the gamlss() function.
Valentina Hurtado Sepúlveda, [email protected]
Nekoukhou, V., Alamatsaz, M. H., & Bidram, H. (2013). Discrete generalized exponential distribution of a second type. Statistics, 47(4), 876-887.
# Example 1 # Generating some random values with # known mu and sigma y <- rDGEII(n=100, mu=0.75, sigma=0.5) # Fitting the model library(gamlss) mod1 <- gamlss(y~1, family=DGEII, control=gamlss.control(n.cyc=500, trace=TRUE)) # Extracting the fitted values for mu and sigma # using the inverse link function inv_logit <- function(x) 1/(1 + exp(-x)) inv_logit(coef(mod1, what="mu")) exp(coef(mod1, what="sigma")) # Example 2 # Generating random values under some model # A function to simulate a data set with Y ~ DGEII gendat <- function(n) { x1 <- runif(n) x2 <- runif(n) mu <- inv_logit(1.7 - 2.8*x1) sigma <- exp(0.73 + 1*x2) y <- rDGEII(n=n, mu=mu, sigma=sigma) data.frame(y=y, x1=x1, x2=x2) } datos <- gendat(n=100) mod2 <- gamlss(y~x1, sigma.fo=~x2, family=DGEII, data=datos, control=gamlss.control(n.cyc=500, trace=TRUE)) summary(mod2) # Example 3 # Number of accidents to 647 women working on H. E. Shells # for 5 weeks. Taken from # Nekoukhou V, Alamatsaz MH, Bidram H (2013) page 886. y <- rep(x=0:5, times=c(447, 132, 42, 21, 3, 2)) mod3 <- gamlss(y~1, family=DGEII, control=gamlss.control(n.cyc=500, trace=TRUE)) # Extracting the fitted values for mu and sigma # using the inverse link function inv_logit <- function(x) 1/(1 + exp(-x)) inv_logit(coef(mod3, what="mu")) exp(coef(mod3, what="sigma"))# Example 1 # Generating some random values with # known mu and sigma y <- rDGEII(n=100, mu=0.75, sigma=0.5) # Fitting the model library(gamlss) mod1 <- gamlss(y~1, family=DGEII, control=gamlss.control(n.cyc=500, trace=TRUE)) # Extracting the fitted values for mu and sigma # using the inverse link function inv_logit <- function(x) 1/(1 + exp(-x)) inv_logit(coef(mod1, what="mu")) exp(coef(mod1, what="sigma")) # Example 2 # Generating random values under some model # A function to simulate a data set with Y ~ DGEII gendat <- function(n) { x1 <- runif(n) x2 <- runif(n) mu <- inv_logit(1.7 - 2.8*x1) sigma <- exp(0.73 + 1*x2) y <- rDGEII(n=n, mu=mu, sigma=sigma) data.frame(y=y, x1=x1, x2=x2) } datos <- gendat(n=100) mod2 <- gamlss(y~x1, sigma.fo=~x2, family=DGEII, data=datos, control=gamlss.control(n.cyc=500, trace=TRUE)) summary(mod2) # Example 3 # Number of accidents to 647 women working on H. E. Shells # for 5 weeks. Taken from # Nekoukhou V, Alamatsaz MH, Bidram H (2013) page 886. y <- rep(x=0:5, times=c(447, 132, 42, 21, 3, 2)) mod3 <- gamlss(y~1, family=DGEII, control=gamlss.control(n.cyc=500, trace=TRUE)) # Extracting the fitted values for mu and sigma # using the inverse link function inv_logit <- function(x) 1/(1 + exp(-x)) inv_logit(coef(mod3, what="mu")) exp(coef(mod3, what="sigma"))
These functions define the density, distribution function, quantile
function and random generation for the Generalized Geometric distribution
with parameters and .
dGGEO(x, mu = 0.5, sigma = 1, log = FALSE) pGGEO(q, mu = 0.5, sigma = 1, lower.tail = TRUE, log.p = FALSE) rGGEO(n, mu = 0.5, sigma = 1) qGGEO(p, mu = 0.5, sigma = 1, lower.tail = TRUE, log.p = FALSE)dGGEO(x, mu = 0.5, sigma = 1, log = FALSE) pGGEO(q, mu = 0.5, sigma = 1, lower.tail = TRUE, log.p = FALSE) rGGEO(n, mu = 0.5, sigma = 1) qGGEO(p, mu = 0.5, sigma = 1, lower.tail = TRUE, log.p = FALSE)
x, q
|
vector of (non-negative integer) quantiles. |
mu |
vector of the mu parameter. |
sigma |
vector of the sigma parameter. |
log, log.p
|
logical; if TRUE, probabilities p are given as log(p). |
lower.tail |
logical; if TRUE (default), probabilities are |
n |
number of random values to return. |
p |
vector of probabilities. |
The GGEO distribution with parameters and
has a support 0, 1, 2, ... and mass function given by
with and . If , the GGEO distribution
reduces to the geometric distribution with success probability .
Note: in this implementation we changed the original parameters
for and for ,
we did it to implement this distribution within gamlss framework.
dGGEO gives the density, pGGEO gives the distribution
function, qGGEO gives the quantile function, rGGEO
generates random deviates.
Valentina Hurtado Sepulveda, [email protected]
Gómez-Déniz, E. (2010). Another generalization of the geometric distribution. Test, 19, 399-415.
GGEO.
# Example 1 # Plotting the mass function for different parameter values x_max <- 80 probs1 <- dGGEO(x=0:x_max, mu=0.5, sigma=10) probs2 <- dGGEO(x=0:x_max, mu=0.7, sigma=30) probs3 <- dGGEO(x=0:x_max, mu=0.9, sigma=50) # To plot the first k values plot(x=0:x_max, y=probs1, type="o", lwd=2, col="dodgerblue", las=1, ylab="P(X=x)", xlab="X", main="Probability for GGEO", ylim=c(0, 0.20)) points(x=0:x_max, y=probs2, type="o", lwd=2, col="tomato") points(x=0:x_max, y=probs3, type="o", lwd=2, col="green4") legend("topright", col=c("dodgerblue", "tomato", "green4"), lwd=3, legend=c("mu=0.5, sigma=10", "mu=0.7, sigma=30", "mu=0.9, sigma=50")) # Example 2 # Checking if the cumulative curves converge to 1 x_max <- 10 plot_discrete_cdf(x=0:x_max, fx=dGGEO(x=0:x_max, mu=0.3, sigma=15), col="dodgerblue", main="CDF for GGEO", lwd= 3) legend("bottomright", legend="mu=0.3, sigma=15", col="dodgerblue", lty=1, lwd=2, cex=0.8) plot_discrete_cdf(x=0:x_max, fx=dGGEO(x=0:x_max, mu=0.5, sigma=30), col="tomato", main="CDF for GGEO", lwd=3) legend("bottomright", legend="mu=0.5, sigma=30", col="tomato", lty=1, lwd=2, cex=0.8) plot_discrete_cdf(x=0:x_max, fx=dGGEO(x=0:x_max, mu=0.5, sigma=50), col="green4", main="CDF for GGEO", lwd=3) legend("bottomright", legend="mu=0.5, sigma=50", col="green4", lty=1, lwd=2, cex=0.8) # Example 3 # Comparing the random generator output with # the theoretical probabilities x_max <- 15 probs1 <- dGGEO(x=0:x_max, mu=0.5, sigma=5) names(probs1) <- 0:x_max x <- rGGEO(n=1000, mu=0.5, sigma=5) probs2 <- prop.table(table(x)) cn <- union(names(probs1), names(probs2)) height <- rbind(probs1[cn], probs2[cn]) mp <- barplot(height, beside=TRUE, names.arg=cn, col=c("dodgerblue3", "firebrick3"), las=1, xlab="X", ylab="Proportion") legend("topright", legend=c("Theoretical", "Simulated"), bty="n", lwd=3, col=c("dodgerblue3","firebrick3"), lty=1) # Example 4 # Checking the quantile function mu <- 0.5 sigma <- 5 p <- seq(from=0, to=1, by=0.01) qxx <- qGGEO(p=p, mu=mu, sigma=sigma, lower.tail=TRUE, log.p=FALSE) plot(p, qxx, type="s", lwd=2, col="green3", ylab="quantiles", main="Quantiles of GGEO(mu=0.5, sigma=0.5)")# Example 1 # Plotting the mass function for different parameter values x_max <- 80 probs1 <- dGGEO(x=0:x_max, mu=0.5, sigma=10) probs2 <- dGGEO(x=0:x_max, mu=0.7, sigma=30) probs3 <- dGGEO(x=0:x_max, mu=0.9, sigma=50) # To plot the first k values plot(x=0:x_max, y=probs1, type="o", lwd=2, col="dodgerblue", las=1, ylab="P(X=x)", xlab="X", main="Probability for GGEO", ylim=c(0, 0.20)) points(x=0:x_max, y=probs2, type="o", lwd=2, col="tomato") points(x=0:x_max, y=probs3, type="o", lwd=2, col="green4") legend("topright", col=c("dodgerblue", "tomato", "green4"), lwd=3, legend=c("mu=0.5, sigma=10", "mu=0.7, sigma=30", "mu=0.9, sigma=50")) # Example 2 # Checking if the cumulative curves converge to 1 x_max <- 10 plot_discrete_cdf(x=0:x_max, fx=dGGEO(x=0:x_max, mu=0.3, sigma=15), col="dodgerblue", main="CDF for GGEO", lwd= 3) legend("bottomright", legend="mu=0.3, sigma=15", col="dodgerblue", lty=1, lwd=2, cex=0.8) plot_discrete_cdf(x=0:x_max, fx=dGGEO(x=0:x_max, mu=0.5, sigma=30), col="tomato", main="CDF for GGEO", lwd=3) legend("bottomright", legend="mu=0.5, sigma=30", col="tomato", lty=1, lwd=2, cex=0.8) plot_discrete_cdf(x=0:x_max, fx=dGGEO(x=0:x_max, mu=0.5, sigma=50), col="green4", main="CDF for GGEO", lwd=3) legend("bottomright", legend="mu=0.5, sigma=50", col="green4", lty=1, lwd=2, cex=0.8) # Example 3 # Comparing the random generator output with # the theoretical probabilities x_max <- 15 probs1 <- dGGEO(x=0:x_max, mu=0.5, sigma=5) names(probs1) <- 0:x_max x <- rGGEO(n=1000, mu=0.5, sigma=5) probs2 <- prop.table(table(x)) cn <- union(names(probs1), names(probs2)) height <- rbind(probs1[cn], probs2[cn]) mp <- barplot(height, beside=TRUE, names.arg=cn, col=c("dodgerblue3", "firebrick3"), las=1, xlab="X", ylab="Proportion") legend("topright", legend=c("Theoretical", "Simulated"), bty="n", lwd=3, col=c("dodgerblue3","firebrick3"), lty=1) # Example 4 # Checking the quantile function mu <- 0.5 sigma <- 5 p <- seq(from=0, to=1, by=0.01) qxx <- qGGEO(p=p, mu=mu, sigma=sigma, lower.tail=TRUE, log.p=FALSE) plot(p, qxx, type="s", lwd=2, col="green3", ylab="quantiles", main="Quantiles of GGEO(mu=0.5, sigma=0.5)")
These functions define the density, distribution function, quantile
function and random generation for the hyper-Poisson, HYPERPO(), distribution
with parameters and .
dHYPERPO(x, mu = 1, sigma = 1, log = FALSE) pHYPERPO(q, mu = 1, sigma = 1, lower.tail = TRUE, log.p = FALSE) rHYPERPO(n, mu = 1, sigma = 1) qHYPERPO(p, mu = 1, sigma = 1, lower.tail = TRUE, log.p = FALSE)dHYPERPO(x, mu = 1, sigma = 1, log = FALSE) pHYPERPO(q, mu = 1, sigma = 1, lower.tail = TRUE, log.p = FALSE) rHYPERPO(n, mu = 1, sigma = 1) qHYPERPO(p, mu = 1, sigma = 1, lower.tail = TRUE, log.p = FALSE)
x, q
|
vector of (non-negative integer) quantiles. |
mu |
vector of the mu parameter. |
sigma |
vector of the sigma parameter. |
log, log.p
|
logical; if TRUE, probabilities p are given as log(p). |
lower.tail |
logical; if TRUE (default), probabilities are |
n |
number of random values to return. |
p |
vector of probabilities. |
The hyper-Poisson distribution with parameters and
has a support 0, 1, 2, ... and density given by
where the function is defined as
and for and positive integer.
Note: in this implementation we changed the original parameters and
for and respectively, we did it to implement this distribution within gamlss framework.
dHYPERPO gives the density, pHYPERPO gives the distribution
function, qHYPERPO gives the quantile function, rHYPERPO
generates random deviates.
Freddy Hernandez, [email protected]
Sáez-Castillo, A. J., & Conde-Sánchez, A. (2013). A hyper-Poisson regression model for overdispersed and underdispersed count data. Computational Statistics & Data Analysis, 61, 148-157.
# Example 1 # Plotting the mass function for different parameter values x_max <- 30 probs1 <- dHYPERPO(x=0:x_max, mu=5, sigma=0.1) probs2 <- dHYPERPO(x=0:x_max, mu=5, sigma=1.0) probs3 <- dHYPERPO(x=0:x_max, mu=5, sigma=1.8) # To plot the first k values plot(x=0:x_max, y=probs1, type="o", lwd=2, col="dodgerblue", las=1, ylab="P(X=x)", xlab="X", main="Probability for hyper-Poisson", ylim=c(0, 0.20)) points(x=0:x_max, y=probs2, type="o", lwd=2, col="tomato") points(x=0:x_max, y=probs3, type="o", lwd=2, col="green4") legend("topright", col=c("dodgerblue", "tomato", "green4"), lwd=3, legend=c("mu=5, sigma=0.1", "mu=5, sigma=1.0", "mu=5, sigma=1.8")) # Example 2 # Checking if the cumulative curves converge to 1 x_max <- 15 cumulative_probs1 <- pHYPERPO(q=0:x_max, mu=5, sigma=0.1) cumulative_probs2 <- pHYPERPO(q=0:x_max, mu=5, sigma=1.0) cumulative_probs3 <- pHYPERPO(q=0:x_max, mu=5, sigma=1.8) plot(x=0:x_max, y=cumulative_probs1, col="dodgerblue", type="o", las=1, ylim=c(0, 1), main="Cumulative probability for hyper-Poisson", xlab="X", ylab="Probability") points(x=0:x_max, y=cumulative_probs2, type="o", col="tomato") points(x=0:x_max, y=cumulative_probs3, type="o", col="green4") legend("bottomright", col=c("dodgerblue", "tomato", "green4"), lwd=3, legend=c("mu=5, sigma=0.1", "mu=5, sigma=1.0", "mu=5, sigma=1.8")) # Example 3 # Comparing the random generator output with # the theoretical probabilities x_max <- 15 probs1 <- dHYPERPO(x=0:x_max, mu=3, sigma=1.1) names(probs1) <- 0:x_max x <- rHYPERPO(n=1000, mu=3, sigma=1.1) probs2 <- prop.table(table(x)) cn <- union(names(probs1), names(probs2)) height <- rbind(probs1[cn], probs2[cn]) nombres <- cn mp <- barplot(height, beside = TRUE, names.arg = nombres, col=c("dodgerblue3","firebrick3"), las=1, xlab="X", ylab="Proportion") legend("topright", legend=c("Theoretical", "Simulated"), bty="n", lwd=3, col=c("dodgerblue3","firebrick3"), lty=1) # Example 4 # Checking the quantile function mu <- 3 sigma <-3 p <- seq(from=0, to=1, by=0.01) qxx <- qHYPERPO(p=p, mu=mu, sigma=sigma, lower.tail=TRUE, log.p=FALSE) plot(p, qxx, type="s", lwd=2, col="green3", ylab="quantiles", main="Quantiles of HP(mu=3, sigma=3)")# Example 1 # Plotting the mass function for different parameter values x_max <- 30 probs1 <- dHYPERPO(x=0:x_max, mu=5, sigma=0.1) probs2 <- dHYPERPO(x=0:x_max, mu=5, sigma=1.0) probs3 <- dHYPERPO(x=0:x_max, mu=5, sigma=1.8) # To plot the first k values plot(x=0:x_max, y=probs1, type="o", lwd=2, col="dodgerblue", las=1, ylab="P(X=x)", xlab="X", main="Probability for hyper-Poisson", ylim=c(0, 0.20)) points(x=0:x_max, y=probs2, type="o", lwd=2, col="tomato") points(x=0:x_max, y=probs3, type="o", lwd=2, col="green4") legend("topright", col=c("dodgerblue", "tomato", "green4"), lwd=3, legend=c("mu=5, sigma=0.1", "mu=5, sigma=1.0", "mu=5, sigma=1.8")) # Example 2 # Checking if the cumulative curves converge to 1 x_max <- 15 cumulative_probs1 <- pHYPERPO(q=0:x_max, mu=5, sigma=0.1) cumulative_probs2 <- pHYPERPO(q=0:x_max, mu=5, sigma=1.0) cumulative_probs3 <- pHYPERPO(q=0:x_max, mu=5, sigma=1.8) plot(x=0:x_max, y=cumulative_probs1, col="dodgerblue", type="o", las=1, ylim=c(0, 1), main="Cumulative probability for hyper-Poisson", xlab="X", ylab="Probability") points(x=0:x_max, y=cumulative_probs2, type="o", col="tomato") points(x=0:x_max, y=cumulative_probs3, type="o", col="green4") legend("bottomright", col=c("dodgerblue", "tomato", "green4"), lwd=3, legend=c("mu=5, sigma=0.1", "mu=5, sigma=1.0", "mu=5, sigma=1.8")) # Example 3 # Comparing the random generator output with # the theoretical probabilities x_max <- 15 probs1 <- dHYPERPO(x=0:x_max, mu=3, sigma=1.1) names(probs1) <- 0:x_max x <- rHYPERPO(n=1000, mu=3, sigma=1.1) probs2 <- prop.table(table(x)) cn <- union(names(probs1), names(probs2)) height <- rbind(probs1[cn], probs2[cn]) nombres <- cn mp <- barplot(height, beside = TRUE, names.arg = nombres, col=c("dodgerblue3","firebrick3"), las=1, xlab="X", ylab="Proportion") legend("topright", legend=c("Theoretical", "Simulated"), bty="n", lwd=3, col=c("dodgerblue3","firebrick3"), lty=1) # Example 4 # Checking the quantile function mu <- 3 sigma <-3 p <- seq(from=0, to=1, by=0.01) qxx <- qHYPERPO(p=p, mu=mu, sigma=sigma, lower.tail=TRUE, log.p=FALSE) plot(p, qxx, type="s", lwd=2, col="green3", ylab="quantiles", main="Quantiles of HP(mu=3, sigma=3)")
These functions define the density, distribution function, quantile
function and random generation for the hyper-Poisson in
the second parameterization with parameters (as mean) and
as the dispersion parameter.
dHYPERPO2(x, mu = 1, sigma = 1, log = FALSE) pHYPERPO2(q, mu = 1, sigma = 1, lower.tail = TRUE, log.p = FALSE) rHYPERPO2(n, mu = 1, sigma = 1) qHYPERPO2(p, mu = 1, sigma = 1, lower.tail = TRUE, log.p = FALSE)dHYPERPO2(x, mu = 1, sigma = 1, log = FALSE) pHYPERPO2(q, mu = 1, sigma = 1, lower.tail = TRUE, log.p = FALSE) rHYPERPO2(n, mu = 1, sigma = 1) qHYPERPO2(p, mu = 1, sigma = 1, lower.tail = TRUE, log.p = FALSE)
x, q
|
vector of (non-negative integer) quantiles. |
mu |
vector of positive values of this parameter. |
sigma |
vector of positive values of this parameter. |
log, log.p
|
logical; if TRUE, probabilities p are given as log(p). |
lower.tail |
logical; if TRUE (default), probabilities are |
n |
number of random values to return |
p |
vector of probabilities. |
The hyper-Poisson distribution with parameters and
has a support 0, 1, 2, ...
Note: in this implementation the parameter is the mean
of the distribution and corresponds to
the dispersion parameter. If you fit a model with this parameterization,
the time will increase because an internal procedure to convert
to parameter.
dHYPERPO2 gives the density, pHYPERPO2 gives the distribution
function, qHYPERPO2 gives the quantile function, rHYPERPO2
generates random deviates.
Freddy Hernandez, [email protected]
Sáez-Castillo, A. J., & Conde-Sánchez, A. (2013). A hyper-Poisson regression model for overdispersed and underdispersed count data. Computational Statistics & Data Analysis, 61, 148-157.
# Example 1 # Plotting the mass function for different parameter values x_max <- 30 probs1 <- dHYPERPO2(x=0:x_max, sigma=0.01, mu=3) probs2 <- dHYPERPO2(x=0:x_max, sigma=0.50, mu=5) probs3 <- dHYPERPO2(x=0:x_max, sigma=1.00, mu=7) # To plot the first k values plot(x=0:x_max, y=probs1, type="o", lwd=2, col="dodgerblue", las=1, ylab="P(X=x)", xlab="X", main="Probability for hyper-Poisson", ylim=c(0, 0.30)) points(x=0:x_max, y=probs2, type="o", lwd=2, col="tomato") points(x=0:x_max, y=probs3, type="o", lwd=2, col="green4") legend("topright", col=c("dodgerblue", "tomato", "green4"), lwd=3, legend=c("sigma=0.01, mu=3", "sigma=0.50, mu=5", "sigma=1.00, mu=7")) # Example 2 # Checking if the cumulative curves converge to 1 x_max <- 15 cumulative_probs1 <- pHYPERPO2(q=0:x_max, mu=1, sigma=1.5) cumulative_probs2 <- pHYPERPO2(q=0:x_max, mu=3, sigma=1.5) cumulative_probs3 <- pHYPERPO2(q=0:x_max, mu=5, sigma=1.5) plot(x=0:x_max, y=cumulative_probs1, col="dodgerblue", type="o", las=1, ylim=c(0, 1), main="Cumulative probability for hyper-Poisson", xlab="X", ylab="Probability") points(x=0:x_max, y=cumulative_probs2, type="o", col="tomato") points(x=0:x_max, y=cumulative_probs3, type="o", col="green4") legend("bottomright", col=c("dodgerblue", "tomato", "green4"), lwd=3, legend=c("sigma=1.5, mu=1", "sigma=1.5, mu=3", "sigma=1.5, mu=5")) # Example 3 # Comparing the random generator output with # the theoretical probabilities x_max <- 15 probs1 <- dHYPERPO2(x=0:x_max, mu=3, sigma=1.1) names(probs1) <- 0:x_max x <- rHYPERPO2(n=1000, mu=3, sigma=1.1) probs2 <- prop.table(table(x)) cn <- union(names(probs1), names(probs2)) height <- rbind(probs1[cn], probs2[cn]) nombres <- cn mp <- barplot(height, beside = TRUE, names.arg = nombres, col=c('dodgerblue3','firebrick3'), las=1, xlab='X', ylab='Proportion') legend('topright', legend=c('Theoretical', 'Simulated'), bty='n', lwd=3, col=c('dodgerblue3','firebrick3'), lty=1) # Example 4 # Checking the quantile function mu <- 3 sigma <-3 p <- seq(from=0, to=1, by=0.01) qxx <- qHYPERPO2(p=p, mu=mu, sigma=sigma, lower.tail=TRUE, log.p=FALSE) plot(p, qxx, type="s", lwd=2, col="green3", ylab="quantiles", main="Quantiles of HP2(mu = sigma = 3)")# Example 1 # Plotting the mass function for different parameter values x_max <- 30 probs1 <- dHYPERPO2(x=0:x_max, sigma=0.01, mu=3) probs2 <- dHYPERPO2(x=0:x_max, sigma=0.50, mu=5) probs3 <- dHYPERPO2(x=0:x_max, sigma=1.00, mu=7) # To plot the first k values plot(x=0:x_max, y=probs1, type="o", lwd=2, col="dodgerblue", las=1, ylab="P(X=x)", xlab="X", main="Probability for hyper-Poisson", ylim=c(0, 0.30)) points(x=0:x_max, y=probs2, type="o", lwd=2, col="tomato") points(x=0:x_max, y=probs3, type="o", lwd=2, col="green4") legend("topright", col=c("dodgerblue", "tomato", "green4"), lwd=3, legend=c("sigma=0.01, mu=3", "sigma=0.50, mu=5", "sigma=1.00, mu=7")) # Example 2 # Checking if the cumulative curves converge to 1 x_max <- 15 cumulative_probs1 <- pHYPERPO2(q=0:x_max, mu=1, sigma=1.5) cumulative_probs2 <- pHYPERPO2(q=0:x_max, mu=3, sigma=1.5) cumulative_probs3 <- pHYPERPO2(q=0:x_max, mu=5, sigma=1.5) plot(x=0:x_max, y=cumulative_probs1, col="dodgerblue", type="o", las=1, ylim=c(0, 1), main="Cumulative probability for hyper-Poisson", xlab="X", ylab="Probability") points(x=0:x_max, y=cumulative_probs2, type="o", col="tomato") points(x=0:x_max, y=cumulative_probs3, type="o", col="green4") legend("bottomright", col=c("dodgerblue", "tomato", "green4"), lwd=3, legend=c("sigma=1.5, mu=1", "sigma=1.5, mu=3", "sigma=1.5, mu=5")) # Example 3 # Comparing the random generator output with # the theoretical probabilities x_max <- 15 probs1 <- dHYPERPO2(x=0:x_max, mu=3, sigma=1.1) names(probs1) <- 0:x_max x <- rHYPERPO2(n=1000, mu=3, sigma=1.1) probs2 <- prop.table(table(x)) cn <- union(names(probs1), names(probs2)) height <- rbind(probs1[cn], probs2[cn]) nombres <- cn mp <- barplot(height, beside = TRUE, names.arg = nombres, col=c('dodgerblue3','firebrick3'), las=1, xlab='X', ylab='Proportion') legend('topright', legend=c('Theoretical', 'Simulated'), bty='n', lwd=3, col=c('dodgerblue3','firebrick3'), lty=1) # Example 4 # Checking the quantile function mu <- 3 sigma <-3 p <- seq(from=0, to=1, by=0.01) qxx <- qHYPERPO2(p=p, mu=mu, sigma=sigma, lower.tail=TRUE, log.p=FALSE) plot(p, qxx, type="s", lwd=2, col="green3", ylab="quantiles", main="Quantiles of HP2(mu = sigma = 3)")
The function DIKUM() defines the
discrete Inverted Kumaraswamy distribution
a two parameter distribution,
for a gamlss.family object to be used in GAMLSS
fitting using the function gamlss().
DIKUM(mu.link = "log", sigma.link = "log")DIKUM(mu.link = "log", sigma.link = "log")
mu.link |
defines the mu.link, with "log" link as the default for the mu parameter. |
sigma.link |
defines the sigma.link, with "log" link as the default for the sigma. |
The discrete Inverted Kumaraswamy distribution with parameters and
has a support 0, 1, 2, ... and density given by
with and .
Note: in this implementation we changed the original parameters and
for and respectively, we did it to implement this distribution within gamlss framework.
Returns a gamlss.family object which can be used
to fit a discrete Inverted Kumaraswamy distribution
in the gamlss() function.
Daniel Felipe Villa Rengifo, [email protected]
El-Helbawy, A. A., Hegazy, M. A., Al-Dayian, G. R., & Abd EL-Kader, R. E. (2022). A discrete analog of the inverted Kumaraswamy distribution: properties and estimation with application to COVID-19 data. Pakistan Journal of Statistics and Operation Research, 18(1), 297-328.
# Example 1 # Generating some random values with # known mu and sigma set.seed(150) y <- rDIKUM(1000, mu=1, sigma=5) # Fitting the model library(gamlss) mod1 <- gamlss(y ~ 1, sigma.fo = ~1, family=DIKUM, control = gamlss.control(n.cyc=500, trace=FALSE)) # Extracting the fitted values for mu and sigma # using the inverse link function exp(coef(mod1, what="mu")) exp(coef(mod1, what="sigma")) # Example 2 # Generating random values under some model library(gamlss) # A function to simulate a data set with Y ~ DIKUM gendat <- function(n) { x1 <- runif(n, min=0.4, max=0.6) x2 <- runif(n, min=0.4, max=0.6) mu <- exp(1.21 - 3 * x1) # 0.75 approximately sigma <- exp(1.26 - 2 * x2) # 1.30 approximately y <- rDIKUM(n=n, mu=mu, sigma=sigma) data.frame(y=y, x1=x1, x2=x2) } dat <- gendat(n=1000) # Fitting the model mod2 <- gamlss(y ~ x1, sigma.fo = ~x2, family = "DIKUM", data=dat, control=gamlss.control(n.cyc=500, trace=FALSE)) summary(mod2)# Example 1 # Generating some random values with # known mu and sigma set.seed(150) y <- rDIKUM(1000, mu=1, sigma=5) # Fitting the model library(gamlss) mod1 <- gamlss(y ~ 1, sigma.fo = ~1, family=DIKUM, control = gamlss.control(n.cyc=500, trace=FALSE)) # Extracting the fitted values for mu and sigma # using the inverse link function exp(coef(mod1, what="mu")) exp(coef(mod1, what="sigma")) # Example 2 # Generating random values under some model library(gamlss) # A function to simulate a data set with Y ~ DIKUM gendat <- function(n) { x1 <- runif(n, min=0.4, max=0.6) x2 <- runif(n, min=0.4, max=0.6) mu <- exp(1.21 - 3 * x1) # 0.75 approximately sigma <- exp(1.26 - 2 * x2) # 1.30 approximately y <- rDIKUM(n=n, mu=mu, sigma=sigma) data.frame(y=y, x1=x1, x2=x2) } dat <- gendat(n=1000) # Fitting the model mod2 <- gamlss(y ~ x1, sigma.fo = ~x2, family = "DIKUM", data=dat, control=gamlss.control(n.cyc=500, trace=FALSE)) summary(mod2)
The function DLD() defines the
Discrete Lindley distribution
a single parameter distribution,
for a gamlss.family object to be used in GAMLSS
fitting using the function gamlss().
DLD(mu.link = "log")DLD(mu.link = "log")
mu.link |
defines the mu.link, with "log" link as the default for the mu parameter. |
The Discrete Lindley distribution with parameters has a support
0, 1, 2, ... and density given by
The parameter can be interpreted as a strict upper bound on the failure rate function
The conventional discrete distributions (such as geometric, Poisson, etc.) are not suitable for various scenarios like reliability, failure times, and counts. Consequently, alternative discrete distributions have been created by adapting well-known continuous models for reliability and failure times. Among these, the discrete Weibull distribution stands out as the most widely used. But models like these require two parameters and not many of the known discrete distributions can provide accurate models for both times and counts, which the Discrete Lindley distribution does.
Note: in this implementation we changed the original parameters for ,
we did it to implement this distribution within gamlss framework.
Returns a gamlss.family object which can be used
to fit a Discrete Lindley distribution
in the gamlss() function.
Yojan Andrés Alcaraz Pérez, [email protected]
Bakouch, H. S., Jazi, M. A., & Nadarajah, S. (2014). A new discrete distribution. Statistics, 48(1), 200-240.
dDLD.
# Example 1 # Generating some random values with # known mu y <- rDLD(n=100, mu=0.3) # Fitting the model library(gamlss) mod1 <- gamlss(y~1, family=DLD, control=gamlss.control(n.cyc=500, trace=FALSE)) # Extracting the fitted values for mu # using the inverse link function exp(coef(mod1, what="mu")) # Example 2 # Generating random values under some model # A function to simulate a data set with Y ~ DLD gendat <- function(n) { x1 <- runif(n) mu <- exp(2 - 4 * x1) y <- rDLD(n=n, mu=mu) data.frame(y=y, x1=x1) } set.seed(1235) datos <- gendat(n=150) mod2 <- NULL mod2 <- gamlss(y~x1, sigma.fo=~x2, family=DLD, data=datos, control=gamlss.control(n.cyc=500, trace=FALSE)) summary(mod2) # Example 3 # Survival times in days of 72 guinea pigs. # Taken from Bakouch et al (2014) page 26. y <- c(12, 15, 22, 24, 24, 32, 32, 33, 34, 38, 38, 43, 44, 48, 52, 53, 54, 54, 55, 56, 57, 58, 58, 59, 60, 60, 60, 60, 61, 62, 63, 65, 65, 67, 68, 70, 70, 72, 73, 75, 76, 76, 81, 83, 84, 85, 87, 91, 95, 96, 98, 99, 109, 110, 121, 127, 129, 131, 143, 146, 146, 175, 175, 211, 233, 258, 258, 263, 297, 341, 341, 376) mod3 <- gamlss(y~1, family=DLD, control=gamlss.control(n.cyc=500, trace=FALSE)) # Extracting the fitted values for mu # using the inverse link function exp(coef(mod3, what="mu")) # Example 4 # Remission times in weeks for 20 leukaemia patients. # Taken from Bakouch et al (2014) page 26. y <- c(1, 3, 3, 6, 7, 7, 10, 12, 14, 15, 18, 19, 22, 26, 28, 29, 34, 40, 48, 49) mod4 <- gamlss(y~1, family=DLD, control=gamlss.control(n.cyc=500, trace=FALSE)) # Extracting the fitted values for mu # using the inverse link function exp(coef(mod4, what="mu")) # Example 5 # Numbers of fires in Greece for the period from 1 # July 1998 to 31 August of the same year . # Taken from Bakouch et al (2014) page 26. y <- c(2, 4, 4, 3, 3, 1, 2, 4, 3, 1, 1, 0, 5, 5, 0, 3, 1, 1, 0, 1, 0, 2, 0, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 4, 2, 2, 1, 2, 1, 2, 0, 2, 2, 1, 0, 3, 2, 1, 2, 2, 7, 3, 5, 2, 5, 4, 5, 6, 5, 4, 3, 8, 43, 8, 4, 4, 3, 10, 5, 4, 5, 12, 3, 8, 12, 10, 11, 6, 1, 8, 9, 12, 9, 4, 8, 12, 11, 8, 6, 4, 7, 9, 15, 12, 15, 15, 12, 9, 16, 7, 11, 9, 11, 6, 5, 20, 9, 8, 8, 5, 7, 10, 6, 6, 5, 5, 15, 6, 8, 5, 6) mod5 <- gamlss(y~1, family=DLD, control=gamlss.control(n.cyc=500, trace=FALSE)) # Extracting the fitted values for mu # using the inverse link function exp(coef(mod5, what="mu")) # Example 6 # Final examination marks of space students in # mathematics in the Indian Institute of Technology at Kanpur. # Taken from Bakouch et al (2014) page 26. y <- c(29, 25, 50, 15, 13, 27, 15, 18, 7, 7, 8, 19, 12, 18, 5, 21, 15, 86, 21, 15, 14, 39, 15, 14, 70, 44, 6, 23, 58, 19, 50, 23, 11, 6, 34, 18, 28, 34, 12, 37, 4, 60, 20, 23, 40, 65, 19, 31) mod6 <- gamlss(y~1, family=DLD, control=gamlss.control(n.cyc=500, trace=FALSE)) # Extracting the fitted values for mu # using the inverse link function exp(coef(mod6, what="mu"))# Example 1 # Generating some random values with # known mu y <- rDLD(n=100, mu=0.3) # Fitting the model library(gamlss) mod1 <- gamlss(y~1, family=DLD, control=gamlss.control(n.cyc=500, trace=FALSE)) # Extracting the fitted values for mu # using the inverse link function exp(coef(mod1, what="mu")) # Example 2 # Generating random values under some model # A function to simulate a data set with Y ~ DLD gendat <- function(n) { x1 <- runif(n) mu <- exp(2 - 4 * x1) y <- rDLD(n=n, mu=mu) data.frame(y=y, x1=x1) } set.seed(1235) datos <- gendat(n=150) mod2 <- NULL mod2 <- gamlss(y~x1, sigma.fo=~x2, family=DLD, data=datos, control=gamlss.control(n.cyc=500, trace=FALSE)) summary(mod2) # Example 3 # Survival times in days of 72 guinea pigs. # Taken from Bakouch et al (2014) page 26. y <- c(12, 15, 22, 24, 24, 32, 32, 33, 34, 38, 38, 43, 44, 48, 52, 53, 54, 54, 55, 56, 57, 58, 58, 59, 60, 60, 60, 60, 61, 62, 63, 65, 65, 67, 68, 70, 70, 72, 73, 75, 76, 76, 81, 83, 84, 85, 87, 91, 95, 96, 98, 99, 109, 110, 121, 127, 129, 131, 143, 146, 146, 175, 175, 211, 233, 258, 258, 263, 297, 341, 341, 376) mod3 <- gamlss(y~1, family=DLD, control=gamlss.control(n.cyc=500, trace=FALSE)) # Extracting the fitted values for mu # using the inverse link function exp(coef(mod3, what="mu")) # Example 4 # Remission times in weeks for 20 leukaemia patients. # Taken from Bakouch et al (2014) page 26. y <- c(1, 3, 3, 6, 7, 7, 10, 12, 14, 15, 18, 19, 22, 26, 28, 29, 34, 40, 48, 49) mod4 <- gamlss(y~1, family=DLD, control=gamlss.control(n.cyc=500, trace=FALSE)) # Extracting the fitted values for mu # using the inverse link function exp(coef(mod4, what="mu")) # Example 5 # Numbers of fires in Greece for the period from 1 # July 1998 to 31 August of the same year . # Taken from Bakouch et al (2014) page 26. y <- c(2, 4, 4, 3, 3, 1, 2, 4, 3, 1, 1, 0, 5, 5, 0, 3, 1, 1, 0, 1, 0, 2, 0, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 4, 2, 2, 1, 2, 1, 2, 0, 2, 2, 1, 0, 3, 2, 1, 2, 2, 7, 3, 5, 2, 5, 4, 5, 6, 5, 4, 3, 8, 43, 8, 4, 4, 3, 10, 5, 4, 5, 12, 3, 8, 12, 10, 11, 6, 1, 8, 9, 12, 9, 4, 8, 12, 11, 8, 6, 4, 7, 9, 15, 12, 15, 15, 12, 9, 16, 7, 11, 9, 11, 6, 5, 20, 9, 8, 8, 5, 7, 10, 6, 6, 5, 5, 15, 6, 8, 5, 6) mod5 <- gamlss(y~1, family=DLD, control=gamlss.control(n.cyc=500, trace=FALSE)) # Extracting the fitted values for mu # using the inverse link function exp(coef(mod5, what="mu")) # Example 6 # Final examination marks of space students in # mathematics in the Indian Institute of Technology at Kanpur. # Taken from Bakouch et al (2014) page 26. y <- c(29, 25, 50, 15, 13, 27, 15, 18, 7, 7, 8, 19, 12, 18, 5, 21, 15, 86, 21, 15, 14, 39, 15, 14, 70, 44, 6, 23, 58, 19, 50, 23, 11, 6, 34, 18, 28, 34, 12, 37, 4, 60, 20, 23, 40, 65, 19, 31) mod6 <- gamlss(y~1, family=DLD, control=gamlss.control(n.cyc=500, trace=FALSE)) # Extracting the fitted values for mu # using the inverse link function exp(coef(mod6, what="mu"))
The function DMOLBE() defines the
Discrete Marshall-Olkin Length Biased Exponential distribution
a two parameter distribution,
for a gamlss.family object to be used in GAMLSS
fitting using the function gamlss().
DMOLBE(mu.link = "log", sigma.link = "log")DMOLBE(mu.link = "log", sigma.link = "log")
mu.link |
defines the mu.link, with "log" link as the default for the mu parameter. |
sigma.link |
defines the sigma.link, with "log" link as the default for the sigma. |
The DMOLBE distribution with parameters and
has a support 0, 1, 2, ... and mass function given by
with and
Returns a gamlss.family object which can be used
to fit a DMOLBE distribution
in the gamlss() function.
Olga Usuga, [email protected]
Aljohani, H. M., Ahsan-ul-Haq, M., Zafar, J., Almetwally, E. M., Alghamdi, A. S., Hussam, E., & Muse, A. H. (2023). Analysis of Covid-19 data using discrete Marshall–Olkinin length biased exponential: Bayesian and frequentist approach. Scientific Reports, 13(1), 12243.
# Example 1 # Generating some random values with # known mu and sigma set.seed(1234) y <- rDMOLBE(n=200, mu=3, sigma=7) # Fitting the model library(gamlss) mod1 <- gamlss(y~1, sigma.fo=~1, family=DMOLBE) # Extracting the fitted values for mu and sigma # using the inverse link function exp(coef(mod1, what="mu")) exp(coef(mod1, what="sigma")) # Example 2 # Generating random values under some model # A function to simulate a data set with Y ~ DMOLBE gendat <- function(n) { x1 <- runif(n) x2 <- runif(n) mu <- exp(1.21 - 3 * x1) # 0.75 approximately sigma <- exp(1.26 - 2 * x2) # 1.30 approximately y <- rDMOLBE(n=n, mu=mu, sigma=sigma) data.frame(y=y, x1=x1, x2=x2) } set.seed(123) dat <- gendat(n=200) # Fitting the model mod2 <- NULL mod2 <- gamlss(y~x1, sigma.fo=~x2, family=DMOLBE, data=dat, control=gamlss.control(n.cyc=500, trace=FALSE)) summary(mod2) # Example 3 # Data Set I (death due to coronavirus in China). The first data set is the number # of deaths due to coronavirus in China from 23 January to 28 March. # The data sets used in the paper was collected from 2020 year. The data set # is reported in https://www.worldometers.info/coronavirus/country/china/. # The data are: y <- c(8, 16, 15, 24, 26, 26, 38, 43, 46, 45, 57, 64, 65, 73, 73, 86, 89, 97, 108, 97, 146, 121, 143, 142, 105, 98, 136, 114, 118, 109, 97, 150, 71, 52, 29, 44, 47, 35, 42, 31, 38, 31, 30, 28, 27, 22, 17, 22, 11, 7, 13, 10, 14, 13, 11, 8, 3, 7, 6, 9, 7, 4, 6, 5, 3, 5) # Fitting the model mod3 <- gamlss(y~1, sigma.fo=~1, family=DMOLBE, control=gamlss.control(n.cyc=500, trace=FALSE)) summary(mod3) # Extracting the fitted values for mu and sigma # using the inverse link function mu_hat <- exp(coef(mod3, what="mu")) mu_hat sigma_hat <- exp(coef(mod3, what="sigma")) sigma_hat # Example 4 # Data Set II (daily death due to coronavirus in Pakistan). The second data # set is the daily deaths due to coronavirus in Pakistan from 18 March # to 30 June. The data sets used in the paper was collected from 2020 year. # The data is reported in # https://www.worldometers.info/coronavirus/country/Pakistan. # The data are: y <- c(1, 6, 6, 4, 4, 4, 1, 20, 5, 2, 3, 15, 17, 7, 8, 25, 8, 25, 11, 25, 16, 16, 12, 11, 20, 31, 42, 32, 23, 17, 19, 38, 50, 21, 14, 37, 23, 47, 31, 24, 9, 64, 39, 30, 36, 46, 32, 50, 34, 32, 34, 30, 28, 35, 57, 78, 88, 60, 78, 67, 82, 68, 97, 67, 65, 105, 83, 101, 107, 88, 178, 110, 136, 118, 136, 153, 119, 89, 105, 60, 148, 59, 73, 83, 49, 137, 91) # Fitting the model mod4 <- gamlss(y~1, sigma.fo=~1, family=DMOLBE, control=gamlss.control(n.cyc=500, trace=FALSE)) summary(mod4) # Extracting the fitted values for mu and sigma # using the inverse link function mu_hat <- exp(coef(mod4, what="mu")) mu_hat sigma_hat <- exp(coef(mod4, what="sigma")) sigma_hat# Example 1 # Generating some random values with # known mu and sigma set.seed(1234) y <- rDMOLBE(n=200, mu=3, sigma=7) # Fitting the model library(gamlss) mod1 <- gamlss(y~1, sigma.fo=~1, family=DMOLBE) # Extracting the fitted values for mu and sigma # using the inverse link function exp(coef(mod1, what="mu")) exp(coef(mod1, what="sigma")) # Example 2 # Generating random values under some model # A function to simulate a data set with Y ~ DMOLBE gendat <- function(n) { x1 <- runif(n) x2 <- runif(n) mu <- exp(1.21 - 3 * x1) # 0.75 approximately sigma <- exp(1.26 - 2 * x2) # 1.30 approximately y <- rDMOLBE(n=n, mu=mu, sigma=sigma) data.frame(y=y, x1=x1, x2=x2) } set.seed(123) dat <- gendat(n=200) # Fitting the model mod2 <- NULL mod2 <- gamlss(y~x1, sigma.fo=~x2, family=DMOLBE, data=dat, control=gamlss.control(n.cyc=500, trace=FALSE)) summary(mod2) # Example 3 # Data Set I (death due to coronavirus in China). The first data set is the number # of deaths due to coronavirus in China from 23 January to 28 March. # The data sets used in the paper was collected from 2020 year. The data set # is reported in https://www.worldometers.info/coronavirus/country/china/. # The data are: y <- c(8, 16, 15, 24, 26, 26, 38, 43, 46, 45, 57, 64, 65, 73, 73, 86, 89, 97, 108, 97, 146, 121, 143, 142, 105, 98, 136, 114, 118, 109, 97, 150, 71, 52, 29, 44, 47, 35, 42, 31, 38, 31, 30, 28, 27, 22, 17, 22, 11, 7, 13, 10, 14, 13, 11, 8, 3, 7, 6, 9, 7, 4, 6, 5, 3, 5) # Fitting the model mod3 <- gamlss(y~1, sigma.fo=~1, family=DMOLBE, control=gamlss.control(n.cyc=500, trace=FALSE)) summary(mod3) # Extracting the fitted values for mu and sigma # using the inverse link function mu_hat <- exp(coef(mod3, what="mu")) mu_hat sigma_hat <- exp(coef(mod3, what="sigma")) sigma_hat # Example 4 # Data Set II (daily death due to coronavirus in Pakistan). The second data # set is the daily deaths due to coronavirus in Pakistan from 18 March # to 30 June. The data sets used in the paper was collected from 2020 year. # The data is reported in # https://www.worldometers.info/coronavirus/country/Pakistan. # The data are: y <- c(1, 6, 6, 4, 4, 4, 1, 20, 5, 2, 3, 15, 17, 7, 8, 25, 8, 25, 11, 25, 16, 16, 12, 11, 20, 31, 42, 32, 23, 17, 19, 38, 50, 21, 14, 37, 23, 47, 31, 24, 9, 64, 39, 30, 36, 46, 32, 50, 34, 32, 34, 30, 28, 35, 57, 78, 88, 60, 78, 67, 82, 68, 97, 67, 65, 105, 83, 101, 107, 88, 178, 110, 136, 118, 136, 153, 119, 89, 105, 60, 148, 59, 73, 83, 49, 137, 91) # Fitting the model mod4 <- gamlss(y~1, sigma.fo=~1, family=DMOLBE, control=gamlss.control(n.cyc=500, trace=FALSE)) summary(mod4) # Extracting the fitted values for mu and sigma # using the inverse link function mu_hat <- exp(coef(mod4, what="mu")) mu_hat sigma_hat <- exp(coef(mod4, what="sigma")) sigma_hat
These functions define the density, distribution function, quantile
function and random generation for the Poisson-generalised Lindley (NPGL)
distribution
with parameters and .
dNPGL(x, mu = 0.1, sigma = 2, log = FALSE) pNPGL(q, mu = 0.1, sigma = 2, lower.tail = TRUE, log.p = FALSE) rNPGL(n, mu = 0.1, sigma = 2) qNPGL(p, mu = 0.1, sigma = 2, lower.tail = TRUE, log.p = FALSE)dNPGL(x, mu = 0.1, sigma = 2, log = FALSE) pNPGL(q, mu = 0.1, sigma = 2, lower.tail = TRUE, log.p = FALSE) rNPGL(n, mu = 0.1, sigma = 2) qNPGL(p, mu = 0.1, sigma = 2, lower.tail = TRUE, log.p = FALSE)
x, q
|
vector of (non-negative integer) quantiles. |
mu |
vector of the mu parameter. |
sigma |
vector of the sigma parameter. |
log, log.p
|
logical; if TRUE, probabilities p are given as log(p). |
lower.tail |
logical; if TRUE (default), probabilities are |
n |
number of random values to return. |
p |
vector of probabilities. |
The Poisson-generalised Lindley distribution with parameters and
has support and probability mass function given by
with and .
This distribution is useful for modeling over-dispersed count data.
Note: in this implementation we changed the original parameters and
for and respectively, we did it to implement this distribution within gamlss framework.
dNPGL gives the density, pNPGL gives the distribution
function, qNPGL gives the quantile function, rNPGL
generates random deviates.
Tomas Mesa, [email protected]
Altun, E. A new two-parameter discrete poisson-generalized Lindley distribution with properties and applications to healthcare data sets. Comput Stat 36, 2841–2861 (2021). https://doi.org/10.1007/s00180-021-01097-0
NPGL.
# Example 1 # Plotting the mass function for different parameter values x_max <- 50 probs1 <- dNPGL(x=0:x_max, mu = 0.1, sigma = 2) probs2 <- dNPGL(x=0:x_max, mu = 0.5, sigma = 5) probs3 <- dNPGL(x=0:x_max, mu = 0.2, sigma = 6) probs4 <- dNPGL(x=0:x_max, mu = 20, sigma = 2) plot(x=0:x_max, y=probs1, type="h", lwd=2, col="dodgerblue", las=1, ylab="P(X=x)", xlab="X", main="Probability for dNPGL", ylim=c(0, 0.035)) legend("topright", legend="mu=0.1, sigma=2") plot(x=0:x_max, y=probs2, type="h", lwd=2, col="tomato", las=1, ylab="P(X=x)", xlab="X", main="Probability for dNPGL", ylim=c(0, 0.1)) legend("topright", legend="mu=0.5, sigma=5") plot(x=0:x_max, y=probs3, type="h", lwd=2, col="green4", las=1, ylab="P(X=x)", xlab="X", main="Probability for dNPGL", ylim=c(0, 0.03)) legend("topright", legend="mu=0.2, sigma=6") plot(x=0:x_max, y=probs4, type="h", lwd=2, col="magenta", las=1, ylab="P(X=x)", xlab="X", main="Probability for dNPGL", ylim=c(0, 1)) legend("topright", legend="mu=20, sigma=2") # Example 2 # Checking if the cumulative curves converge to 1 x_max <- 100 cumulative_probs1 <- pNPGL(q=0:x_max, mu = 0.1, sigma = 2) cumulative_probs2 <- pNPGL(q=0:x_max, mu = 0.5, sigma = 5) cumulative_probs3 <- pNPGL(q=0:x_max, mu = 0.2, sigma = 6) cumulative_probs4 <- pNPGL(q=0:x_max, mu = 20, sigma = 2) plot(x=0:x_max, y=cumulative_probs1, col="dodgerblue", type="o", las=1, ylim=c(0, 1), main="Cumulative probability for NPGL", xlab="X", ylab="Probability") points(x=0:x_max, y=cumulative_probs2, type="o", col="tomato") points(x=0:x_max, y=cumulative_probs3, type="o", col="green4") points(x=0:x_max, y=cumulative_probs4, type="o", col="magenta") legend("bottomright", col=c("dodgerblue", "tomato", "green4", "magenta"), lwd=3, legend=c("mu=0.1, sigma=2", "mu=0.5, sigma=5", "mu=0.2, sigma=6", "mu=20, sigma=2")) # Example 3 # Comparing the random generator output with # the theoretical probabilities x_max <- 100 mu <- 0.1 sigma <- 2 probs1 <- dNPGL(x=0:x_max, mu=mu, sigma=sigma) names(probs1) <- 0:x_max x <- rNPGL(n=10000, mu=mu, sigma=sigma) probs2 <- prop.table(table(x)) cn <- union(names(probs1), names(probs2)) height <- rbind(probs1[cn], probs2[cn]) nombres <- cn mp <- barplot(height, beside = TRUE, names.arg = nombres, col=c("dodgerblue3","firebrick3"), las=1, xlab="X", ylab="Proportion") legend("topright", legend=c("Theoretical", "Simulated"), bty="n", lwd=3, col=c("dodgerblue3","firebrick3"), lty=1) # Example 4 # Checking the quantile function mu <- 0.1 sigma <- 2 p <- seq(from=0, to=1, by=0.01) qxx <- qNPGL(p=p, mu=mu, sigma=sigma, lower.tail=TRUE, log.p=FALSE) plot(p, qxx, type="s", lwd=2, col="green3", ylab="quantiles", main="Quantiles of NPGL(mu=0.1, sigma=2)")# Example 1 # Plotting the mass function for different parameter values x_max <- 50 probs1 <- dNPGL(x=0:x_max, mu = 0.1, sigma = 2) probs2 <- dNPGL(x=0:x_max, mu = 0.5, sigma = 5) probs3 <- dNPGL(x=0:x_max, mu = 0.2, sigma = 6) probs4 <- dNPGL(x=0:x_max, mu = 20, sigma = 2) plot(x=0:x_max, y=probs1, type="h", lwd=2, col="dodgerblue", las=1, ylab="P(X=x)", xlab="X", main="Probability for dNPGL", ylim=c(0, 0.035)) legend("topright", legend="mu=0.1, sigma=2") plot(x=0:x_max, y=probs2, type="h", lwd=2, col="tomato", las=1, ylab="P(X=x)", xlab="X", main="Probability for dNPGL", ylim=c(0, 0.1)) legend("topright", legend="mu=0.5, sigma=5") plot(x=0:x_max, y=probs3, type="h", lwd=2, col="green4", las=1, ylab="P(X=x)", xlab="X", main="Probability for dNPGL", ylim=c(0, 0.03)) legend("topright", legend="mu=0.2, sigma=6") plot(x=0:x_max, y=probs4, type="h", lwd=2, col="magenta", las=1, ylab="P(X=x)", xlab="X", main="Probability for dNPGL", ylim=c(0, 1)) legend("topright", legend="mu=20, sigma=2") # Example 2 # Checking if the cumulative curves converge to 1 x_max <- 100 cumulative_probs1 <- pNPGL(q=0:x_max, mu = 0.1, sigma = 2) cumulative_probs2 <- pNPGL(q=0:x_max, mu = 0.5, sigma = 5) cumulative_probs3 <- pNPGL(q=0:x_max, mu = 0.2, sigma = 6) cumulative_probs4 <- pNPGL(q=0:x_max, mu = 20, sigma = 2) plot(x=0:x_max, y=cumulative_probs1, col="dodgerblue", type="o", las=1, ylim=c(0, 1), main="Cumulative probability for NPGL", xlab="X", ylab="Probability") points(x=0:x_max, y=cumulative_probs2, type="o", col="tomato") points(x=0:x_max, y=cumulative_probs3, type="o", col="green4") points(x=0:x_max, y=cumulative_probs4, type="o", col="magenta") legend("bottomright", col=c("dodgerblue", "tomato", "green4", "magenta"), lwd=3, legend=c("mu=0.1, sigma=2", "mu=0.5, sigma=5", "mu=0.2, sigma=6", "mu=20, sigma=2")) # Example 3 # Comparing the random generator output with # the theoretical probabilities x_max <- 100 mu <- 0.1 sigma <- 2 probs1 <- dNPGL(x=0:x_max, mu=mu, sigma=sigma) names(probs1) <- 0:x_max x <- rNPGL(n=10000, mu=mu, sigma=sigma) probs2 <- prop.table(table(x)) cn <- union(names(probs1), names(probs2)) height <- rbind(probs1[cn], probs2[cn]) nombres <- cn mp <- barplot(height, beside = TRUE, names.arg = nombres, col=c("dodgerblue3","firebrick3"), las=1, xlab="X", ylab="Proportion") legend("topright", legend=c("Theoretical", "Simulated"), bty="n", lwd=3, col=c("dodgerblue3","firebrick3"), lty=1) # Example 4 # Checking the quantile function mu <- 0.1 sigma <- 2 p <- seq(from=0, to=1, by=0.01) qxx <- qNPGL(p=p, mu=mu, sigma=sigma, lower.tail=TRUE, log.p=FALSE) plot(p, qxx, type="s", lwd=2, col="green3", ylab="quantiles", main="Quantiles of NPGL(mu=0.1, sigma=2)")
These functions define the density, distribution function, quantile
function and random generation for the Poisson-generalised Lindley in second
parametrization with parameters (as mean) and .
dNPGL2(x, mu = 2, sigma = 2, log = FALSE) pNPGL2(q, mu = 2, sigma = 2, lower.tail = TRUE, log.p = FALSE) rNPGL2(n, mu = 2, sigma = 2) qNPGL2(p, mu = 2, sigma = 2, lower.tail = TRUE, log.p = FALSE)dNPGL2(x, mu = 2, sigma = 2, log = FALSE) pNPGL2(q, mu = 2, sigma = 2, lower.tail = TRUE, log.p = FALSE) rNPGL2(n, mu = 2, sigma = 2) qNPGL2(p, mu = 2, sigma = 2, lower.tail = TRUE, log.p = FALSE)
x, q
|
vector of (non-negative integer) quantiles. |
mu |
vector of the mu parameter. |
sigma |
vector of the sigma parameter. |
log, log.p
|
logical; if TRUE, probabilities p are given as log(p). |
lower.tail |
logical; if TRUE (default), probabilities are |
n |
number of random values to return. |
p |
vector of probabilities. |
The Poisson-generalised Lindley distribution with parameters and
has support and probability mass function given by
Note: in this implementation the parameter is the mean
of the distribution and (equivalent to
in the original NPGL parametrization).
dNPGL2 gives the density, pNPGL2 gives the distribution
function, qNPGL2 gives the quantile function, rNPGL2
generates random deviates.
Tomás Mesa, [email protected]
Altun, E. A new two-parameter discrete poisson-generalized Lindley distribution with properties and applications to healthcare data sets. Comput Stat 36, 2841–2861 (2021). https://doi.org/10.1007/s00180-021-01097-0
# Example 1 # Plotting the mass function for different parameter values # Original parameters and their corresponding means casos <- data.frame( mu_orig = c(0.1, 0.5, 0.2, 20), sigma = c(2, 5, 6, 2) ) casos$mu_mean <- (casos$sigma + casos$mu_orig) / (casos$mu_orig * (1 + casos$mu_orig)) x_max <- 50 probs1 <- dNPGL2(x=0:x_max, mu=casos$mu_mean[1], sigma=casos$sigma[1]) probs2 <- dNPGL2(x=0:x_max, mu=casos$mu_mean[2], sigma=casos$sigma[2]) probs3 <- dNPGL2(x=0:x_max, mu=casos$mu_mean[3], sigma=casos$sigma[3]) probs4 <- dNPGL2(x=0:x_max, mu=casos$mu_mean[4], sigma=casos$sigma[4]) plot(x = 0:x_max, y = probs1, type = "h", lwd = 2, col = "dodgerblue", las = 1, ylab = "P(X=x)", xlab = "X", main = "Probability for dNPGL2", ylim = c(0, 0.035)) legend("topright", legend = paste0("mu=", round(casos$mu_mean[1], 2), ", sigma=", casos$sigma[1])) plot(x = 0:x_max, y = probs2, type = "h", lwd = 2, col = "tomato", las = 1, ylab = "P(X=x)", xlab = "X", main = "Probability for dNPGL2", ylim = c(0, 0.1)) legend("topright", legend = paste0("mu=", round(casos$mu_mean[2], 2), ", sigma=", casos$sigma[2])) plot(x = 0:x_max, y = probs3, type = "h", lwd = 2, col = "green4", las = 1, ylab = "P(X=x)", xlab = "X", main = "Probability for dNPGL2", ylim = c(0, 0.03)) legend("topright", legend = paste0("mu=", round(casos$mu_mean[3], 2), ", sigma=", casos$sigma[3])) plot(x = 0:x_max, y = probs4, type = "h", lwd = 2, col = "magenta", las = 1, ylab = "P(X=x)", xlab = "X", main = "Probability for dNPGL2", ylim = c(0, 1)) legend("topright", legend = paste0("mu=", round(casos$mu_mean[4], 4), ", sigma=", casos$sigma[4])) # Example 2 # Checking if the cumulative curves converge to 1 x_max <- 100 cumulative_probs1 <- pNPGL2(q = 0:x_max, mu = casos$mu_mean[1], sigma = casos$sigma[1]) cumulative_probs2 <- pNPGL2(q = 0:x_max, mu = casos$mu_mean[2], sigma = casos$sigma[2]) cumulative_probs3 <- pNPGL2(q = 0:x_max, mu = casos$mu_mean[3], sigma = casos$sigma[3]) cumulative_probs4 <- pNPGL2(q = 0:x_max, mu = casos$mu_mean[4], sigma = casos$sigma[4]) plot(x = 0:x_max, y = cumulative_probs1, col = "dodgerblue", type = "o", las = 1, ylim = c(0, 1), main = "Cumulative probability for NPGL2", xlab = "X", ylab = "Probability") points(x = 0:x_max, y = cumulative_probs2, type = "o", col = "tomato") points(x = 0:x_max, y = cumulative_probs3, type = "o", col = "green4") points(x = 0:x_max, y = cumulative_probs4, type = "o", col = "magenta") legend("bottomright", col = c("dodgerblue", "tomato", "green4", "magenta"), lwd = 3, legend = c( paste0("mu=", round(casos$mu_mean[1], 2), ", sigma=", casos$sigma[1]), paste0("mu=", round(casos$mu_mean[2], 2), ", sigma=", casos$sigma[2]), paste0("mu=", round(casos$mu_mean[3], 2), ", sigma=", casos$sigma[3]), paste0("mu=", round(casos$mu_mean[4], 4), ", sigma=", casos$sigma[4]) )) # Example 3 # Comparing the random generator output with # the theoretical probabilities x_max <- 60 mu <- 5 sigma <- 2 probs1 <- dNPGL2(x = 0:x_max, mu = mu, sigma = sigma) names(probs1) <- 0:x_max set.seed(123) x <- rNPGL2(n = 10000, mu = mu, sigma = sigma) probs2 <- prop.table(table(x)) cn <- union(names(probs1), names(probs2)) height <- rbind(probs1[cn], probs2[cn]) mp <- barplot(height, beside = TRUE, names.arg = cn, col = c("dodgerblue3", "firebrick3"), las = 1, xlab = "X", ylab = "Proportion", main = paste0("NPGL2(mu=", mu, ", sigma=", sigma, ")")) legend("topright", legend = c("Theoretical", "Simulated"), bty = "n", lwd = 3, col = c("dodgerblue3", "firebrick3"), lty = 1) # Example 4 # Checking the quantile function mu <- 5 sigma <- 2 p <- seq(from = 0, to = 1, by = 0.01) qxx <- qNPGL2(p = p, mu = mu, sigma = sigma, lower.tail = TRUE, log.p = FALSE) plot(p, qxx, type = "s", lwd = 2, col = "green3", ylab = "quantiles", main = paste0("Quantiles of NPGL2(mu=", mu, ", sigma=", sigma, ")"))# Example 1 # Plotting the mass function for different parameter values # Original parameters and their corresponding means casos <- data.frame( mu_orig = c(0.1, 0.5, 0.2, 20), sigma = c(2, 5, 6, 2) ) casos$mu_mean <- (casos$sigma + casos$mu_orig) / (casos$mu_orig * (1 + casos$mu_orig)) x_max <- 50 probs1 <- dNPGL2(x=0:x_max, mu=casos$mu_mean[1], sigma=casos$sigma[1]) probs2 <- dNPGL2(x=0:x_max, mu=casos$mu_mean[2], sigma=casos$sigma[2]) probs3 <- dNPGL2(x=0:x_max, mu=casos$mu_mean[3], sigma=casos$sigma[3]) probs4 <- dNPGL2(x=0:x_max, mu=casos$mu_mean[4], sigma=casos$sigma[4]) plot(x = 0:x_max, y = probs1, type = "h", lwd = 2, col = "dodgerblue", las = 1, ylab = "P(X=x)", xlab = "X", main = "Probability for dNPGL2", ylim = c(0, 0.035)) legend("topright", legend = paste0("mu=", round(casos$mu_mean[1], 2), ", sigma=", casos$sigma[1])) plot(x = 0:x_max, y = probs2, type = "h", lwd = 2, col = "tomato", las = 1, ylab = "P(X=x)", xlab = "X", main = "Probability for dNPGL2", ylim = c(0, 0.1)) legend("topright", legend = paste0("mu=", round(casos$mu_mean[2], 2), ", sigma=", casos$sigma[2])) plot(x = 0:x_max, y = probs3, type = "h", lwd = 2, col = "green4", las = 1, ylab = "P(X=x)", xlab = "X", main = "Probability for dNPGL2", ylim = c(0, 0.03)) legend("topright", legend = paste0("mu=", round(casos$mu_mean[3], 2), ", sigma=", casos$sigma[3])) plot(x = 0:x_max, y = probs4, type = "h", lwd = 2, col = "magenta", las = 1, ylab = "P(X=x)", xlab = "X", main = "Probability for dNPGL2", ylim = c(0, 1)) legend("topright", legend = paste0("mu=", round(casos$mu_mean[4], 4), ", sigma=", casos$sigma[4])) # Example 2 # Checking if the cumulative curves converge to 1 x_max <- 100 cumulative_probs1 <- pNPGL2(q = 0:x_max, mu = casos$mu_mean[1], sigma = casos$sigma[1]) cumulative_probs2 <- pNPGL2(q = 0:x_max, mu = casos$mu_mean[2], sigma = casos$sigma[2]) cumulative_probs3 <- pNPGL2(q = 0:x_max, mu = casos$mu_mean[3], sigma = casos$sigma[3]) cumulative_probs4 <- pNPGL2(q = 0:x_max, mu = casos$mu_mean[4], sigma = casos$sigma[4]) plot(x = 0:x_max, y = cumulative_probs1, col = "dodgerblue", type = "o", las = 1, ylim = c(0, 1), main = "Cumulative probability for NPGL2", xlab = "X", ylab = "Probability") points(x = 0:x_max, y = cumulative_probs2, type = "o", col = "tomato") points(x = 0:x_max, y = cumulative_probs3, type = "o", col = "green4") points(x = 0:x_max, y = cumulative_probs4, type = "o", col = "magenta") legend("bottomright", col = c("dodgerblue", "tomato", "green4", "magenta"), lwd = 3, legend = c( paste0("mu=", round(casos$mu_mean[1], 2), ", sigma=", casos$sigma[1]), paste0("mu=", round(casos$mu_mean[2], 2), ", sigma=", casos$sigma[2]), paste0("mu=", round(casos$mu_mean[3], 2), ", sigma=", casos$sigma[3]), paste0("mu=", round(casos$mu_mean[4], 4), ", sigma=", casos$sigma[4]) )) # Example 3 # Comparing the random generator output with # the theoretical probabilities x_max <- 60 mu <- 5 sigma <- 2 probs1 <- dNPGL2(x = 0:x_max, mu = mu, sigma = sigma) names(probs1) <- 0:x_max set.seed(123) x <- rNPGL2(n = 10000, mu = mu, sigma = sigma) probs2 <- prop.table(table(x)) cn <- union(names(probs1), names(probs2)) height <- rbind(probs1[cn], probs2[cn]) mp <- barplot(height, beside = TRUE, names.arg = cn, col = c("dodgerblue3", "firebrick3"), las = 1, xlab = "X", ylab = "Proportion", main = paste0("NPGL2(mu=", mu, ", sigma=", sigma, ")")) legend("topright", legend = c("Theoretical", "Simulated"), bty = "n", lwd = 3, col = c("dodgerblue3", "firebrick3"), lty = 1) # Example 4 # Checking the quantile function mu <- 5 sigma <- 2 p <- seq(from = 0, to = 1, by = 0.01) qxx <- qNPGL2(p = p, mu = mu, sigma = sigma, lower.tail = TRUE, log.p = FALSE) plot(p, qxx, type = "s", lwd = 2, col = "green3", ylab = "quantiles", main = paste0("Quantiles of NPGL2(mu=", mu, ", sigma=", sigma, ")"))
The function DPERKS() defines the
Discrete Perks distribution
a two parameter distribution,
for a gamlss.family object to be used in GAMLSS
fitting using the function gamlss().
DPERKS(mu.link = "log", sigma.link = "log")DPERKS(mu.link = "log", sigma.link = "log")
mu.link |
defines the mu.link, with "log" link as the default for the mu parameter. |
sigma.link |
defines the sigma.link, with "log" link as the default for the sigma. |
The discrete Perks distribution with parameters and
has a support 0, 1, 2, ... and density given by
Note: in this implementation we changed the original parameters
for and for ,
we did it to implement this distribution within gamlss framework.
Veronica Seguro Varela, [email protected]
Tyagi, A., Choudhary, N., & Singh, B. (2020). A new discrete distribution: Theory and applications to discrete failure lifetime and count data. J. Appl. Probab. Statist, 15, 117-143.
# Example 1 # Generating some random values with # known mu and sigma set.seed(123) y <- rDPERKS(n=1000, mu=2.5, sigma=0.4) # Fitting the model library(gamlss) mod1 <- gamlss(y~1, family=DPERKS, control=gamlss.control(n.cyc=500, trace=TRUE)) # Extracting the fitted values for mu and sigma # using the inverse link function exp(coef(mod1, what="mu")) exp(coef(mod1, what="sigma")) # Example 2 # Generating random values under some model # A function to simulate a data set with Y ~ DPERKS gendat <- function(n) { x1 <- runif(n) x2 <- runif(n) mu <- exp(-1.6 + 5 * x1) sigma <- exp(1.7 - 5 * x2) y <- rDPERKS(n=n, mu=mu, sigma=sigma) data.frame(y=y, x1=x1, x2=x2) } set.seed(12345) datos <- gendat(n=1000) mod2 <- NULL mod2 <- gamlss(y~x1, sigma.fo=~x2, family=DPERKS, data=datos, control=gamlss.control(n.cyc=500, trace=TRUE)) summary(mod2) # Example 3 # The dataset comes from Tyagi et al. (2020) page 21 # The dataset contains the number of outbreaks of strikes in the # UK coal mining industries in four successive week periods # in the year 1948-59. y <- rep(0:4, times=c(46, 76, 24, 9, 1)) # Fitting the model library(gamlss) mod3 <- gamlss(y~1, family=DPERKS, control=gamlss.control(n.cyc=500, trace=TRUE)) # Extracting the fitted values for mu and sigma # using the inverse link function exp(coef(mod3, what="mu")) exp(coef(mod3, what="sigma")) # Example 4 # The dataset comes from Tyagi et al. (2020) page 21 # The dataset contains the number fishes caught # in traps (David, 1971, pg. 168). y <- rep(0:9, times=c(1, 2, 11, 20, 29, 23, 10, 3, 1, 0)) # Fitting the model library(gamlss) mod4 <- gamlss(y~1, family=DPERKS, control=gamlss.control(n.cyc=500, trace=TRUE)) # Extracting the fitted values for mu and sigma # using the inverse link function exp(coef(mod4, what="mu")) exp(coef(mod4, what="sigma")) # Example 5 # The dataset comes from Tyagi et al. (2020) page 24 # This dataset consists of remission times in weeks # for 20 leukemia patients randomly assigned to a certain treatment y <- c(1, 3, 3, 6, 7, 7, 10, 12, 14, 15, 18, 19, 22, 26, 28, 29, 34, 40, 48, 49) # Fitting the model library(gamlss) mod4 <- gamlss(y~1, family=DPERKS) # Extracting the fitted values for mu and sigma # using the inverse link function exp(coef(mod4, what="mu")) exp(coef(mod4, what="sigma"))# Example 1 # Generating some random values with # known mu and sigma set.seed(123) y <- rDPERKS(n=1000, mu=2.5, sigma=0.4) # Fitting the model library(gamlss) mod1 <- gamlss(y~1, family=DPERKS, control=gamlss.control(n.cyc=500, trace=TRUE)) # Extracting the fitted values for mu and sigma # using the inverse link function exp(coef(mod1, what="mu")) exp(coef(mod1, what="sigma")) # Example 2 # Generating random values under some model # A function to simulate a data set with Y ~ DPERKS gendat <- function(n) { x1 <- runif(n) x2 <- runif(n) mu <- exp(-1.6 + 5 * x1) sigma <- exp(1.7 - 5 * x2) y <- rDPERKS(n=n, mu=mu, sigma=sigma) data.frame(y=y, x1=x1, x2=x2) } set.seed(12345) datos <- gendat(n=1000) mod2 <- NULL mod2 <- gamlss(y~x1, sigma.fo=~x2, family=DPERKS, data=datos, control=gamlss.control(n.cyc=500, trace=TRUE)) summary(mod2) # Example 3 # The dataset comes from Tyagi et al. (2020) page 21 # The dataset contains the number of outbreaks of strikes in the # UK coal mining industries in four successive week periods # in the year 1948-59. y <- rep(0:4, times=c(46, 76, 24, 9, 1)) # Fitting the model library(gamlss) mod3 <- gamlss(y~1, family=DPERKS, control=gamlss.control(n.cyc=500, trace=TRUE)) # Extracting the fitted values for mu and sigma # using the inverse link function exp(coef(mod3, what="mu")) exp(coef(mod3, what="sigma")) # Example 4 # The dataset comes from Tyagi et al. (2020) page 21 # The dataset contains the number fishes caught # in traps (David, 1971, pg. 168). y <- rep(0:9, times=c(1, 2, 11, 20, 29, 23, 10, 3, 1, 0)) # Fitting the model library(gamlss) mod4 <- gamlss(y~1, family=DPERKS, control=gamlss.control(n.cyc=500, trace=TRUE)) # Extracting the fitted values for mu and sigma # using the inverse link function exp(coef(mod4, what="mu")) exp(coef(mod4, what="sigma")) # Example 5 # The dataset comes from Tyagi et al. (2020) page 24 # This dataset consists of remission times in weeks # for 20 leukemia patients randomly assigned to a certain treatment y <- c(1, 3, 3, 6, 7, 7, 10, 12, 14, 15, 18, 19, 22, 26, 28, 29, 34, 40, 48, 49) # Fitting the model library(gamlss) mod4 <- gamlss(y~1, family=DPERKS) # Extracting the fitted values for mu and sigma # using the inverse link function exp(coef(mod4, what="mu")) exp(coef(mod4, what="sigma"))
These functions define the density, distribution function, quantile
function and random generation for the Discrete Poisson XLindley distribution
with parameter .
dPOISXL(x, mu = 0.3, log = FALSE) pPOISXL(q, mu = 0.3, lower.tail = TRUE, log.p = FALSE) qPOISXL(p, mu = 0.3, lower.tail = TRUE, log.p = FALSE) rPOISXL(n, mu = 0.3)dPOISXL(x, mu = 0.3, log = FALSE) pPOISXL(q, mu = 0.3, lower.tail = TRUE, log.p = FALSE) qPOISXL(p, mu = 0.3, lower.tail = TRUE, log.p = FALSE) rPOISXL(n, mu = 0.3)
x, q
|
vector of (non-negative integer) quantiles. |
mu |
vector of the mu parameter. |
log, log.p
|
logical; if TRUE, probabilities p are given as log(p). |
lower.tail |
logical; if TRUE (default), probabilities are |
p |
vector of probabilities. |
n |
number of random values to return |
The Discrete Poisson XLindley distribution with parameters has a support
0, 1, 2, ... and mass function given by
; with .
Note: in this implementation we changed the original parameters for ,
we did it to implement this distribution within gamlss framework.
dPOISXL gives the density, pPOISXL gives the distribution
function, qPOISXL gives the quantile function, rPOISXL
generates random deviates.
Mariana Blandon Mejia, [email protected]
Ahsan-ul-Haq, M., Al-Bossly, A., El-Morshedy, M., & Eliwa, M. S. (2022). Poisson XLindley distribution for count data: statistical and reliability properties with estimation techniques and inference. Computational Intelligence and neuroscience, 2022(1), 6503670.
# Example 1 # Plotting the mass function for different parameter values x_max <- 20 probs1 <- dPOISXL(x=0:x_max, mu=0.2) probs2 <- dPOISXL(x=0:x_max, mu=0.5) probs3 <- dPOISXL(x=0:x_max, mu=1.0) # To plot the first k values plot(x=0:x_max, y=probs1, type="o", lwd=2, col="dodgerblue", las=1, ylab="P(X=x)", xlab="X", main="Probability for Poisson XLindley", ylim=c(0, 0.50)) points(x=0:x_max, y=probs2, type="o", lwd=2, col="tomato") points(x=0:x_max, y=probs3, type="o", lwd=2, col="green4") legend("topright", col=c("dodgerblue", "tomato", "green4"), lwd=3, legend=c("mu=0.2", "mu=0.5", "mu=1.0")) # Example 2 # Checking if the cumulative curves converge to 1 x_max <- 20 plot_discrete_cdf(x=0:x_max, fx=dPOISXL(x=0:x_max, mu=0.2), col="dodgerblue", main="CDF for Poisson XLindley with mu=0.2") plot_discrete_cdf(x=0:x_max, fx=dPOISXL(x=0:x_max, mu=0.5), col="tomato", main="CDF for Poisson XLindley with mu=0.5") plot_discrete_cdf(x=0:x_max, fx=dPOISXL(x=0:x_max, mu=1.0), col="green4", main="CDF for Poisson XLindley with mu=1.0") # Example 3 # Comparing the random generator output with # the theoretical probabilities x_max <- 15 probs1 <- dPOISXL(x=0:x_max, mu=0.3) names(probs1) <- 0:x_max x <- rPOISXL(n=3000, mu=0.3) probs2 <- prop.table(table(x)) cn <- union(names(probs1), names(probs2)) height <- rbind(probs1[cn], probs2[cn]) mp <- barplot(height, beside = TRUE, names.arg = cn, col=c("dodgerblue3","firebrick3"), las=1, xlab="X", ylab="Proportion") legend("topright", legend=c("Theoretical", "Simulated"), bty="n", lwd=3, col=c("dodgerblue3","firebrick3"), lty=1) # Example 4 # Checking the quantile function mu <- 0.3 p <- seq(from=0, to=1, by = 0.01) qxx <- qPOISXL(p, mu, lower.tail = TRUE, log.p = FALSE) plot(p, qxx, type="s", lwd=2, col="green3", ylab="quantiles", main="Quantiles for Poisson XLindley mu=0.3")# Example 1 # Plotting the mass function for different parameter values x_max <- 20 probs1 <- dPOISXL(x=0:x_max, mu=0.2) probs2 <- dPOISXL(x=0:x_max, mu=0.5) probs3 <- dPOISXL(x=0:x_max, mu=1.0) # To plot the first k values plot(x=0:x_max, y=probs1, type="o", lwd=2, col="dodgerblue", las=1, ylab="P(X=x)", xlab="X", main="Probability for Poisson XLindley", ylim=c(0, 0.50)) points(x=0:x_max, y=probs2, type="o", lwd=2, col="tomato") points(x=0:x_max, y=probs3, type="o", lwd=2, col="green4") legend("topright", col=c("dodgerblue", "tomato", "green4"), lwd=3, legend=c("mu=0.2", "mu=0.5", "mu=1.0")) # Example 2 # Checking if the cumulative curves converge to 1 x_max <- 20 plot_discrete_cdf(x=0:x_max, fx=dPOISXL(x=0:x_max, mu=0.2), col="dodgerblue", main="CDF for Poisson XLindley with mu=0.2") plot_discrete_cdf(x=0:x_max, fx=dPOISXL(x=0:x_max, mu=0.5), col="tomato", main="CDF for Poisson XLindley with mu=0.5") plot_discrete_cdf(x=0:x_max, fx=dPOISXL(x=0:x_max, mu=1.0), col="green4", main="CDF for Poisson XLindley with mu=1.0") # Example 3 # Comparing the random generator output with # the theoretical probabilities x_max <- 15 probs1 <- dPOISXL(x=0:x_max, mu=0.3) names(probs1) <- 0:x_max x <- rPOISXL(n=3000, mu=0.3) probs2 <- prop.table(table(x)) cn <- union(names(probs1), names(probs2)) height <- rbind(probs1[cn], probs2[cn]) mp <- barplot(height, beside = TRUE, names.arg = cn, col=c("dodgerblue3","firebrick3"), las=1, xlab="X", ylab="Proportion") legend("topright", legend=c("Theoretical", "Simulated"), bty="n", lwd=3, col=c("dodgerblue3","firebrick3"), lty=1) # Example 4 # Checking the quantile function mu <- 0.3 p <- seq(from=0, to=1, by = 0.01) qxx <- qPOISXL(p, mu, lower.tail = TRUE, log.p = FALSE) plot(p, qxx, type="s", lwd=2, col="green3", ylab="quantiles", main="Quantiles for Poisson XLindley mu=0.3")
These functions define the density, distribution function, quantile
function and random generation for the
Poisson–transmuted record type exponential (PTRTE) distribution
with parameters and .
This distribution was proposed by Erbayram and Akdogan (2025) as a new discrete distribution obtained from a mixed Poisson model, where the Poisson parameter follows a transmuted record type exponential distribution.
dPTRTE(x, mu, sigma, log = FALSE) pPTRTE(q, mu, sigma, lower.tail = TRUE, log.p = FALSE) qPTRTE(p, mu, sigma, lower.tail = TRUE, log.p = FALSE) rPTRTE(n, mu, sigma)dPTRTE(x, mu, sigma, log = FALSE) pPTRTE(q, mu, sigma, lower.tail = TRUE, log.p = FALSE) qPTRTE(p, mu, sigma, lower.tail = TRUE, log.p = FALSE) rPTRTE(n, mu, sigma)
x, q
|
vector of (non-negative integer) quantiles. |
mu |
vector of the mu parameter. |
sigma |
vector of the sigma parameter. |
log, log.p
|
logical; if TRUE, probabilities p are given as log(p). |
lower.tail |
logical; if TRUE (default), probabilities are
|
p |
vector of probabilities. |
n |
number of random values to return. |
The Poisson–transmuted record type exponential distribution with
parameters and has support
and probability mass function given by
with and .
dPTRTE gives the density,
pPTRTE gives the distribution function,
qPTRTE gives the quantile function,
rPTRTE generates random deviates.
Rebeca Isabel Rodriguez Gonzalez, [email protected]
Erbayram, T., & Akdogan, Y. (2025). A new discrete model generated from mixed Poisson transmuted record type exponential distribution. Ricerca di Matematica, 74, 1225–1247.
# Example 1 # Plotting the mass function for different parameter values x_max <- 20 probs1 <- dPTRTE(x=0:x_max, mu=0.5, sigma=0.5) probs2 <- dPTRTE(x=0:x_max, mu=1, sigma=0.5) probs3 <- dPTRTE(x=0:x_max, mu=2, sigma=0.5) # To plot the first k values plot(x=0:x_max, y=probs1, type="o", lwd=2, col="dodgerblue", las=1, ylab="P(X=x)", xlab="X", main="Probability for PTRTE", ylim=c(0, 0.80)) points(x=0:x_max, y=probs2, type="o", lwd=2, col="tomato") points(x=0:x_max, y=probs3, type="o", lwd=2, col="green4") legend("topright", col=c("dodgerblue", "tomato", "green4"), lwd=3, legend=c("mu=0.5, sigma=0.5", "mu=1, sigma=0.5", "mu=2, sigma=0.5")) # Example 2 # Checking if the cumulative curves converge to 1 x_max <- 10 cumulative_probs1 <- pPTRTE(q=0:x_max, mu=1, sigma=0.5) cumulative_probs2 <- pPTRTE(q=0:x_max, mu=1, sigma=0.7) cumulative_probs3 <- pPTRTE(q=0:x_max, mu=1, sigma=0.9) plot(x=0:x_max, y=cumulative_probs1, col="dodgerblue", type="o", las=1, ylim=c(0, 1), main="Cumulative for PTRTE", xlab="X", ylab="Probability") points(x=0:x_max, y=cumulative_probs2, type="o", col="tomato") points(x=0:x_max, y=cumulative_probs3, type="o", col="green4") legend("bottomright", col=c("dodgerblue", "tomato", "green4"), lwd=3, legend=c("mu=1, sigma=0.5", "mu=1, sigma=0.7", "mu=1, sigma=0.9")) # Example 3 # Comparing the random generator output with # the theoretical probabilities x_max <- 30 probs1 <- dPTRTE(x=0:x_max, mu=0.5, sigma=0.5) names(probs1) <- 0:x_max x <- rPTRTE(n=1000, mu=0.5, sigma=0.5) probs2 <- prop.table(table(x)) cn <- union(names(probs1), names(probs2)) height <- rbind(probs1[cn], probs2[cn]) mp <- barplot(height, beside=TRUE, names.arg=cn, col=c("dodgerblue3","firebrick3"), las=1, xlab="X", ylab="Proportion") legend("topright", legend=c("Theoretical", "Simulated"), bty="n", lwd=3, col=c("dodgerblue3","firebrick3"), lty=1) # Example 4 # Checking the quantile function mu <- 1 sigma <- 0.5 p <- seq(from=0, to=1, by=0.01) qxx <- qPTRTE(p=p, mu=mu, sigma=sigma, lower.tail=TRUE, log.p=FALSE) plot(p, qxx, type="s", lwd=2, col="green3", ylab="quantiles", main="Quantiles of DPTRTE(mu=1, sigma=0.5)")# Example 1 # Plotting the mass function for different parameter values x_max <- 20 probs1 <- dPTRTE(x=0:x_max, mu=0.5, sigma=0.5) probs2 <- dPTRTE(x=0:x_max, mu=1, sigma=0.5) probs3 <- dPTRTE(x=0:x_max, mu=2, sigma=0.5) # To plot the first k values plot(x=0:x_max, y=probs1, type="o", lwd=2, col="dodgerblue", las=1, ylab="P(X=x)", xlab="X", main="Probability for PTRTE", ylim=c(0, 0.80)) points(x=0:x_max, y=probs2, type="o", lwd=2, col="tomato") points(x=0:x_max, y=probs3, type="o", lwd=2, col="green4") legend("topright", col=c("dodgerblue", "tomato", "green4"), lwd=3, legend=c("mu=0.5, sigma=0.5", "mu=1, sigma=0.5", "mu=2, sigma=0.5")) # Example 2 # Checking if the cumulative curves converge to 1 x_max <- 10 cumulative_probs1 <- pPTRTE(q=0:x_max, mu=1, sigma=0.5) cumulative_probs2 <- pPTRTE(q=0:x_max, mu=1, sigma=0.7) cumulative_probs3 <- pPTRTE(q=0:x_max, mu=1, sigma=0.9) plot(x=0:x_max, y=cumulative_probs1, col="dodgerblue", type="o", las=1, ylim=c(0, 1), main="Cumulative for PTRTE", xlab="X", ylab="Probability") points(x=0:x_max, y=cumulative_probs2, type="o", col="tomato") points(x=0:x_max, y=cumulative_probs3, type="o", col="green4") legend("bottomright", col=c("dodgerblue", "tomato", "green4"), lwd=3, legend=c("mu=1, sigma=0.5", "mu=1, sigma=0.7", "mu=1, sigma=0.9")) # Example 3 # Comparing the random generator output with # the theoretical probabilities x_max <- 30 probs1 <- dPTRTE(x=0:x_max, mu=0.5, sigma=0.5) names(probs1) <- 0:x_max x <- rPTRTE(n=1000, mu=0.5, sigma=0.5) probs2 <- prop.table(table(x)) cn <- union(names(probs1), names(probs2)) height <- rbind(probs1[cn], probs2[cn]) mp <- barplot(height, beside=TRUE, names.arg=cn, col=c("dodgerblue3","firebrick3"), las=1, xlab="X", ylab="Proportion") legend("topright", legend=c("Theoretical", "Simulated"), bty="n", lwd=3, col=c("dodgerblue3","firebrick3"), lty=1) # Example 4 # Checking the quantile function mu <- 1 sigma <- 0.5 p <- seq(from=0, to=1, by=0.01) qxx <- qPTRTE(p=p, mu=mu, sigma=sigma, lower.tail=TRUE, log.p=FALSE) plot(p, qxx, type="s", lwd=2, col="green3", ylab="quantiles", main="Quantiles of DPTRTE(mu=1, sigma=0.5)")
The function DsPA() defines the
discrete power-Ailamujia distribution
a two parameter distribution,
for a gamlss.family object to be used in GAMLSS
fitting using the function gamlss().
DsPA(mu.link = "log", sigma.link = "logit")DsPA(mu.link = "log", sigma.link = "logit")
mu.link |
defines the mu.link, with "log" link as the default for the mu parameter. |
sigma.link |
defines the sigma.link, with "logit" link as the default for the sigma parameter. Other links are "probit" and "cloglog"'(complementary log-log). |
The discrete power-Ailamujia distribution with parameters and
has a support 0, 1, 2, ... and density given by
Note: in this implementation we changed the original parameters and
for and respectively, we did it to implement this distribution within gamlss framework.
Returns a gamlss.family object which can be used
to fit a discrete power-Ailamujia distribution
in the gamlss() function.
Maria Camila Mena Romana, [email protected]
Alghamdi, A. S., Ahsan-ul-Haq, M., Babar, A., Aljohani, H. M., Afify, A. Z., & Cell, Q. E. (2022). The discrete power-Ailamujia distribution: properties, inference, and applications. AIMS Math, 7(5), 8344-8360.
# Example 1 # Generating some random values with # known mu and sigma y <- rDsPA(n=100, mu=1.2, sigma=0.5) # Fitting the model library(gamlss) mod1 <- gamlss(y~1, family=DsPA, control=gamlss.control(n.cyc=500, trace=TRUE)) # Extracting the fitted values for mu and sigma # using the inverse link function inv_logit <- function(x) 1/(1 + exp(-x)) exp(coef(mod1, what="mu")) inv_logit(coef(mod1, what="sigma")) # Example 2 # Generating random values under some model # A function to simulate a data set with Y ~ DsPA gendat <- function(n) { x1 <- runif(n) x2 <- runif(n) x3 <- runif(n) x4 <- runif(n) mu <- exp(1 + 1.2*x1 + 0.2*x2) sigma <- inv_logit(2 + 1.5*x3 + 1.5*x4) y <- rDsPA(n=n, mu=mu, sigma=sigma) data.frame(y=y, x1=x1, x2=x2, x3=x3, x4=x4) } set.seed(123) datos <- gendat(n=100) mod2 <- gamlss(y~x1+x2, sigma.fo=~x3+x4, family=DsPA, data=datos, control=gamlss.control(n.cyc=500, trace=TRUE)) summary(mod2) # Example 3 # failure times for a sample of 15 electronic components in an acceleration life test # Taken from # Alghamdi et. al (202) page 8354. y <- c(1.0, 5.0, 6.0, 11.0, 12.0, 19.0, 20.0, 22.0, 23.0, 31.0, 37.0, 46.0, 54.0, 60.0, 66.0) mod3 <- gamlss(y~1, family=DsPA, control=gamlss.control(n.cyc=500, trace=FALSE)) # Extracting the fitted values for mu and sigma # using the inverse link function inv_logit <- function(x) 1/(1 + exp(-x)) exp(coef(mod3, what="mu")) inv_logit(coef(mod3, what="sigma")) # Example 4 # number of fires in Greece from July 1, 1998 to August 31, 1998. # Taken from # Alghamdi et. al (202) page 8354. y <- c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 10, 10, 10, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 15, 15, 15, 15, 16, 20, 43) mod4 <- gamlss(y~1, family=DsPA, control=gamlss.control(n.cyc=500, trace=FALSE)) # Extracting the fitted values for mu and sigma # using the inverse link function inv_logit <- function(x) 1/(1 + exp(-x)) exp(coef(mod4, what="mu")) inv_logit(coef(mod4, what="sigma"))# Example 1 # Generating some random values with # known mu and sigma y <- rDsPA(n=100, mu=1.2, sigma=0.5) # Fitting the model library(gamlss) mod1 <- gamlss(y~1, family=DsPA, control=gamlss.control(n.cyc=500, trace=TRUE)) # Extracting the fitted values for mu and sigma # using the inverse link function inv_logit <- function(x) 1/(1 + exp(-x)) exp(coef(mod1, what="mu")) inv_logit(coef(mod1, what="sigma")) # Example 2 # Generating random values under some model # A function to simulate a data set with Y ~ DsPA gendat <- function(n) { x1 <- runif(n) x2 <- runif(n) x3 <- runif(n) x4 <- runif(n) mu <- exp(1 + 1.2*x1 + 0.2*x2) sigma <- inv_logit(2 + 1.5*x3 + 1.5*x4) y <- rDsPA(n=n, mu=mu, sigma=sigma) data.frame(y=y, x1=x1, x2=x2, x3=x3, x4=x4) } set.seed(123) datos <- gendat(n=100) mod2 <- gamlss(y~x1+x2, sigma.fo=~x3+x4, family=DsPA, data=datos, control=gamlss.control(n.cyc=500, trace=TRUE)) summary(mod2) # Example 3 # failure times for a sample of 15 electronic components in an acceleration life test # Taken from # Alghamdi et. al (202) page 8354. y <- c(1.0, 5.0, 6.0, 11.0, 12.0, 19.0, 20.0, 22.0, 23.0, 31.0, 37.0, 46.0, 54.0, 60.0, 66.0) mod3 <- gamlss(y~1, family=DsPA, control=gamlss.control(n.cyc=500, trace=FALSE)) # Extracting the fitted values for mu and sigma # using the inverse link function inv_logit <- function(x) 1/(1 + exp(-x)) exp(coef(mod3, what="mu")) inv_logit(coef(mod3, what="sigma")) # Example 4 # number of fires in Greece from July 1, 1998 to August 31, 1998. # Taken from # Alghamdi et. al (202) page 8354. y <- c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 10, 10, 10, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 15, 15, 15, 15, 16, 20, 43) mod4 <- gamlss(y~1, family=DsPA, control=gamlss.control(n.cyc=500, trace=FALSE)) # Extracting the fitted values for mu and sigma # using the inverse link function inv_logit <- function(x) 1/(1 + exp(-x)) exp(coef(mod4, what="mu")) inv_logit(coef(mod4, what="sigma"))
This function generates initial values for NPGL distribution.
estim_mu_sigma_NPGL(y)estim_mu_sigma_NPGL(y)
y |
vector with the random sample |
y <- rNPGL(n=100, mu=0.1, sigma=2) estim_mu_sigma_NPGL(y=y)y <- rNPGL(n=100, mu=0.1, sigma=2) estim_mu_sigma_NPGL(y=y)
This function generates initial values for NPGL distribution using the method of moments estimators given in equations (19) and (20) of Altun (2021).
estim_mu_sigma_NPGL_MM(y)estim_mu_sigma_NPGL_MM(y)
y |
vector with the random sample |
y <- rNPGL(n=100, mu=0.1, sigma=2) estim_mu_sigma_NPGL_MM(y=y)y <- rNPGL(n=100, mu=0.1, sigma=2) estim_mu_sigma_NPGL_MM(y=y)
estim_mu_sigma_NPGL2
estim_mu_sigma_NPGL2(y)estim_mu_sigma_NPGL2(y)
y |
vector with the random sample |
y <- rNPGL2(n = 100, mu = 3, sigma = 2) estim_mu_sigma_NPGL2(y = y)y <- rNPGL2(n = 100, mu = 3, sigma = 2) estim_mu_sigma_NPGL2(y = y)
The function GGEO() defines the
Generalized Geometric distribution
a two parameter distribution,
for a gamlss.family object to be used in GAMLSS
fitting using the function gamlss().
GGEO(mu.link = "logit", sigma.link = "log")GGEO(mu.link = "logit", sigma.link = "log")
mu.link |
defines the mu.link, with "log" link as the default for the mu parameter. |
sigma.link |
defines the sigma.link, with "logit" link as the default for the sigma. Other links are "probit" and "cloglog"'(complementary log-log) |
The GGEO distribution with parameters and
has a support 0, 1, 2, ... and mass function given by
with and . If , the GGEO distribution
reduces to the geometric distribution with success probability .
Returns a gamlss.family object which can be used
to fit a GGEO distribution
in the gamlss() function.
Valentina Hurtado Sepúlveda, [email protected]
Gómez-Déniz, E. (2010). Another generalization of the geometric distribution. Test, 19, 399-415.
# Example 1 # Generating some random values with # known mu and sigma set.seed(123) y <- rGGEO(n=200, mu=0.95, sigma=1.5) # Fitting the model library(gamlss) mod1 <- gamlss(y~1, family=GGEO, control=gamlss.control(n.cyc=500, trace=TRUE)) # Extracting the fitted values for mu and sigma # using the inverse link function inv_logit <- function(x) 1/(1 + exp(-x)) inv_logit(coef(mod1, what="mu")) exp(coef(mod1, what="sigma")) # Example 2 # Generating random values under some model # A function to simulate a data set with Y ~ GGEO ## Not run: gendat <- function(n) { x1 <- runif(n) x2 <- runif(n) mu <- inv_logit(1.7 - 2.8*x1) sigma <- exp(0.73 + 1*x2) y <- rGGEO(n=n, mu=mu, sigma=sigma) data.frame(y=y, x1=x1, x2=x2) } set.seed(78353) datos <- gendat(n=100) mod2 <- gamlss(y~x1, sigma.fo=~x2, family=GGEO, data=datos, control=gamlss.control(n.cyc=500, trace=TRUE)) summary(mod2) ## End(Not run) # Example 3 # Number of accidents to 647 women working on H. E. Shells # for 5 weeks. Taken from Gomez-Deniz (2010) page 411. y <- rep(x=0:5, times=c(447, 132, 42, 21, 3, 2)) mod3 <- gamlss(y~1, family=GGEO, control=gamlss.control(n.cyc=500, trace=TRUE)) # Extracting the fitted values for mu and sigma # using the inverse link function inv_logit <- function(x) 1/(1 + exp(-x)) inv_logit(coef(mod3, what="mu")) exp(coef(mod3, what="sigma")) # Example 4 # Total number of carious teeth among the four deciduous molars # Taken from Gomez-Deniz (2010) page 412. y <- rep(x=0:4, times=c(64, 17, 10, 6, 3)) mod4 <- gamlss(y~1, family=GGEO, control=gamlss.control(n.cyc=500, trace=TRUE)) # Extracting the fitted values for mu and sigma # using the inverse link function inv_logit <- function(x) 1/(1 + exp(-x)) inv_logit(coef(mod4, what="mu")) exp(coef(mod4, what="sigma")) # Example 5 # Results of ten shots fired from a rifle at each of 100 targets. # Taken from Gomez-Deniz (2010) page 412. y <- rep(x=0:10, times=c(0, 2, 4, 10, 22, 26, 18, 12, 4, 2, 0)) mod5 <- gamlss(y~1, family=GGEO, control=gamlss.control(n.cyc=500, trace=TRUE)) # Extracting the fitted values for mu and sigma # using the inverse link function inv_logit <- function(x) 1/(1 + exp(-x)) inv_logit(coef(mod5, what="mu")) exp(coef(mod5, what="sigma")) # Example 6 # Fish catch data in Kemp (1992). # Taken from Gomez-Deniz (2010) page 412. y <- rep(x=0:9, times=c(1, 2, 11, 20, 29, 23, 10, 3, 1, 0)) mod6 <- gamlss(y~1, family=GGEO, control=gamlss.control(n.cyc=500, trace=TRUE)) # Extracting the fitted values for mu and sigma # using the inverse link function inv_logit <- function(x) 1/(1 + exp(-x)) inv_logit(coef(mod6, what="mu")) exp(coef(mod6, what="sigma"))# Example 1 # Generating some random values with # known mu and sigma set.seed(123) y <- rGGEO(n=200, mu=0.95, sigma=1.5) # Fitting the model library(gamlss) mod1 <- gamlss(y~1, family=GGEO, control=gamlss.control(n.cyc=500, trace=TRUE)) # Extracting the fitted values for mu and sigma # using the inverse link function inv_logit <- function(x) 1/(1 + exp(-x)) inv_logit(coef(mod1, what="mu")) exp(coef(mod1, what="sigma")) # Example 2 # Generating random values under some model # A function to simulate a data set with Y ~ GGEO ## Not run: gendat <- function(n) { x1 <- runif(n) x2 <- runif(n) mu <- inv_logit(1.7 - 2.8*x1) sigma <- exp(0.73 + 1*x2) y <- rGGEO(n=n, mu=mu, sigma=sigma) data.frame(y=y, x1=x1, x2=x2) } set.seed(78353) datos <- gendat(n=100) mod2 <- gamlss(y~x1, sigma.fo=~x2, family=GGEO, data=datos, control=gamlss.control(n.cyc=500, trace=TRUE)) summary(mod2) ## End(Not run) # Example 3 # Number of accidents to 647 women working on H. E. Shells # for 5 weeks. Taken from Gomez-Deniz (2010) page 411. y <- rep(x=0:5, times=c(447, 132, 42, 21, 3, 2)) mod3 <- gamlss(y~1, family=GGEO, control=gamlss.control(n.cyc=500, trace=TRUE)) # Extracting the fitted values for mu and sigma # using the inverse link function inv_logit <- function(x) 1/(1 + exp(-x)) inv_logit(coef(mod3, what="mu")) exp(coef(mod3, what="sigma")) # Example 4 # Total number of carious teeth among the four deciduous molars # Taken from Gomez-Deniz (2010) page 412. y <- rep(x=0:4, times=c(64, 17, 10, 6, 3)) mod4 <- gamlss(y~1, family=GGEO, control=gamlss.control(n.cyc=500, trace=TRUE)) # Extracting the fitted values for mu and sigma # using the inverse link function inv_logit <- function(x) 1/(1 + exp(-x)) inv_logit(coef(mod4, what="mu")) exp(coef(mod4, what="sigma")) # Example 5 # Results of ten shots fired from a rifle at each of 100 targets. # Taken from Gomez-Deniz (2010) page 412. y <- rep(x=0:10, times=c(0, 2, 4, 10, 22, 26, 18, 12, 4, 2, 0)) mod5 <- gamlss(y~1, family=GGEO, control=gamlss.control(n.cyc=500, trace=TRUE)) # Extracting the fitted values for mu and sigma # using the inverse link function inv_logit <- function(x) 1/(1 + exp(-x)) inv_logit(coef(mod5, what="mu")) exp(coef(mod5, what="sigma")) # Example 6 # Fish catch data in Kemp (1992). # Taken from Gomez-Deniz (2010) page 412. y <- rep(x=0:9, times=c(1, 2, 11, 20, 29, 23, 10, 3, 1, 0)) mod6 <- gamlss(y~1, family=GGEO, control=gamlss.control(n.cyc=500, trace=TRUE)) # Extracting the fitted values for mu and sigma # using the inverse link function inv_logit <- function(x) 1/(1 + exp(-x)) inv_logit(coef(mod6, what="mu")) exp(coef(mod6, what="sigma"))
In this experiment, the density of understorey birds at a series of sites in two areas either side of a stockproof fence were compared. Once side had limited grazing (mainly from native herbivores), and the other was heavily grazed by feral herbivores, mostly horses. Bird counts were done at the sites either side of the fence (the Before measurements). Then the herbivores were removed, and bird counts done again (the After measurements). The measurements are the total number of understorey-foraging birds observed in three 20-minute surveys of two hectare quadrats.
grazinggrazing
grazingA data frame with 62 rows and 3 variables:
when the bird count was conducted
a factor with levels Reference and Feral
the number of understorey birds
...
Rodrigo Matheus
https://github.com/rdmatheus/bergreg
The function HYPERPO() defines the
hyper Poisson distribution
a two parameter distribution,
for a gamlss.family object to be used in GAMLSS
fitting using the function gamlss().
HYPERPO(mu.link = "log", sigma.link = "log")HYPERPO(mu.link = "log", sigma.link = "log")
mu.link |
defines the mu.link, with "log" link as the default for the mu parameter. |
sigma.link |
defines the sigma.link, with "log" link as the default for the sigma. |
The hyper-Poisson distribution with parameters and
has a support 0, 1, 2, ... and density given by
where the function is defined as
and for and positive integer.
Note: in this implementation we changed the original parameters and
for and respectively, we did it to implement this distribution within gamlss framework.
Returns a gamlss.family object which can be used
to fit a hyper-Poisson distribution
in the gamlss() function.
Freddy Hernandez, [email protected]
Sáez-Castillo, A. J., & Conde-Sánchez, A. (2013). A hyper-Poisson regression model for overdispersed and underdispersed count data. Computational Statistics & Data Analysis, 61, 148-157.
# Example 1 # Generating some random values with # known mu and sigma set.seed(1234) y <- rHYPERPO(n=200, mu=10, sigma=1.5) # Fitting the model library(gamlss) mod1 <- gamlss(y~1, sigma.fo=~1, family=HYPERPO, control=gamlss.control(n.cyc=500, trace=TRUE)) # Extracting the fitted values for mu and sigma # using the inverse link function exp(coef(mod1, what="mu")) exp(coef(mod1, what="sigma")) # Example 2 # Generating random values under some model # A function to simulate a data set with Y ~ HYPERPO gendat <- function(n) { x1 <- runif(n) x2 <- runif(n) mu <- exp(1.21 - 3 * x1) # 0.75 approximately sigma <- exp(1.26 - 2 * x2) # 1.30 approximately y <- rHYPERPO(n=n, mu=mu, sigma=sigma) data.frame(y=y, x1=x1, x2=x2) } set.seed(1234) dat <- gendat(n=100) mod2 <- gamlss(y~x1, sigma.fo=~x2, family=HYPERPO, data=dat, control=gamlss.control(n.cyc=500, trace=TRUE)) summary(mod2)# Example 1 # Generating some random values with # known mu and sigma set.seed(1234) y <- rHYPERPO(n=200, mu=10, sigma=1.5) # Fitting the model library(gamlss) mod1 <- gamlss(y~1, sigma.fo=~1, family=HYPERPO, control=gamlss.control(n.cyc=500, trace=TRUE)) # Extracting the fitted values for mu and sigma # using the inverse link function exp(coef(mod1, what="mu")) exp(coef(mod1, what="sigma")) # Example 2 # Generating random values under some model # A function to simulate a data set with Y ~ HYPERPO gendat <- function(n) { x1 <- runif(n) x2 <- runif(n) mu <- exp(1.21 - 3 * x1) # 0.75 approximately sigma <- exp(1.26 - 2 * x2) # 1.30 approximately y <- rHYPERPO(n=n, mu=mu, sigma=sigma) data.frame(y=y, x1=x1, x2=x2) } set.seed(1234) dat <- gendat(n=100) mod2 <- gamlss(y~x1, sigma.fo=~x2, family=HYPERPO, data=dat, control=gamlss.control(n.cyc=500, trace=TRUE)) summary(mod2)
The function HYPERPO2() defines the
hyper Poisson distribution (with mu as mean)
a two parameter distribution,
for a gamlss.family object to be used in GAMLSS
fitting using the function gamlss().
HYPERPO2(mu.link = "log", sigma.link = "log")HYPERPO2(mu.link = "log", sigma.link = "log")
mu.link |
defines the mu.link, with "log" link as the default for the mu parameter. |
sigma.link |
defines the sigma.link, with "log" link as the default for the sigma. |
The hyper-Poisson distribution with parameters and
has a support 0, 1, 2, ...
Note: in this implementation the parameter is the mean
of the distribution and corresponds to
the dispersion parameter. If you fit a model with this parameterization,
the time will increase because an internal procedure to convert
to parameter.
Returns a gamlss.family object which can be used
to fit a hyper-Poisson distribution version 2
in the gamlss() function.
Freddy Hernandez, [email protected]
Sáez-Castillo, A. J., & Conde-Sánchez, A. (2013). A hyper-Poisson regression model for overdispersed and underdispersed count data. Computational Statistics & Data Analysis, 61, 148-157.
# Example 1 # Generating some random values with # known mu and sigma set.seed(1234) y <- rHYPERPO2(n=100, mu=4, sigma=1.5) # Fitting the model library(gamlss) mod1 <- gamlss(y~1, sigma.fo=~1, family=HYPERPO2, control=gamlss.control(n.cyc=500, trace=TRUE)) # Extracting the fitted values for mu and sigma # using the inverse link function exp(coef(mod1, what="mu")) exp(coef(mod1, what="sigma")) # Example 2 # Generating random values under some model ## Not run: # A function to simulate a data set with Y ~ HYPERPO2 gendat <- function(n) { x1 <- runif(n) x2 <- runif(n) mu <- exp(1.21 - 3 * x1) # 0.75 approximately sigma <- exp(1.26 - 2 * x2) # 1.30 approximately y <- rHYPERPO2(n=n, mu=mu, sigma=sigma) data.frame(y=y, x1=x1, x2=x2) } set.seed(12345) dat <- gendat(n=200) mod2 <- gamlss(y~x1, sigma.fo=~x2, family=HYPERPO2, data=dat, control=gamlss.control(n.cyc=500, trace=TRUE)) summary(mod2) ## End(Not run)# Example 1 # Generating some random values with # known mu and sigma set.seed(1234) y <- rHYPERPO2(n=100, mu=4, sigma=1.5) # Fitting the model library(gamlss) mod1 <- gamlss(y~1, sigma.fo=~1, family=HYPERPO2, control=gamlss.control(n.cyc=500, trace=TRUE)) # Extracting the fitted values for mu and sigma # using the inverse link function exp(coef(mod1, what="mu")) exp(coef(mod1, what="sigma")) # Example 2 # Generating random values under some model ## Not run: # A function to simulate a data set with Y ~ HYPERPO2 gendat <- function(n) { x1 <- runif(n) x2 <- runif(n) mu <- exp(1.21 - 3 * x1) # 0.75 approximately sigma <- exp(1.26 - 2 * x2) # 1.30 approximately y <- rHYPERPO2(n=n, mu=mu, sigma=sigma) data.frame(y=y, x1=x1, x2=x2) } set.seed(12345) dat <- gendat(n=200) mod2 <- gamlss(y~x1, sigma.fo=~x2, family=HYPERPO2, data=dat, control=gamlss.control(n.cyc=500, trace=TRUE)) summary(mod2) ## End(Not run)
This is an auxiliar function to obtain the logLik for NPGL.
logLik_NPGL(param = c(0, 0), x)logLik_NPGL(param = c(0, 0), x)
param |
vector with the values for mu and sigma |
x |
vector with the data |
y <- rNPGL(n=100, mu=0.1, sigma=2) logLik_NPGL(param=c(0, 0), x=y)y <- rNPGL(n=100, mu=0.1, sigma=2) logLik_NPGL(param=c(0, 0), x=y)
Auxiliary function to evaluate the log-likelihood of the mean-parametrized NPGL2 distribution.
logLik_NPGL2(param = c(log(3), log(2)), x)logLik_NPGL2(param = c(log(3), log(2)), x)
param |
vector with the values for mu and sigma |
x |
vector with the data |
y <- rNPGL2(n = 100, mu = 3, sigma = 2) logLik_NPGL2(param = c(log(3), log(2)), x = y)y <- rNPGL2(n = 100, mu = 3, sigma = 2) logLik_NPGL2(param = c(log(3), log(2)), x = y)
This function calculates the mean and variance for the
hyper-Poisson distribution with parameters and .
mean_var_hp(mu, sigma) mean_var_hp2(mu, sigma)mean_var_hp(mu, sigma) mean_var_hp2(mu, sigma)
mu |
value of the mu parameter. |
sigma |
value of the sigma parameter. |
The hyper-Poisson distribution with parameters and
has a support 0, 1, 2, ... and density given by
where the function is defined as
and for and positive integer.
This function calculates the mean and variance of this distribution.
the function returns a list with the mean and variance.
Freddy Hernandez, [email protected]
Sáez-Castillo, A. J., & Conde-Sánchez, A. (2013). A hyper-Poisson regression model for overdispersed and underdispersed count data. Computational Statistics & Data Analysis, 61, 148-157.
# Example 1 # Theoretical values mean_var_hp(mu=5.5, sigma=0.1) # Using simulated values y <- rHYPERPO(n=1000, mu=5.5, sigma=0.1) mean(y) var(y) # Example 2 # Theoretical values mean_var_hp2(mu=5.5, sigma=1.9) # Using simulated values y <- rHYPERPO2(n=1000, mu=5.5, sigma=1.9) mean(y) var(y)# Example 1 # Theoretical values mean_var_hp(mu=5.5, sigma=0.1) # Using simulated values y <- rHYPERPO(n=1000, mu=5.5, sigma=0.1) mean(y) var(y) # Example 2 # Theoretical values mean_var_hp2(mu=5.5, sigma=1.9) # Using simulated values y <- rHYPERPO2(n=1000, mu=5.5, sigma=1.9) mean(y) var(y)
The function NPGL() defines the
Poisson-generalised Lindley distribution,
a two parameter distribution,
for a gamlss.family object to be used in GAMLSS
fitting using the function gamlss().
NPGL(mu.link = "log", sigma.link = "log")NPGL(mu.link = "log", sigma.link = "log")
mu.link |
defines the mu.link, with "log" link as the default for the mu parameter. |
sigma.link |
defines the sigma.link, with "log" link as the default for the sigma. |
The Poisson-generalised Lindley distribution with parameters and
has support and probability mass function given by
with and .
This distribution is useful for modeling over-dispersed count data.
Note: in this implementation we changed the original parameters and
for and respectively, we did it to implement this distribution within gamlss framework.
Returns a gamlss.family object which can be used
to fit a NPGL distribution
in the gamlss() function.
Tomás Mesa, [email protected]
Altun, E. A new two-parameter discrete poisson-generalized Lindley distribution with properties and applications to healthcare data sets. Comput Stat 36, 2841–2861 (2021). https://doi.org/10.1007/s00180-021-01097-0
# Example 1 # Generating some random values with # known mu and sigma set.seed(123) y <- rNPGL(n=100, mu=20, sigma=2) # Fitting the model library(gamlss) mod1 <- gamlss(y~1, family=NPGL, control=gamlss.control(n.cyc=500, trace=FALSE)) # Extracting the fitted values for mu and sigma exp(coef(mod1, what="mu")) exp(coef(mod1, what="sigma")) # Example 2 # Generating random values under some model # A function to simulate a data set with Y ~ NPGL gendat <- function(n) { x1 <- runif(n) x2 <- runif(n) mu <- exp(1.7 - 2.8 * x1) # Approx 1.35 sigma <- exp(0.73 + 1 * x2) # Approx 3.42 y <- rNPGL(n=n, mu=mu, sigma=sigma) data.frame(y=y, x1=x1, x2=x2) } set.seed(1234) datos <- gendat(n=200) mod2 <- gamlss(y~x1, sigma.fo=~x2, family=NPGL, data=datos, control=gamlss.control(n.cyc=800, trace=FALSE)) summary(mod2)# Example 1 # Generating some random values with # known mu and sigma set.seed(123) y <- rNPGL(n=100, mu=20, sigma=2) # Fitting the model library(gamlss) mod1 <- gamlss(y~1, family=NPGL, control=gamlss.control(n.cyc=500, trace=FALSE)) # Extracting the fitted values for mu and sigma exp(coef(mod1, what="mu")) exp(coef(mod1, what="sigma")) # Example 2 # Generating random values under some model # A function to simulate a data set with Y ~ NPGL gendat <- function(n) { x1 <- runif(n) x2 <- runif(n) mu <- exp(1.7 - 2.8 * x1) # Approx 1.35 sigma <- exp(0.73 + 1 * x2) # Approx 3.42 y <- rNPGL(n=n, mu=mu, sigma=sigma) data.frame(y=y, x1=x1, x2=x2) } set.seed(1234) datos <- gendat(n=200) mod2 <- gamlss(y~x1, sigma.fo=~x2, family=NPGL, data=datos, control=gamlss.control(n.cyc=800, trace=FALSE)) summary(mod2)
The function NPGL2() defines the mean-parametrized version of the
Poisson-generalised Lindley distribution, a two-parameter distribution,
for a gamlss.family object to be used in GAMLSS fitting using
the function gamlss().
NPGL2(mu.link = "log", sigma.link = "log")NPGL2(mu.link = "log", sigma.link = "log")
mu.link |
defines the mu.link, with "log" link as the default for the mu parameter (the mean of the distribution). |
sigma.link |
defines the sigma.link, with "log" link as the default for the sigma parameter (parameter alpha of the original NPGL). |
This family uses the mean-parametrized version of the NPGL distribution proposed in Section 6 of Altun (2021). The new parameters are:
: the mean of the distribution, i.e. .
The reparametrization links the mean and
to the original parameter via the mean
equation
Returns a gamlss.family object which can be used to fit a
mean-parametrized NPGL distribution in the gamlss() function.
Tomas Mesa, [email protected]
Altun, E. A new two-parameter discrete poisson-generalized Lindley distribution with properties and applications to healthcare data sets. Comput Stat 36, 2841-2861 (2021). https://doi.org/10.1007/s00180-021-01097-0
# Example 1 # Generating some random values with # known mu and sigma set.seed(123) y <- rNPGL2(n=5000, mu=4, sigma=2) # Fitting the model library(gamlss) mod1 <- gamlss(y~1, sigma.fo=~1, family=NPGL2, control=gamlss.control(n.cyc=500, trace=TRUE)) # Extracting the fitted values for mu and sigma # using the inverse link function exp(coef(mod1, what="mu")) exp(coef(mod1, what="sigma")) # Example 2 # Generating random values under some model # A function to simulate a data set with Y ~ NPGL2 gendat <- function(n) { x1 <- runif(n) x2 <- runif(n) mu <- exp(1.5 - 1.8 * x1) # mean of the distribution sigma <- exp(0.5 + 0.8 * x2) # shape parameter alpha y <- rNPGL2(n=n, mu=mu, sigma=sigma) data.frame(y=y, x1=x1, x2=x2) } set.seed(123) dat <- gendat(n=1000) # Fitting the model mod2 <- gamlss(y~x1, sigma.fo=~x2, family=NPGL2, data=dat, control=gamlss.control(n.cyc=800, trace=TRUE)) summary(mod2) # Example 3 # Using the data from Altun (2021), Section 8.1. # The dataset is about the 1991 Arizona cardiovascular patient. # We model the length of hospital stay (los) with cardiovascular # procedure, sex, type of admission and age as covariates. # The response variable has a dispersion index of 5.43, # confirming over-dispersion. # Data available in the azpro dataset of the COUNT package. library(COUNT) data(azpro) mod3 <- gamlss( los ~ procedure + sex + admit + age75, sigma.fo = ~1, family = NPGL2(mu.link = "log"), data = azpro, control = gamlss.control(n.cyc = 500, trace = TRUE) ) # Extracting the fitted values for mu and sigma # using the inverse link function coef(mod3, what="mu") coef(mod3, what="sigma") # Note: coef(mod3, what="mu") is the estimated mean length # of hospital stay for the reference group (PTCA procedure, # female, elective admission, age <= 75), directly interpretable # because mu is the mean of the NPGL2 distribution. # Example 4 # Using the data from Altun (2021), Section 8.2. # The dataset originates from the US National Medical Expenditure # Survey (NMES) conducted in 1987 and 1988. We model the number # of physician office visits with hospital stays, chronic conditions, # activity limitations, age, gender, marital status, income, # employment status, Medicaid, private insurance and self-perceived # health status as covariates. # The response variable has a dispersion index of 7.91, # confirming over-dispersion. # Data available in the NMES1988 dataset of the AER package. library(AER) data("NMES1988") # Set "average" as the reference category for health status, # so that healthexcellent and healthpoor are the two dummies, # matching x11 and x12 in Altun (2021). NMES1988$health <- relevel(factor(NMES1988$health), ref = "average") mod4 <- gamlss( visits ~ hospital + chronic + adl + age + gender + married + income + employed + medicaid + insurance + health, sigma.fo = ~1, family = NPGL2(mu.link = "log"), data = NMES1988, control = gamlss.control(n.cyc = 500, trace = TRUE) ) coef(mod4, what="mu") coef(mod4, what="sigma")# Example 1 # Generating some random values with # known mu and sigma set.seed(123) y <- rNPGL2(n=5000, mu=4, sigma=2) # Fitting the model library(gamlss) mod1 <- gamlss(y~1, sigma.fo=~1, family=NPGL2, control=gamlss.control(n.cyc=500, trace=TRUE)) # Extracting the fitted values for mu and sigma # using the inverse link function exp(coef(mod1, what="mu")) exp(coef(mod1, what="sigma")) # Example 2 # Generating random values under some model # A function to simulate a data set with Y ~ NPGL2 gendat <- function(n) { x1 <- runif(n) x2 <- runif(n) mu <- exp(1.5 - 1.8 * x1) # mean of the distribution sigma <- exp(0.5 + 0.8 * x2) # shape parameter alpha y <- rNPGL2(n=n, mu=mu, sigma=sigma) data.frame(y=y, x1=x1, x2=x2) } set.seed(123) dat <- gendat(n=1000) # Fitting the model mod2 <- gamlss(y~x1, sigma.fo=~x2, family=NPGL2, data=dat, control=gamlss.control(n.cyc=800, trace=TRUE)) summary(mod2) # Example 3 # Using the data from Altun (2021), Section 8.1. # The dataset is about the 1991 Arizona cardiovascular patient. # We model the length of hospital stay (los) with cardiovascular # procedure, sex, type of admission and age as covariates. # The response variable has a dispersion index of 5.43, # confirming over-dispersion. # Data available in the azpro dataset of the COUNT package. library(COUNT) data(azpro) mod3 <- gamlss( los ~ procedure + sex + admit + age75, sigma.fo = ~1, family = NPGL2(mu.link = "log"), data = azpro, control = gamlss.control(n.cyc = 500, trace = TRUE) ) # Extracting the fitted values for mu and sigma # using the inverse link function coef(mod3, what="mu") coef(mod3, what="sigma") # Note: coef(mod3, what="mu") is the estimated mean length # of hospital stay for the reference group (PTCA procedure, # female, elective admission, age <= 75), directly interpretable # because mu is the mean of the NPGL2 distribution. # Example 4 # Using the data from Altun (2021), Section 8.2. # The dataset originates from the US National Medical Expenditure # Survey (NMES) conducted in 1987 and 1988. We model the number # of physician office visits with hospital stays, chronic conditions, # activity limitations, age, gender, marital status, income, # employment status, Medicaid, private insurance and self-perceived # health status as covariates. # The response variable has a dispersion index of 7.91, # confirming over-dispersion. # Data available in the NMES1988 dataset of the AER package. library(AER) data("NMES1988") # Set "average" as the reference category for health status, # so that healthexcellent and healthpoor are the two dummies, # matching x11 and x12 in Altun (2021). NMES1988$health <- relevel(factor(NMES1988$health), ref = "average") mod4 <- gamlss( visits ~ hospital + chronic + adl + age + gender + married + income + employed + medicaid + insurance + health, sigma.fo = ~1, family = NPGL2(mu.link = "log"), data = NMES1988, control = gamlss.control(n.cyc = 500, trace = TRUE) ) coef(mod4, what="mu") coef(mod4, what="sigma")
Draw the CDF for a discrete random variable
plot_discrete_cdf(x, fx, col = "blue", lwd = 3, ...)plot_discrete_cdf(x, fx, col = "blue", lwd = 3, ...)
x |
vector with the values of the random variable |
fx |
vector with the probabilities of |
col |
color for the line. |
lwd |
line width. |
... |
further arguments and graphical parameters. |
A plot with the cumulative distribution function.
Freddy Hernandez, [email protected]
# Example 1 # for a particular distribution x <- 1:6 fx <- c(0.19, 0.21, 0.4, 0.12, 0.05, 0.03) plot_discrete_cdf(x, fx, las=1, main="") # Example 2 # for a Poisson distribution x <- 0:10 fx <- dpois(x, lambda=3) plot_discrete_cdf(x, fx, las=1, main="CDF for Poisson")# Example 1 # for a particular distribution x <- 1:6 fx <- c(0.19, 0.21, 0.4, 0.12, 0.05, 0.03) plot_discrete_cdf(x, fx, las=1, main="") # Example 2 # for a Poisson distribution x <- 0:10 fx <- dpois(x, lambda=3) plot_discrete_cdf(x, fx, las=1, main="CDF for Poisson")
The function POISXL() defines the
Discrete Poisson XLindley distribution
a single parameter distribution,
for a gamlss.family object to be used in GAMLSS
fitting using the function gamlss().
POISXL(mu.link = "log")POISXL(mu.link = "log")
mu.link |
defines the mu.link, with "log" link as the default for the mu parameter. |
The Discrete Poisson XLindley distribution with parameters has a support
0, 1, 2, ... and mass function given by
; with .
Note: in this implementation we changed the original parameters for ,
we did it to implement this distribution within gamlss framework.
Returns a gamlss.family object which can be used
to fit a Discrete Poisson XLindley distribution
in the gamlss() function.
Mariana Blandon Mejia, [email protected]
Ahsan-ul-Haq, M., Al-Bossly, A., El-Morshedy, M., & Eliwa, M. S. (2022). Poisson XLindley distribution for count data: statistical and reliability properties with estimation techniques and inference. Computational Intelligence and neuroscience, 2022(1), 6503670.
# Example 1 # Generating some random values with # known mu y <- rPOISXL(n=1000, mu=1) # Fitting the model library(gamlss) mod1 <- gamlss(y~1, family=POISXL, control=gamlss.control(n.cyc=500, trace=FALSE)) # Extracting the fitted values for mu # using the inverse link function exp(coef(mod1, what="mu")) # Example 2 # Generating random values under some model # A function to simulate a data set with Y ~ POISXL gendat <- function(n) { x1 <- runif(n, min=0.4, max=0.6) mu <- exp(1.21 - 3 * x1) # 0.75 approximately y <- rPOISXL(n=n, mu=mu) data.frame(y=y, x1=x1) } dat <- gendat(n=1500) # Fitting the model mod2 <- NULL mod2 <- gamlss(y~x1, family=POISXL, data=dat, control=gamlss.control(n.cyc=500, trace=FALSE)) summary(mod2) # Example 3 # The counts the number of borers per hill of corn in an # experiment conducted randomly on 8 hills in 15 replications. # Taken from Ahsan-ul-Haq et al (2022) page 10. y <- rep(x=0:8, times=c(43, 35, 17, 11, 5, 4, 1, 2, 2)) mod3 <- gamlss(y~1, family=POISXL, control=gamlss.control(n.cyc=500, trace=FALSE)) # Extracting the fitted values for mu exp(coef(mod3, what="mu")) # Example 4 # The number of mammalian cytogenetic dosimetry lesions produced # by streptogramin exposure in rabbit. # Taken from Ahsan-ul-Haq et al (2022) page 10. y <- rep(x=0:4, times=c(200, 57, 30, 7, 6)) mod4 <- gamlss(y~1, family=POISXL, control=gamlss.control(n.cyc=500, trace=FALSE)) # Extracting the fitted values for mu exp(coef(mod4, what="mu"))# Example 1 # Generating some random values with # known mu y <- rPOISXL(n=1000, mu=1) # Fitting the model library(gamlss) mod1 <- gamlss(y~1, family=POISXL, control=gamlss.control(n.cyc=500, trace=FALSE)) # Extracting the fitted values for mu # using the inverse link function exp(coef(mod1, what="mu")) # Example 2 # Generating random values under some model # A function to simulate a data set with Y ~ POISXL gendat <- function(n) { x1 <- runif(n, min=0.4, max=0.6) mu <- exp(1.21 - 3 * x1) # 0.75 approximately y <- rPOISXL(n=n, mu=mu) data.frame(y=y, x1=x1) } dat <- gendat(n=1500) # Fitting the model mod2 <- NULL mod2 <- gamlss(y~x1, family=POISXL, data=dat, control=gamlss.control(n.cyc=500, trace=FALSE)) summary(mod2) # Example 3 # The counts the number of borers per hill of corn in an # experiment conducted randomly on 8 hills in 15 replications. # Taken from Ahsan-ul-Haq et al (2022) page 10. y <- rep(x=0:8, times=c(43, 35, 17, 11, 5, 4, 1, 2, 2)) mod3 <- gamlss(y~1, family=POISXL, control=gamlss.control(n.cyc=500, trace=FALSE)) # Extracting the fitted values for mu exp(coef(mod3, what="mu")) # Example 4 # The number of mammalian cytogenetic dosimetry lesions produced # by streptogramin exposure in rabbit. # Taken from Ahsan-ul-Haq et al (2022) page 10. y <- rep(x=0:4, times=c(200, 57, 30, 7, 6)) mod4 <- gamlss(y~1, family=POISXL, control=gamlss.control(n.cyc=500, trace=FALSE)) # Extracting the fitted values for mu exp(coef(mod4, what="mu"))
The function PTRTE() defines the Poisson-transmuted record type exponential distribution,
a two-parameter discrete distribution, for a gamlss.family object to be used in GAMLSS fitting
using the function gamlss().
PTRTE(mu.link = "log", sigma.link = "logit")PTRTE(mu.link = "log", sigma.link = "logit")
mu.link |
defines the link function for the mu parameter, with "log" as the default. |
sigma.link |
defines the link function for the sigma parameter, with "logit" as the default. |
The Poisson-transmuted record type exponential distribution with parameters
and has support and probability mass function given by
Parameter restrictions:
and .
Note: we renamed the original parameters and to and respectively
to implement this distribution within the gamlss framework.
Returns a gamlss.family object that can be used to fit the Poisson-transmuted record type exponential
distribution using the gamlss() function.
Rebeca Isabel Rodriguez Gonzalez, [email protected]
Erbayram, T., & Akdogan, Y. (2025). A new discrete model generated from mixed Poisson transmuted record type exponential distribution. Ricerca di Matematica, 74, 1225–1247.
# Example 1 # Generating some random values with known mu and sigma # logit_inv function logit_inv <- function(x) exp(x) / (exp(x)+1) set.seed(12345) y <- rPTRTE(n=200, mu=0.2, sigma=0.5) # Fitting the model library(gamlss) mod1 <- gamlss(y~1, family=PTRTE) # Extracting the fitted values for mu and sigma exp(coef(mod1, what="mu")) logit_inv(coef(mod1, what="sigma")) # Example 2 # Generating random values under some model # A function to simulate a data set with Y ~ PTRTE gendat <- function(n) { x1 <- runif(n) x2 <- runif(n) mu <- exp(2 + 1 * x1) # 12 approximately sigma <- logit_inv(2 - 2 * x2) # 0.73 approximately y <- rPTRTE(n=n, mu=mu, sigma=sigma) data.frame(y=y, x1=x1, x2=x2) } set.seed(12345) dat <- gendat(n=2000) # Fitting the model mod2 <- NULL mod2 <- gamlss(y~x1, sigma.fo=~x2, family=PTRTE, data=dat, control=gamlss.control(n.cyc=500, trace=FALSE)) summary(mod2) # Example 3 (Second data set of the article) # European corn-borer count data reported by McGuire et al. (1957). # The observed and fitted frequencies are given in Table 11 of # Erbayram and Akdogan (2025), where the P-TRTE distribution is # illustrated using this data set. values <- 0:5 freq <- c(188, 83, 36, 14, 2, 1) y <- rep(x=values, times=freq) mod3 <- gamlss(y~1, sigma.fo=~1, family=PTRTE(), control=gamlss.control(n.cyc=500, trace=TRUE)) exp(coef(mod3, what="mu")) logit_inv(coef(mod3, what="sigma"))# Example 1 # Generating some random values with known mu and sigma # logit_inv function logit_inv <- function(x) exp(x) / (exp(x)+1) set.seed(12345) y <- rPTRTE(n=200, mu=0.2, sigma=0.5) # Fitting the model library(gamlss) mod1 <- gamlss(y~1, family=PTRTE) # Extracting the fitted values for mu and sigma exp(coef(mod1, what="mu")) logit_inv(coef(mod1, what="sigma")) # Example 2 # Generating random values under some model # A function to simulate a data set with Y ~ PTRTE gendat <- function(n) { x1 <- runif(n) x2 <- runif(n) mu <- exp(2 + 1 * x1) # 12 approximately sigma <- logit_inv(2 - 2 * x2) # 0.73 approximately y <- rPTRTE(n=n, mu=mu, sigma=sigma) data.frame(y=y, x1=x1, x2=x2) } set.seed(12345) dat <- gendat(n=2000) # Fitting the model mod2 <- NULL mod2 <- gamlss(y~x1, sigma.fo=~x2, family=PTRTE, data=dat, control=gamlss.control(n.cyc=500, trace=FALSE)) summary(mod2) # Example 3 (Second data set of the article) # European corn-borer count data reported by McGuire et al. (1957). # The observed and fitted frequencies are given in Table 11 of # Erbayram and Akdogan (2025), where the P-TRTE distribution is # illustrated using this data set. values <- 0:5 freq <- c(188, 83, 36, 14, 2, 1) y <- rep(x=values, times=freq) mod3 <- gamlss(y~1, sigma.fo=~1, family=PTRTE(), control=gamlss.control(n.cyc=500, trace=TRUE)) exp(coef(mod3, what="mu")) logit_inv(coef(mod3, what="sigma"))