#' @title One dimensional projection estimator
#'
#' @description Given a sample of i.i.d. real random variables with common density, and a basis of class \code{\link{Basis}}
#' this function calculates the projection estimator of this density.
#' @param basis an object of class \code{\link{Basis}}
#' @param data a numeric vector containing a sample of i.i.d. real random variables with common density
#' @param D a natural number smaller or equal to the dimension of the vector space generated by \code{basis}
#' @export
#' @keywords
#' @seealso
#' @return The projection estimator of the density of \code{data} given \code{basis}
#' @aliases
#' @examples
#' # example with the trigonometric basis
#' d <- 100
#' trig_bas <- Trig_Basis$new(d)
#' data <- runif(100)
#' estimated_density <- est_dens(trig_bas, data, 10)
#' estimated_density
est_dens <- function(basis, data, D) {
stopifnot(is.numeric(D))
stopifnot(D <= basis$.dimension)
stopifnot(D > 0)
stopifnot(length(D) == 1)
stopifnot(isTRUE(all.equal(D, as.integer(D))))
stopifnot(any(class(basis) %in% "Basis"))
stopifnot(is.numeric(data))
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))
}
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.