Topic: Utilities

Topic Description:

Basic R utilities used in many packages and functions, such as date and string manipulations, statistical distributions, geometry of lines and distances. The R package date is required for the two data functions.



File: utilities/distributions.r

View File Source Download File No help file available

Function: mvrnormRC

Function Description: mvrnormRC

Function that takes a variance-covariance matrix and produces normal variates following it, but with means 0. The R function mvrnorm does this too; this was a test of the algorithm from Tommaso Zillio. Sigma must be square. N is the number to draw.

Function Arguments:

ArgumentDefault Value
N
Sigma

Function Source:

mvrnormRC=function(N,Sigma)
{
dimension=dim(Sigma)[1]
SVD=svd(Sigma)
M = SVD$u %*% diag(sqrt(SVD$d))

norm=x=matrix(nrow=N,ncol=dimension)

for(i in 1:N) norm[i,]=rnorm(dimension)
for(i in 1:N) x[i,] = t(M %*% norm[i,])

return(x)
}