R/lmFit.R

# extracted from CKAT.bin from CKAT package and adapted to suit package needs
#
# Debashis Ghosh and Xiang Zhan. "CKAT software" (2016)
# Available at: http://works.bepress.com/debashis_ghosh/75/
#
#' @importFrom stats model.matrix lm residuals
.lmFit <- function (y, X) {

  n <- length(x = y)
  
  if (ncol(X) > 0L) {
    X1 <- stats::model.matrix(~. , as.data.frame(X))
  } else {
    X1 <- matrix(1.0, nrow(X), ncol = 1L)
  }
  
  mod <- stats::lm(y ~ X1 - 1)
  res <- residuals(object = mod)
  s2 <- sum(res^2)

  P0  <- diag(x = n)  - X1 %*% solve(a = crossprod(x = X1), b = t(x = X1))
    
  return( list("P0" = P0, "res" = res, "s2" = s2) )

}

Try the POSTm package in your browser

Any scripts or data that you put into this service are public.

POSTm documentation built on May 29, 2024, 9:24 a.m.