R/mt_matrix_linear_predictor.R

Defines functions mt_matrix_linear_predictor

Documented in mt_matrix_linear_predictor

#' @title Matrix Linear Predictor
#' @author Wagner Hugo Bonat, \email{wbonat@@ufpr.br}
#'
#' @description Compute the matrix linear predictor. It is an internal
#' function, however, since the concept of matrix linear predictor
#' was proposed recently. I decided let this function visible to the
#' interested reader gets some feeling about how it works.
#'
#' @param tau a numeric vector of dispersion parameters.
#' @param Z a list of known matrices.
#'
#' @return A matrix.
#'
#' @export
#' @import Matrix
#'
#' @details Given a list with a set of known matrices
#'     (\eqn{Z_0,...,Z_D}) the function \cr
#'     \code{mt_matrix_linear_predictor} returns \eqn{U = \tau_0 Z_0 +
#'     ... + \tau_D Z_D}.
#'
#'
#' @source Bonat, W. H. (2018). Multiple Response Variables Regression
#' Models in R: The mcglm Package. Journal of Statistical Software, 84(4):1--30.
#'
#' @source Bonat, W. H. and Jorgensen, B. (2016) Multivariate
#'     covariance generalized linear models.
#'     Journal of Royal Statistical Society - Series C 65:649--675.
#'
#' @examples
#' require(Matrix)
#' Z0 <- Diagonal(5, 1)
#' Z1 <- Matrix(rep(1,5)%*%t(rep(1,5)))
#' Z <- list(Z0, Z1)
#' mt_matrix_linear_predictor(tau = c(1,0.8), Z = Z)

# Matrix linear predictor ----------------------------------------------
mt_matrix_linear_predictor <- function(tau, Z) {
    if (length(Z) != length(tau)) {
        stop("Incorrect number of parameters")
    }
    output <- mapply("*", Z, tau, SIMPLIFY = FALSE)
    output <- Reduce("+", output)
    return(output)
}
wbonat/mglm4twin documentation built on Oct. 14, 2023, 9:37 p.m.