R/weighted.pred.env.R

Defines functions weighted.pred.env

Documented in weighted.pred.env

weighted.pred.env <- function(X, Y, Xnew) {
  
  X <- as.matrix(X)
  a <- dim(Y)
  n <- a[1]
  r <- a[2]
  p <- ncol(X)
  
  Xnew <- as.matrix(Xnew)
  if (nrow(Xnew) == 1) Xnew <- t(Xnew)
  A <- qr.Q(qr(Xnew), complete = TRUE)
  Ainv <- solve(A)
  Z <- tcrossprod(X, Ainv)
  X1 <- Z[, 1]
  X2 <- Z[, 2:p]
  
  fit <- weighted.penv(X1, X2, Y)
  X1new <- Ainv[1, ] %*% Xnew
  X2new <- Ainv[2:p, ] %*% Xnew
  value <- fit$mu + fit$beta1 %*% X1new + fit$beta2 %*% X2new

  return(value)
  
}

Try the Renvlp package in your browser

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

Renvlp documentation built on Sept. 11, 2021, 9:07 a.m.