R/cfE_EmpiricalBootstrapped.R

Defines functions cfE_EmpiricalBootstrapped

#' @title Characteristic function of the EMPIRICAL BOOTSTRAPPED distribution, based on the bootstrapped data
#'
#' @description
#' That is, \eqn{cf(t) = (1/N)*(cfD(dataBoot_1*t) +...+ cfD(dataBoot_N*t))}, where
#' \eqn{cfD(t)} represents the characteristic function of the DIRAC RV
#' concentrated at the constant \eqn{d=1}, i.e. \eqn{cfD(t) = exp(1i*t)}.
#'
#' \code{cfE_Empirical(t, data, randID, cfX)} evaluates the compound characteristic function
#' \eqn{cf(t) = cfE_EmpiricalBootstrapped(-1i*log(cfX(t)),data,randID) = (1/N) * sum_{j=1}^N cfX(t)^dataBoot_j};
#' where \code{cfX} is function handle of the characteristic function \eqn{cfX(t)} of the random variable \eqn{X}.
#'
#' @family Empirical Probability Distribution
#'
#' @seealso For more details see WIKIPEDIA:
#' \url{https://en.wikipedia.org/wiki/Empirical_distribution_function.}
#' \url{https://en.wikipedia.org/wiki/Bootstrapping_(statistics)}

#'
#' @param t vector or array of real values, where the CF is evaluated.
#' @param data vector of original data. If empty, default value is \code{data = 1}.
#' @param randID vector of pseudorandom  integers between 1 and \code{lemngth(data)}. If
#' empty, randID is randomly generated by \code{randID = randi(length(data),size(data))}.
#' @param cfX function handle of the characteristic function of a random
#' variable \eqn{X}. If \code{cfX} is non-empty, a compound CF is evaluated as \eqn{cf(t) = cf(-1i*log(cfX(t)),data)}.
#'
#' @return Characteristic function \eqn{cf(t)} of the EMPIRICAL BOOTSTRAPPED distribution, based on the bootstrapped data.
#'
#' @references
#' WITKOVSKY V., WIMMER G., DUBY T. (2017). Computing the aggregate
#' loss distribution based on numerical inversion of the compound empirical
#' characteristic function of frequency and severity. arXiv preprint arXiv:1701.08299.
#'
#' @note Ver.: 02-Sep-2022 17:21:10 (consistent with Matlab CharFunTool v1.5.1, 15-Sep-2018 11:47:29).
#'
#' @example R/Examples/example_cfE_EmpiricalBootstrapped.R
#'
#' @export
#'


cfE_EmpiricalBootstrapped <- function(t, data, randID, cfX) {
        ## CHECK THE INPUT PARAMETERS
        if(missing(data)){
                data<-vector()}
        if(missing(randID)) {
                randID<-vector()}
        if(missing(cfX)) {
                cfX<-NULL}
if (length(data)==0) {
        data<-1
}

        szd<-dim(data)
        data<-Conj(data)
        dataN<-length(data)

        if (length(randID)==0) {
                randID<-pracma::randi(dataN,dataN,1)
        }

        data<-data[randID]
        dim(data) <- szd

        weights<-vector()
        cf<-cfE_DiracMixture(t,data,weights,cfX)

        return(cf)
}
gajdosandrej/CharFunToolR documentation built on June 3, 2024, 7:46 p.m.