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: dpois.max
Function Description: dpois.max
A probability distribution which is simply a curtailed poisson: all probability above a maximum integer, maxx, is given to that maximum. For all xFunction Arguments:
| Argument | Default Value |
|---|---|
| x | |
| lambda | |
| maxx | |
| log | FALSE |
Function Source:
dpois.max=function(x,lambda,maxx,log=FALSE)
{
result=standard=dpois(x,lambda=lambda)
below=which(x above=which(x>maxx)
exact=which(x==maxx)
if(length(below)>0) result[below]=standard[below]
if(length(above)>0) result[above]=0
if(length(exact)>0) result[exact]=1-sum(dpois(0:(maxx-1),lambda=lambda))
if(log) return(log(result))
else return(result)
}
#
#
# dpois.trunc
#
#
# A zero-truncated Poisson distribution.
#
#
#
#
#
#
#
#
dpois.trunc=function(x,lambda,log=FALSE)
{
result=dpois(x,lambda=lambda)/(1-exp(-lambda))
zero=x==0
result[zero]=0
if(log) return(log(result))
else return(result)
}
{
result=standard=dpois(x,lambda=lambda)
below=which(x
exact=which(x==maxx)
if(length(below)>0) result[below]=standard[below]
if(length(above)>0) result[above]=0
if(length(exact)>0) result[exact]=1-sum(dpois(0:(maxx-1),lambda=lambda))
if(log) return(log(result))
else return(result)
}
#
#
# dpois.trunc
#
#
# A zero-truncated Poisson distribution.
#
#
#
#
#
#
#
#
dpois.trunc=function(x,lambda,log=FALSE)
{
result=dpois(x,lambda=lambda)/(1-exp(-lambda))
zero=x==0
result[zero]=0
if(log) return(log(result))
else return(result)
}