Description Usage Arguments Details Value Source References See Also Examples

Returns density, probability, quantile values and random generation for distribution functions left-truncated at a specified value.

1 2 3 4 |

`f` |
character;
root name of the density or distribution function to be truncated
- e.g., |

`x, q` |
vector of quantiles. |

`trunc` |
numeric, |

`p` |
vector of probabilities. |

`n` |
number of random values to return. |

`coef` |
numeric named list; parameters values of the density or distribution function, named accordingly (see details). |

`log, log.p` |
logical; if TRUE, probabilities p are given as log(p). |

`lower.tail` |
logical; if TRUE (default), probabilities are P[X <= x], otherwise, P[X > x]. |

Given a distribution with probability distribution function (PDF) g
and cumulative distribution function (CDF) G, a random variable
`x`

with these distributions left-truncated at `trunc`

has
its PDF:

g'(x) = g(x)/(1 - G(trunc)) for any x <= trunc and zero otherwise

and CDF:

G'(x) = (G(max(x,trunc)) - G(trunc)) / (1 - G(trunc))

`dtrunc`

and `ptrunc`

calculates the left-truncated
distributions functions
g'(x) and G'(x) defined above for
a vector of values `x`

from any
standard distribution function available in R.
This means the 'upper tail' of a continuous distribution
is rescaled to integrate to one.
Accordingly, for discrete distributions, the probabilities
for all `x`

>trunc are rescaled to sum one.
`qtrunc`

is the inverse function of `ptrunc`

.

Left-truncated distributions can be used to describe the species abundance distributions (SADs), specially for continuous distributions (e.g., truncated lognormal distribution).

`dtrunc`

gives the (log) density defined by `f`

left-truncated at `trunc`

.
`ptrunc`

gives the (log) distribution function defined by
`f`

left-truncated at `trunc`

.
`qtrunc`

gives the quantile of the density defined by `f`

left-truncated at `trunc`

.
`rtrunc`

generates a sample from the density defined by `f`

left-truncated at `trunc`

.

Codes from Nadarajah and Kotz (2006), which provide a more generic solution for left and right truncation.

Nadarajah, S. and Kotz, S. 2006. R Programs for Computing Truncated
Distributions. *Journal of Statistical Software 16*:Code Snippet 2.

Distributions for standard distributions in R;
many functions in package sads have an argument `trunc`

that
allows to simulate and fit truncated
distributions
for species abundance distributions (e.g., `fitsad`

`rsad`

, `radpred`

, `octavpred`

.
Package 'VGAM' has truncated versions of many standard functions;
see `Truncate-methods`

in package distr for general
methods to build R objects of truncated distributions.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | ```
A <- dtrunc("lnorm", x = 1:5, trunc = 0.5,
coef = list( meanlog=1, sdlog=1.5 ) )
## same as
B <- dlnorm( 1:5 , meanlog = 1, sdlog = 1.5 ) /
( plnorm ( 0.5 , meanlog = 1, sdlog = 1.5, lower = FALSE))
## checking
identical( A, B )
A <- ptrunc("pois", q = 1:5, trunc = 0,
coef = list( lambda = 1.5 ) )
## same as
B <- (ppois( 1:5 , lambda = 1.5 ) -
ppois(0 , lambda = 1.5 ) ) /
(ppois(0 , lambda = 1.5, lower = FALSE))
## checking
identical(A,B)
# Random generation
rtrunc("ls", 100, coef=list(N=1000, alpha=50), trunc=5)
``` |

```
Loading required package: bbmle
Loading required package: stats4
[1] TRUE
[1] TRUE
[1] 8 6 13 7 7 34 19 8 12 10 8 25 7 22 22 9 11 17
[19] 22 14 9 12 14 14 13 18 27 11 7 19 29 12 37 32 11 6
[37] 11 17 9 16 6 6 6 9 14 22 6 7 7 18 24 11 7 13
[55] 11 6 18 11 9 9 7 11 8 7 36 25 6 17 7 6 14 33
[73] 35 41 7 13 7 10 9 13 9 111 17 11 51 10 38 6 17 9
[91] 14 54 14 6 6 7 28 12 44 17
```

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.