pc-cormat.RdFunctions to evaluate and sample from the PC prior for a correlation matrix.
inla.pc.cormat.dim2p(dim)
inla.pc.cormat.p2dim(p)
inla.pc.cormat.theta2R(theta)
inla.pc.cormat.R2theta(R)
inla.pc.cormat.r2R(r)
inla.pc.cormat.R2r(R)
inla.pc.cormat.r2theta(r)
inla.pc.cormat.theta2r(theta)
inla.pc.cormat.permute(R)
inla.pc.cormat.rtheta(n=1, p, lambda = 1)
inla.pc.cormat.dtheta(theta, lambda = 1, log = FALSE)The dimension of theta, the parameterisatin of the correlation matrix
The dimension the correlation matrix
A vector of parameters for the correlation matrix
The off diagonal elements of a correlation matrix
A correlation matrix
Number of observations
The rate parameter in the prior
Logical. Return the density in natural or log-scale.
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.
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.
p = 4
print(paste("theta has length", inla.pc.cormat.p2dim(p)))
#> [1] "theta has length 6"
theta = inla.pc.cormat.rtheta(n=1, p=4, lambda = 1)
print("sample theta:")
#> [1] "sample theta:"
print(theta)
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] 1.216394 1.406149 1.812584 1.320684 1.925814 1.357068
print(paste("log.dens", inla.pc.cormat.dtheta(theta, log=TRUE)))
#> [1] "log.dens -0.292215007886715"
print("r:")
#> [1] "r:"
r = inla.pc.cormat.theta2r(theta)
print(r)
#> [1] 0.34703012 0.16390470 -0.23943903 0.28587113 -0.39961417 0.06290501
print("A sample from the non-exchangable prior, R:")
#> [1] "A sample from the non-exchangable prior, R:"
R = inla.pc.cormat.r2R(r)
print(R)
#> [,1] [,2] [,3] [,4]
#> [1,] 1.0000000 0.3470301 0.16390470 -0.23943903
#> [2,] 0.3470301 1.0000000 0.28587113 -0.39961417
#> [3,] 0.1639047 0.2858711 1.00000000 0.06290501
#> [4,] -0.2394390 -0.3996142 0.06290501 1.00000000
print("A sample from the exchangable prior, R:")
#> [1] "A sample from the exchangable prior, R:"
R = inla.pc.cormat.permute(R)
print(R)
#> [,1] [,2] [,3] [,4]
#> [1,] 1.00000000 -0.3996142 0.1639047 0.06290501
#> [2,] -0.39961417 1.0000000 0.2858711 0.34703012
#> [3,] 0.16390470 0.2858711 1.0000000 -0.23943903
#> [4,] 0.06290501 0.3470301 -0.2394390 1.00000000