#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)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.