trun {gamlss.tr} | R Documentation |
Fits a Truncate Distribution from a gamlss.family
Description
This function can be used to fit truncated distributions. It takes as an argument an existing GAMLSS family distribution and
a parameter vector, of the type c(left.value, right.value), and generates a gamlss.family
object which then can be used to fit
a truncated distribution.
Usage
trun(par = c(0), family = "NO", type = c("left", "right", "both"), name = "tr",
local = TRUE, delta=NULL, varying = FALSE, ...)
Arguments
par |
a vector with one (for |
family |
an existing |
type |
what type of truncation is required, |
name |
a character string to be added to name of the created object i.e. with |
local |
if TRUE the function will try to find the environment of |
delta |
the delta increment used in the numerical derivatives |
varying |
whether the truncation varies for diferent observations. This can be usefull in regression analysis. If |
... |
for extra arguments |
Details
This function is created to help the user to fit a truncated form of existing gamlss
distribution.
It does this by taking an existing gamlss.family
and changing some of the components of the distribution to help the fitting process.
It particular it i) creates a pdf (d
) and a cdf (p
) function within gamlss
,
ii) changes the global deviance function G.dev.incr
, the first derivative functions (see note below) and the quantile residual function.
Value
It returns a gamlss.family
object which has all the components needed for fitting a distribution in gamlss
.
Note
This function is experimental and could be changed. The function trun
changes
the first derivatives of the original gamlss family d
function to numerical derivatives
for the new truncated d
function. The default increment delta
,
for this numerical derivatives function, is eps * pmax(abs(x), 1)
where
eps<-sqrt(.Machine$double.eps)
. The default delta
could be inappropriate
for specific applications and can be overwritten by using the argument delta
.
Author(s)
Mikis Stasinopoulos d.stasinopoulos@gre.ac.uk and Bob Rigby
References
Rigby, R. A. and Stasinopoulos D. M. (2005). Generalized additive models for location, scale and shape,(with discussion), Appl. Statist., 54, part 3, pp 507-554.
Rigby, R. A., Stasinopoulos, D. M., Heller, G. Z., and De Bastiani, F. (2019) Distributions for modeling location, scale, and shape: Using GAMLSS in R, Chapman and Hall/CRC. An older version can be found in https://www.gamlss.com/.
Stasinopoulos D. M. Rigby R.A. (2007) Generalized additive models for location scale and shape (GAMLSS) in R. Journal of Statistical Software, Vol. 23, Issue 7, Dec 2007, https://www.jstatsoft.org/v23/i07/.
Stasinopoulos D. M., Rigby R.A., Heller G., Voudouris V., and De Bastiani F., (2017) Flexible Regression and Smoothing: Using GAMLSS in R, Chapman and Hall/CRC.
(see also https://www.gamlss.com/).
See Also
trun.d
, trun.p
, trun.q
, trun.r
, gen.trun
Examples
# generate a left truncated zero t family
gen.trun(0,family="TF")
# take a random sample of 1000 observations
sam<-rTFtr(1000,mu=10,sigma=5, nu=5 )
hist(sam)
# fit the distribution to the data
mod1<-gamlss(sam~1, family=trun(0,TF))
mod1
# now create a gamlss.family object before the fitting
Ttruc.Zero<- trun(par=0,family=TF, local=FALSE)
mod2<-gamlss(sam~1, family=Ttruc.Zero)
# now check the sensitivity of delta
Ttruc.Zero<- trun(par=0,family=TF, local=FALSE, delta=c(0.01,0.01, 0.01))
mod3<-gamlss(sam~1, family=Ttruc.Zero)