rnorm_qinv_l_eigen: Sample from multivariate normal distribution given symmetric...

Description Usage Arguments Details Value Examples

View source: R/rnorm_qinv_l_eigen.R

Description

Sample from multivariate normal distribution with mean Q^{-1}l and covariance matrix Q^{-1} where Q = UDU^t

Usage

1
2
3
4
5
rnorm_qinv_l_eigen <- function(
  n,
  U,
  d,
  l)

Arguments

n

number of elements to generate

U

orthogonal matrix such that Q = UDU^t

d

p by 1 vector, D = diag(d) and Q = UDU^t

l

p by 1 vector

Details

This function is useful to sample from N((Q + sI)^{-1}l, (Q + sI)^{-1}) given the eigen decomposition of Q

Value

x

An p x 1 vector if n=1 otherwise a n by p matrix

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
  W = cbind(c(10,1), c(1,10))
  ee = eigen(W, symmetric = TRUE)
  U = ee$vectors
  d = ee$values
  crossprod(U)

  solve(W)
  U 

  l = c(50,100)
  m = U 
  ret = rnorm_qinv_l_eigen(50000, U, d, l)
  mean(ret[,1] - m[1])
  mean(ret[,2] - m[2])
  sum(cov(ret) - (U 

dcbdan/s525 documentation built on May 19, 2019, 10:48 p.m.