pc-cormat: Utility functions for the PC prior for a correlation matrix

Description Usage Arguments Details Value Author(s) Examples

Description

Functions to evaluate and sample from the PC prior for a correlation matrix.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12

Arguments

dim

The dimension of theta, the parameterisatin of the correlation matrix

p

The dimension the correlation matrix

theta

A vector of parameters for the correlation matrix

r

The off diagonal elements of a correlation matrix

R

A correlation matrix

n

Number of observations

lambda

The rate parameter in the prior

log

Logical. Return the density in natural or log-scale.

Details

The parameterisation of a correlation matrix of dimension p has dim parameters: theta which are in the interval -pi to pi. The alternative parameterisation is through the off-diagonal elements r of the correlation matrix R. The functions inla.pc.cormat.<A>2<B> convert between parameterisations <A> to parameterisations <B>, where both <A> and <B> are one of theta, r and R, and p and dim.

Value

inla.pc.cormat.rtheta generate samples from the prior, returning a matrix where each row is a sample of theta. inla.pc.cormat.dtheta evaluates the density of theta. inla.pc.cormat.permute randomly permutes a correlation matrix, which is useful if an exchangable sample of a correlation matrix is required.

Author(s)

Havard Rue hrue@math.ntnu.no

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
  p = 4
  print(paste("theta has length", inla.pc.cormat.p2dim(p)))
  theta = inla.pc.cormat.rtheta(n=1, p=4, lambda = 1)
  print("sample theta:")
  print(theta)
  print(paste("log.dens", inla.pc.cormat.dtheta(theta, log=TRUE)))
  print("r:")
  r = inla.pc.cormat.theta2r(theta)
  print(r)
  print("A sample from the non-exchangable prior, R:")
  R = inla.pc.cormat.r2R(r)
  print(R)
  print("A sample from the exchangable prior, R:")
  R = inla.pc.cormat.permute(R)
  print(R)
 

andrewzm/INLA documentation built on May 10, 2019, 11:12 a.m.