trun: Fits a Truncate Distribution from a gamlss.family

Description Usage Arguments Details Value Note Author(s) References See Also Examples

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

1
2
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 "left" or "right" truncation) or two elements for "both". When the argument varying = TRUE then par can be a vector or a matrix with two columns respectively.

family

an existing gamlss.family distribution

type

what type of truncation is required, left, right or both. If both the par should be a vector of length two. (the default is left truncation)

name

a character string to be added to name of the created object i.e. with family=TF and name=trZero the gamlss.family object will be called TFtrZero

local

if TRUE the function will try to find the environment of gamlss to generate the d and p functions required for the fitting, if FALSE the functions will be generated in the global environment

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 varying = TRUE then par should be an n-length vector for type equal "left" and "right" and an n by 2 matrix for type="both"

...

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 [email protected] 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.

Stasinopoulos D. M., Rigby R.A. and Akantziliotou C. (2003) Instructions on how to use the GAMLSS package in R. Accompanying documentation in the current GAMLSS help files, (see also http://www.gamlss.org/).

See Also

trun.d, trun.p, trun.q, trun.r, gen.trun

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# 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)

Example output

Loading required package: gamlss.dist
Loading required package: MASS
Loading required package: gamlss
Loading required package: splines
Loading required package: gamlss.data
Loading required package: nlme
Loading required package: parallel
 **********   GAMLSS Version 5.1-2  ********** 
For more on GAMLSS look at http://www.gamlss.org/
Type gamlssNews() to see new features/changes/bug fixes.

A truncated family of distributions from TF has been generated 
 and saved under the names:  
 dTFtr pTFtr qTFtr rTFtr TFtr 
The type of truncation is left 
 and the truncation parameter is 0  
GAMLSS-RS iteration 1: Global Deviance = 6141.149 
GAMLSS-RS iteration 2: Global Deviance = 6138.934 
GAMLSS-RS iteration 3: Global Deviance = 6138.416 
GAMLSS-RS iteration 4: Global Deviance = 6138.318 
GAMLSS-RS iteration 5: Global Deviance = 6138.301 
GAMLSS-RS iteration 6: Global Deviance = 6138.297 
GAMLSS-RS iteration 7: Global Deviance = 6138.296 
GAMLSS-RS iteration 8: Global Deviance = 6138.295 

Family:  c("TFtr", "left truncated t Family") 
Fitting method: RS() 

Call:  gamlss(formula = sam ~ 1, family = trun(0, TF)) 

Mu Coefficients:
(Intercept)  
      9.866  
Sigma Coefficients:
(Intercept)  
      1.626  
Nu Coefficients:
(Intercept)  
      1.645  

 Degrees of Freedom for the fit: 3 Residual Deg. of Freedom   997 
Global Deviance:     6138.3 
            AIC:     6144.3 
            SBC:     6159.02 
GAMLSS-RS iteration 1: Global Deviance = 6141.149 
GAMLSS-RS iteration 2: Global Deviance = 6138.934 
GAMLSS-RS iteration 3: Global Deviance = 6138.416 
GAMLSS-RS iteration 4: Global Deviance = 6138.318 
GAMLSS-RS iteration 5: Global Deviance = 6138.301 
GAMLSS-RS iteration 6: Global Deviance = 6138.297 
GAMLSS-RS iteration 7: Global Deviance = 6138.296 
GAMLSS-RS iteration 8: Global Deviance = 6138.295 
GAMLSS-RS iteration 1: Global Deviance = 6141.133 
GAMLSS-RS iteration 2: Global Deviance = 6138.925 
GAMLSS-RS iteration 3: Global Deviance = 6138.415 
GAMLSS-RS iteration 4: Global Deviance = 6138.317 
GAMLSS-RS iteration 5: Global Deviance = 6138.301 
GAMLSS-RS iteration 6: Global Deviance = 6138.296 
GAMLSS-RS iteration 7: Global Deviance = 6138.296 

gamlss.tr documentation built on May 2, 2019, 7:15 a.m.