R/utils.R

Defines functions CorrCS CorrAR mstack lnorm

## lnorm
lnorm <- function(a, p = 1)
{
  (sum(abs(a) ^ p)) ^ (1. / p)
}

## Vectorization a matrix by row
mstack <- function(S)
{
  as.vector(t(S))
}


## Autoregressive covariance structure
CorrAR <- function(p, rho)
{
  Sigma <- matrix(nrow = p, ncol = p, NA)
  for (i in seq_len(p)) {
    for (j in seq_len(p)) {
      Sigma[i,j] <- rho ^ (abs(i - j))
    }
  }
  Sigma
}


CorrCS <- function(p, rho)
{
  Sigma <- matrix(nrow = p, ncol = p, rho)
  diag(Sigma) <- 1
  Sigma
}

Try the rrpack package in your browser

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

rrpack documentation built on Jan. 20, 2018, 9:20 a.m.