Topic: Utilities

Topic Description:

Basic R utilities used in many packages and functions, such as date and string manipulations, statistical distributions, geometry of lines and distances. The R package date is required for the two data functions.



File: utilities/distributions.r

View File Source Download File No help file available

Function: dgammadexp

Function Description: dgammadexp

PDF of a function formed by adding a gamma distribution to a symmetrical exponential distribution. This means simply adding a PDF for a gamma minus an exponential to the PDF for a gamma plus an exponential.

Function Arguments:

ArgumentDefault Value
z
mean
sd
lambda
draws10000
div.1
xrangec(-10,30)
graphitF

Function Source:

dgammadexp=function(z,mean,sd,lambda,draws=10000,div=.1,xrange=c(-10,30),graphit=F)
{
sumpart=dgammaPlusdexp(z,mean,sd,lambda)
diffpart=dgammaMinusdexp(z,mean,sd,lambda)
result=0.5*sumpart+0.5*diffpart

if(graphit)
{
r=mean/(sd^2)
a=mean*r

growth=rgamma(draws,shape=a,rate=r)
error=rsymexp(draws,center=0,rate=lambda)

obs=growth+error
minx=min(obs)-div
maxx=max(obs)+div
x=seq(minx,maxx,by=div)
hist(obs,breaks=x,xlim=xrange)
lines(z,draws*div*result)
}

return(result)
}