R/internal.intercor.all.R

##########################################################################################################
#
# miscor: Miscellaneous Functions for the Correlation Coefficient
#
# Internal function: intercor.all
#
# Function copied from the PoisNonNor package <cran.r-project.org/web/packages/PoisNonNor>
internal.intercor.all <- function (cmat, pmat = NULL, lamvec = NULL) {

  n1 <- ifelse(is.null(lamvec), 0, length(lamvec))
  n2 <- ifelse(is.null(pmat), 0, dim(pmat)[1])

  if ((n1 + n2) != dim(cmat)[1]) {
    stop("Correlation matrix dimension is not consistent with number of variables!\n")
  }

  if ((!is.null(lamvec)) & (sum(lamvec > 0) < n1)) {
    stop("Specified lambda should be positive \n")
  }

  if ((!is.null(pmat)) & (dim(pmat)[2] != 4)) {
    stop("column of pmat must be 4\n")
  }

  cmat_N_N <- diag(1, (n1 + n2))
  if (n1 != 0) {
    cmat_PP <- cmat[1:n1, 1:n1]
    cmat_N_N[1:n1, 1:n1] <- internal.intercor.PP(lamvec, cmat_PP)
  }

  if (n2 != 0) {
    cmat_NN <- cmat[(n1 + 1):(n1 + n2), (n1 + 1):(n1 + n2)]
    cmat_N_N[(n1 + 1):(n1 + n2), (n1 + 1):(n1 + n2)] <- internal.intercor.NN(pmat, cmat_NN)
  }

  if (n1 != 0 & n2 != 0) {
    cmat_NNP <- cmat[1:n1, (n1 + 1):(n1 + n2)]
    cmat_N_N[1:n1, (n1 + 1):(n1 + n2)] <- internal.intercor.NNP(lamvec, cmat_NNP, pmat)
    cmat_N_N[(n1 + 1):(n1 + n2), 1:n1] <- t(cmat_N_N[1:n1, (n1 + 1):(n1 + n2)])
  }
  return(cmat_N_N)
}

Try the miscor package in your browser

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

miscor documentation built on May 1, 2019, 10:14 p.m.