View source: R/Transformations.R
| trapzc | R Documentation |
Approximates the integral of a function from its values on an equidistant grid by the composite trapezoidal rule,
\int_a^b f(t)\,dt \approx h\left(\frac{f_1}{2} + f_2 + \dots + f_{n-1} + \frac{f_n}{2}\right),
where h is the grid spacing. It is the integration routine used by
fcenLR, fcenLRp, fcenLRu,
fcenLRinv and compositionalSpline.
trapzc(step, f)
step |
spacing |
f |
numeric vector of at least two function values on the grid, e.g. a density or a clr-transformed density. |
A single number: the approximate value of the integral.
R. Talska talskarenata@seznam.cz, K. Hron karel.hron@upol.cz
fcenLR, fcenLRinv
t <- seq(-4.7, 4.7, length = 1000)
t_step <- diff(t[1:2])
f <- dnorm(t, mean = 0, sd = 1.5)
# integral of the density over the grid (close to 1)
trapzc(t_step, f)
# the clr transform of a density integrates to zero
trapzc(t_step, fcenLR(t, t_step, f))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.