integration | R Documentation |
This is a wrapper routine for integration in maxlogL
framework. It is
used in integration for compute detectability density functions and in
computation of mean values, but it is also a general purpose integrator.
integration(fun, lower, upper, routine = "integrate", ...)
fun |
an R function which should take a numeric argument x and
possibly some parameters. The function returns a numerical vector
value for the given argument |
lower |
a numeric value for the lower limit of the integral. |
upper |
a numeric value for the upper limit of the integral. |
routine |
a character specifying the integration routine.
|
... |
additional arguments to be passed to |
The user can create custom integration routines through implementation of a wrapper function using three arguments
funa function which should take a numeric argument x and possibly some parameters.
lowera numeric value for the lower limit of the integral.
uppera numeric value for the upper limit of the integral.
...furthermore, the user must define additional arguments to be
passed to fun
.
The output must be a numeric atomic value with the result of the integral.
Jaime Mosquera GutiƩrrez, jmosquerag@unal.edu.co
integrate
, gauss_quad
library(EstimationTools) #---------------------------------------------------------------------------- # Example 1: Mean of X ~ N(2,1) using 'integrate'. mynorm <- function(x, mu, sigma) x*dnorm(x, mean = mu, sd = sigma) i1 <- integration(mynorm, lower = -Inf, upper = Inf, mu = 2, sigma = 1) i1 #---------------------------------------------------------------------------- # Example 2: Mean of X ~ N(2,1) using 'gauss_quad' (Gauss-Hermitie # quadrature). g <- function(x, mu, sigma) sqrt(2)*sigma*x + mu i2 <- integration(g, lower = -Inf, upper = Inf, routine = 'gauss_quad', kind = 'hermite.h', normalized = FALSE, mu = 2, sigma = 1) i2 <- i2/sqrt(pi) i2 #---------------------------------------------------------------------------- # Example 3: replicating integrate i3 <- integrate(dnorm, lower=-1.96, upper=1.96) i4 <- integration(dnorm, lower=-1.96, upper=1.96) identical(i3$value, i4) #----------------------------------------------------------------------------
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.