gamlss-dev / gamlss.dist Goto Github PK
View Code? Open in Web Editor NEWgamlss.dist: Distributions for Generalized Additive Models for Location Scale and Shape
Home Page: https://CRAN.R-project.org/package=gamlss.dist
gamlss.dist: Distributions for Generalized Additive Models for Location Scale and Shape
Home Page: https://CRAN.R-project.org/package=gamlss.dist
I fitted a GB2 distribution to my income data and then got puzzled when examining the parameter estimates. I observed that for parameters similar to c(809.6687, 116.4727, 0.0342, 0.0278)
, the quantile values returned by qGB2 are somewhat strange. For instance, the 10% Percentile is still 0 which does not make sense to me, in particular when having a look at the associated density function. Also, using the random number generator rGB2 many 0 values are drawn from the distribution.
I compared the results to the ones by the GB2
R package. Here, the quantile values look more reasonable to me for the very same set of GB2 parameters. For standard GB2 parameters, the two packages return identical results but not for some extreme parameter values. Why is that and might this be a potential bug in the gamlss.dist package?
Here, my example code:
##### GB2 Distribution #####
rm(list = ls())
set.seed(79)
library(GB2)
library(gamlss.dist)
params = c(809.6687, 116.4727, 0.0342, 0.0278)
# params = c(1, 1, 1, 0.5)
mu = params[1]
sigma = params[2]
nu = params[3]
tau = params[4]
GB2::qgb2(c(0.1, 0.5, 0.9), shape1 = sigma, scale = mu, shape2 = nu, shape3 = tau)
gamlss.dist::qGB2(c(0.1, 0.5, 0.9), mu = mu, sigma = sigma, nu = nu, tau = tau)
GB2::pgb2(c(10, 100, 1000, 10000), shape1 = sigma, scale = mu, shape2 = nu, shape3 = tau)
gamlss.dist::pGB2(c(10, 100, 1000, 10000), mu = mu, sigma = sigma, nu = nu, tau = tau)
GB2::dgb2(c(10, 100, 1000, 10000), shape1 = sigma, scale = mu, shape2 = nu, shape3 = tau)
gamlss.dist::dGB2(c(10, 100, 1000, 10000), mu = mu, sigma = sigma, nu = nu, tau = tau)
r1 = GB2::rgb2(100000, shape1 = sigma, scale = mu, shape2 = nu, shape3 = tau)
summary(r1)
sum(r1 == 0)
r2 = gamlss.dist::rGB2(100000, mu = mu, sigma = sigma, nu = nu, tau = tau)
summary(r2)
sum(r2 == 0)
I've found an issue with the BCCG distribution functions. They don't gracefully handle missing values due to the use of any(q < 0)
, which will return NA
if any of its inputs are missing. Here's a reprex, and a comparison to the behaviour of pnorm, which behaves as expected:
# quantiles
q1 = c(0,1)
q2 = c(0,1,NA_real_)
# Expected output: 2 numbers
gamlss.dist::pBCCG(q1, mu = 1, sigma = 1, nu = 0)
#> [1] 0.0 0.5
pnorm(q1, 1, 0.5)
#> [1] 0.02275013 0.50000000
# Expected output: 2 numbers and a missing value. pnorm does this,
# but pBCCG returns an error
gamlss.dist::pBCCG(q2, mu = 1, sigma = 1, nu = 0)
#> Error in if (any(q < 0)) stop(paste("q must be positive", "\n", "")): missing value where TRUE/FALSE needed
pnorm(q2, mean = 1, sd = 0.5)
#> [1] 0.02275013 0.50000000 NA
Created on 2023-09-14 with reprex v2.0.2
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.