R/predict.mrrr.R

Defines functions predict.mrrr

Documented in predict.mrrr

#'  The function predict.mrrr makes predictions for a test/validation set
#'  based on a fitted mrrr model
#'
#' @param object An \code{mrrr} object
#' @param newX An N by P matrix with predictor variables for a test/validation set
#' @param \dots additional arguments to be passed.
#'
#' @return This function returns an object of the class \code{p.mru} with components:
#' \item{Ghat}{Predicted values for the test set}
#'
#' @examples
#' \dontrun{
#' data(dataExample_lpca)
#' Y = as.matrix(dataExample_mru[-c(1:20) , 1:8])
#' X = as.matrix(dataExample_mru[-c(1:20) , 9:13])
#' newY = as.matrix(dataExample_mru[1:20 , 1:8])
#' newX = as.matrix(dataExample_mru[1:20 , 9:13])
#' output = mrrr(Y = Y, X = X, S = 2)
#' preds = predict(output, newX = newX)
#' }
#'
#'
#' @export

predict.mrrr = function(object, newX,...){
  X = scale(newX, center = object$mx, scale = object$sdx)
  ones.n = matrix(1, nrow(X), 1)
  theta = ones.n %*% t(object$m) + X %*% object$B %*% t(object$V)
  Ghat = exp(theta) / rowSums(exp(theta))
  return(Ghat)
}

Try the lmap package in your browser

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

lmap documentation built on April 3, 2025, 5:47 p.m.