R/myl.R

Defines functions myl

Documented in myl

#' myl
#'
#' @param Y The response vector
#' @param X The design matrix
#' @param alpha The level of significance
#' @param a The particular values of x1,x2,...,etc.
#' @param l The value of E(y) for the particular choice of x1,x2,...,etc.
#'
#' @return The confidence interval for the data point represented in a
#' @export
#'
#' @examples
myl = function(Y,X,alpha,a,l){
  n = dim(X)[1]
  kplus1 = dim(X)[2]
  df = n-(kplus1)

  XXinv = solve(t(X)%*%X)
  betahat = (XXinv%*%t(X))%*%Y
  yhat = X%*%betahat
  sse  = t(Y)%*%Y -t(betahat)%*%t(X)%*%Y

  s2 = sse/df
  s=sqrt(s2)

  pairs(X[,2:kplus1], pch = 19)

  ci_lower = l - qt(1-alpha/2,df)*s*sqrt(t(a)%*%XXinv%*%a)
  ci_upper = l + qt(1-alpha/2,df)*s*sqrt(t(a)%*%XXinv%*%a)
  ci = c(ci_lower,ci_upper)
  ci
}
reza-niazi/MLRpack documentation built on Oct. 16, 2020, 7:30 a.m.