2014-02-02 04:07:49 +00:00
|
|
|
# Get distribution function from characteristic function
|
|
|
|
#
|
|
|
|
# Author: François Pelletier
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
|
|
|
|
#' Get distribution function from characteristic function
|
|
|
|
#'
|
2014-02-20 01:35:43 +00:00
|
|
|
#' @param grid Distribution function evaluation points
|
2014-02-02 04:07:49 +00:00
|
|
|
#' @param char.fun Vectorized characteristic function
|
|
|
|
#' @param param Characteristic function parameters
|
|
|
|
#' @param wmin Lower bound for transform variate
|
|
|
|
#' @param wmax Upper bound for transform variate
|
|
|
|
#' @return Distribution function values evaluated on [min,max] range
|
|
|
|
#' @author François Pelletier
|
2014-02-20 01:35:43 +00:00
|
|
|
cftocdf <- function(grid,char.fun,...,wmin=0,wmax=50,MSwindows=FALSE)
|
2014-02-02 04:07:49 +00:00
|
|
|
{
|
2014-02-20 01:35:43 +00:00
|
|
|
n <- length(grid)
|
|
|
|
# Integral in the Gil-Pelaez Ttheorem
|
|
|
|
integrand <- function(w,x,char.fun,...,wmax=50) (1-w/wmax)*
|
|
|
|
Im(exp(-1i*w*x)*char.fun(w,...)) / w
|
|
|
|
# Integrate for each grid point using parallel computation if available
|
2014-02-02 04:07:49 +00:00
|
|
|
if(!MSwindows)
|
|
|
|
{
|
|
|
|
unlist(mclapply(grid,
|
|
|
|
function(x) 1/2-1/pi*
|
2014-02-20 01:35:43 +00:00
|
|
|
integrate(integrand,wmin,wmax,x,char.fun,...)$value))
|
2014-02-02 04:07:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
warning("For faster calculations, use a POSIX compatible Operating System")
|
|
|
|
Fx <- numeric(n)
|
|
|
|
for(i in 1:n)
|
|
|
|
{
|
2014-02-20 01:35:43 +00:00
|
|
|
Fx[i] <- 1/2-1/pi*integrate(integrand,wmin,wmax,x,char.fun,...)$value
|
2014-02-02 04:07:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|