R/est_dens_squared.R

Defines functions est_dens_squared

Documented in est_dens_squared

#This is an internal helper function used below
#It squares the estimated density
#' @title Square projection estimator
#' 
#' @description this function squares the density estimated by the projection estimator
#' @param basis an object of class \code{\link{Basis}}
#' @param data a sample of i.i.d. real random variables with common density
#' @param D a natural number smaller or equal to the Dimension generated by \code{basis}
#' @keywords internal
#' @return the squared projection estimator of the underlying density of \code{data}
est_dens_squared <- function(basis, data, D) {
  coef <- sapply(1:D, function(ind) {
    est_proj_coef(basis, data, ind)
  })
  f_d <- function(x) {
    build_sum <- vapply(
      1:D,
      function(ind) {
        basis$get_function(ind)(x) * coef[ind]
      },
      1
    )
    return(sum(build_sum)^2)
  }
  f_d <- Vectorize(f_d)
  return(f_d)
}
nschaefer1211/OSE documentation built on Dec. 31, 2020, 12:59 a.m.