Skip to content
Snippets Groups Projects
Commit d7bb8d4a authored by Walmes Marques Zeviani's avatar Walmes Marques Zeviani
Browse files

Add tags and tidy code/text.

parent 0372b503
No related branches found
No related tags found
No related merge requests found
#' Exponential-matrix covariance link function
#' @title Exponential-matrix covariance link function
#' @author Wagner Hugo Bonat
#'
#' @description Given a matrix \code{U} the function \code{mc_expm}
#'returns the exponential-matrix \eqn{expm(U)} and some auxiliares matrices to compute
#'its derivatives. This function is based on the eigen-value decomposition it means that it is
#'very slow.
#' returns the exponential-matrix \eqn{expm(U)} and some auxiliares
#' matrices to compute its derivatives. This function is based on
#' the eigen-value decomposition it means that it is very slow.
#'
#' @param U A matrix.
#'@param n A number specifing the dimension of the matrix U. Default \code{n = dim(U)[1]}.
#'@param sparse Logical defining the class of the output matrix. If \code{sparse = TRUE} the output
#'class will be 'dgCMatrix' if \code{sparse = FALSE} the class will be 'dgMatrix'.
#'@param inverse Logical defining if the inverse will be computed or not.
#'@return A list with \eqn{\Omega = expm(U)} its inverse (if \code{inverse = TRUE}) and
#' auxiliares matrices to compute the derivatives.
#' @param n A number specifing the dimension of the matrix U. Default
#' \code{n = dim(U)[1]}.
#' @param sparse Logical defining the class of the output matrix. If
#' \code{sparse = TRUE} the output class will be 'dgCMatrix' if
#' \code{sparse = FALSE} the class will be 'dgMatrix'.
#' @param inverse Logical defining if the inverse will be computed or
#' not.
#' @return A list with \eqn{\Omega = expm(U)} its inverse (if
#' \code{inverse = TRUE}) and auxiliares matrices to compute the
#' derivatives.
#'
#' @seealso \code{\link[Matrix]{expm}}, \code{\link[base]{eigen}},
#' \code{link[mcglm]{mc_dexp_gold}}.
mc_expm <- function(U, n = dim(U)[1], sparse = FALSE, inverse = FALSE) {
tt = eigen(U, symmetric = TRUE)
UU = tt$vectors
Q = tt$values
eQr = Diagonal(n, exp(tt$values))
tt <- eigen(U, symmetric = TRUE)
UU <- tt$vectors
Q <- tt$values
eQr <- Diagonal(n, exp(tt$values))
inv_UU <- t(UU)
Omega = Matrix(UU %*% eQr %*% inv_UU, sparse = sparse)
Omega <- Matrix(UU %*% eQr %*% inv_UU, sparse = sparse)
if (inverse == TRUE) {
eQr_INV = Diagonal(n, exp(-tt$values))
eQr_INV <- Diagonal(n, exp(-tt$values))
inv_Omega <- Matrix(UU %*% eQr_INV %*% inv_UU, sparse = sparse)
saida <- list(Omega = Omega, inv_Omega = inv_Omega, UU = UU, Q = Q, inv_UU = inv_UU)
saida <- list(Omega = Omega, inv_Omega = inv_Omega, UU = UU,
Q = Q, inv_UU = inv_UU)
}
if (inverse == FALSE) {
saida <- list(Omega = Omega, UU = UU, Q = Q, inv_UU = inv_UU)
......
#' Getting information about model parameters
#' @title Getting information about model parameters
#' @author Wagner Hugo Bonat
#'
#' @description This computes all information required about the number of model parameters.
#' @description This computes all information required about the number
#' of model parameters.
#'
#' @param list_initial A list of initial values.
#' @param list_power_fixed A list of logical specyfing if the power parameters should be estimated or not.
#' @param list_power_fixed A list of logical specyfing if the power
#' parameters should be estimated or not.
#' @param n_resp A number specyfing the nmber of response variables.
#' @return The number of \eqn{\beta}'s, \eqn{\tau}'s, power and correlation parameters.
#' @return The number of \eqn{\beta}'s, \eqn{\tau}'s, power and
#' correlation parameters.
mc_getInformation <- function(list_initial, list_power_fixed, n_resp) {
mc_getInformation <- function(list_initial, list_power_fixed,
n_resp) {
n_betas <- lapply(list_initial$regression, length)
n_taus <- lapply(list_initial$tau, length)
n_power <- lapply(list_initial$power, length)
for (i in 1:n_resp) {
if (list_power_fixed[[i]] == TRUE) {
n_power[i] = 0
n_power[i] <- 0
}
}
if (n_resp == 1) {
......@@ -22,7 +27,9 @@ mc_getInformation <- function(list_initial, list_power_fixed, n_resp) {
if (n_resp != 1) {
n_rho <- length(list_initial$rho)
}
n_cov <- sum(do.call(c, n_power)) + n_rho + sum(do.call(c, n_taus))
saida <- list(n_betas = n_betas, n_taus = n_taus, n_power = n_power, n_rho = n_rho, n_cov = n_cov)
n_cov <- sum(do.call(c, n_power)) + n_rho +
sum(do.call(c, n_taus))
saida <- list(n_betas = n_betas, n_taus = n_taus, n_power = n_power,
n_rho = n_rho, n_cov = n_cov)
return(saida)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment