R/Naive.R

Defines functions naive

Documented in naive

#' calculates the Naive estimator
#'
#' @param X  numeric matrix
#' @param Y  numeric vector
#'
#' @return double
#' @export

#'
#' @examples
#' X<-matrix(rnorm(15),3,5)
#' Y<-c(2, 4.2, 5.8)
#' naive(X,Y)

naive <- function(X, Y) {
  W = as.data.frame(X)*Y
  mean_squared_W <- colMeans(W^2)              #calculate first element of beta_square_hat
  var_W <- sapply(W,var)                       #calculate the second element of beta
  beta_square_hat <- mean_squared_W - var_W    #calculate vector of beta2_hat
  return(sum(beta_square_hat))

}
Ilanlivne/ZeroEst documentation built on April 6, 2021, 4:53 a.m.