Correlated random effects: iid1d, iid2d, iid3d, iid4d and iid5d
This model is available for dimensions p = 1, 2, 3, 4 and 5. We describe in detail the case for p = 2,and then the changes required for p = 1, p = 3, p = 4 and p = 5

Parametrization
The 2-dimensional Normal-Wishard model is used if one want to define two vectors of “randomeffects”, u and v, say, for which (ui , vi ) are iid bivariate Normalsuivi!

where the covariance matrix W−1 is∼ N 0, W−1!
√1/τaρ/ τa τb√
ρ/ τa τb1/τbW−1 =(1)and τa , τb and ρ are the hyperparameters.
Note that ρ is the correlation coefficient, and that τa and τb are the marginal precisions, not theelements in the precision matrix.
For these models the precision matrix W is Wishart distributed
W ∼ Wishartp (r, R−1 ),with density

p=21π(W) = c−1 |W|(r−(p+1))/2 exp − Trace(WR) ,2and(rp)/2

c=2|R|−r/2 (p(p−1))/4πpY

j=1Then,E(W) = rR−1 ,andr >p+1Γ((r + 1 − j)/2).

E(W−1 ) = R/(r − (p + 1)).

Hyperparameters
The hyperparameters areθ = (log τa , log τb , ρ̃)
whereρ=2exp(ρ̃)−1exp(ρ̃) + 1

The prior-parameters are(r, R11 , R22 , R12 )where
R=R11 R12
R21 R22!

and r12 = R21 due to symmetry.
The inla function reports posterior distribution for the hyperparameters τa , τb , ρ in equation (1).
The prior for θ is fixed to be wishart2d1

Specification
The model iid2d is specified asy ~ f(i, model="iid2d",n = <length>) + ...
and the iid2d model is represented internally as one vector of length n,(u1 , u2 , . . . , um , v1 , v2 , . . . , vm )where n = 2m, and n is the (required) argument in f().
For this model the argument constr=TRUE is interpreted asXui = 0,andX

vi = 0.

Hyperparameter spesification and default values
doc Gaussian random effect in dim=2 with Wishart priorhyper
theta1
hyperid 26001
name log precision1
short.name prec1
initial 4
fixed FALSE
prior wishart2d
param 4 1 1 0to.theta function(x) log(x)from.theta function(x) exp(x)theta2
hyperid 26002
name log precision2
short.name prec2
initial 4
fixed FALSE
prior none
param
to.theta function(x) log(x)from.theta function(x) exp(x)theta3
hyperid 26003
name logit correlation
short.name cor
initial 4
fixed FALSE
2

prior none
param
to.theta function(x) log((1 + x) / (1 - x))from.theta function(x) 2 * exp(x) / (1 + exp(x)) - 1
constr FALSE
nrow.ncol FALSE
augmented TRUE
aug.factor 1
aug.constr 1 2
n.div.by 2
n.required TRUEset.default.values TRUE
pdf iid123dExampleIn these examples we demonstrate the use of the iid2d-model, with observations that are without
noise (essentially).
n = 1000
N = 2*n## need it to simulate datalibrary(mvtnorm)
if (TRUE){## first example - each variable in the correlated pair has its own row in data
#Using fixed covariance matrix
rho = 0.5## set variances
Sigma = matrix(c(1/1, NA, NA, 1/2), 2, 2)## and the correlation
Sigma[1,2] = Sigma[2,1] = rho*sqrt(Sigma[1,1]*Sigma[2,2])y = yy = rmvnorm(n, sigma=Sigma)
y = c(y[,1], y[,2])i = 1:N
formula = y ~ f(i, model="iid2d", n=N)r = inla(formula, data = data.frame(i,y),control.family=list(initial=10,fixed=TRUE))
3

print(summary(r))
print(1/diag(cov(yy)))print(cor(yy)[1,2])}
if (TRUE){## second example - both correlated variables occur in the same row of data
#drawing covariance matrix from hyperprior#Let’s specify non-default values, expecting strong covariancer = 4
R11 = 5
R22 = 4
R12 = 3R = matrix(c(R11,R12,R12,R22), 2, 2)#Take a single sample from wishart_2(r,R^-1)
W = rWishart(1,r,solve(R))[,,1]Sigma = solve(W) #Compute the covariance matrix

y = yy = rmvnorm(n, sigma=Sigma)z = rnorm(n)zz = rnorm(n)y = y[,1] + z*y[,2] + zz
i = 1:n
j = n + 1:n
formula = y ~ f(i, model="iid2d", n=N) + f(j,z,copy="i") + zz
r = inla(formula, data = data.frame(i,j,y,z,zz),
control.family=list(initial=10,fixed=TRUE),keep=T)
print(summary(r))#The params as in the Sigma matrix
print(1/diag(Sigma))
print(cov2cor(Sigma)[1,2])#The params as seen in data
print(1/diag(cov(yy)))print(cor(yy)[1,2])}

The case p = 1
For p = 1 the hyperparameter is the marginal precisionθ = log τ1The prior is fixed to be wishart1d with parameters4param = r R11
where
R=hR11i

Hyperparameter spesification and default values
doc Gaussian random effect in dim=1 with Wishart priorhyperthetahyperid 25001
name precision
short.name prec
initial 4
fixed FALSE
prior wishart1d
param 2 1e-04
to.theta function(x) log(x)from.theta function(x) exp(x)constr FALSE
nrow.ncol FALSE
augmented FALSE
aug.factor 1
aug.constr
n.div.byn.required FALSE
set.default.values TRUE
pdf iid123d

The case p = 3
For p = 3 the hyperparameters areθ = (log τ1 , log τ2 , log τ3 , ρ̃12 , ρ̃13 , ρ̃23 )The prior is fixed to be wishart3d with parametersparam = r R11 R22 R33 R12 R13 R235

whereR11 R12 R13
R =  R12 R22 R23 
R13 R23 R33

The reported hyperparameters are the marginal precisions τ1 , τ2 and τ3 and the correlations ρ12 , ρ13
and ρ23 .
In this case, the internal representation is given as(u1 , u2 , . . . , um , v1 , v2 , . . . , vm , w1 , w2 , . . . , wm )where n = 3m is a required argument, and where (ui , vi , wi ) are trivariate iid Normal.
Hyperparameter spesification and default values
doc Gaussian random effect in dim=3 with Wishart priorhyper
theta1
hyperid 27001
name log precision1
short.name prec1
initial 4
fixed FALSE
prior wishart3d
param 7 1 1 1 0 0 0
to.theta function(x) log(x)from.theta function(x) exp(x)theta2
hyperid 27002
name log precision2
short.name prec2
initial 4
fixed FALSE
prior none
param
to.theta function(x) log(x)from.theta function(x) exp(x)theta3
hyperid 27003
name log precision3
short.name prec3
initial 4
fixed FALSE
prior noneparam
6

to.theta function(x) log(x)from.theta function(x) exp(x)theta4
hyperid 27004name logit correlation12
short.name cor12
initial 0
fixed FALSE
prior none
param
to.theta function(x) log((1 + x) / (1 - x))from.theta function(x) 2 * exp(x) / (1 + exp(x)) - 1
theta5
hyperid 27005
name logit correlation13
short.name cor13
initial 0
fixed FALSE
prior none
param
to.theta function(x) log((1 + x) / (1 - x))from.theta function(x) 2 * exp(x) / (1 + exp(x)) - 1
theta6
hyperid 27006
name logit correlation23
short.name cor23
initial 0
fixed FALSE
prior none
param
to.theta function(x) log((1 + x) / (1 - x))from.theta function(x) 2 * exp(x) / (1 + exp(x)) - 1
constr FALSE
nrow.ncol FALSE
augmented TRUE
aug.factor 1
aug.constr 1 2 3
n.div.by 3
n.required TRUE
set.default.values TRUE
pdf iid123d7

The case p = 4
For p = 4 the hyperparameters areθ = (log τ1 , log τ2 , log τ3 , log τ4 , ρ̃12 , ρ̃13 , ρ̃14 , ρ̃23 , ρ̃24 , ρ̃34 )The prior is fixed to be wishart4d with parametersparam = r R11 R22 R33 R44 R12 R13 R14 R23 R24 R34
whereR11 RR =  12
 R13R14R12R22R23
R24R13R23R33
R34



R14R24 
R34 R44

The reported hyperparameters are the marginal precisions τ1 , τ2 , τ3 and τ4 , and the correlations ρ12 ,ρ13 , ρ14 , ρ23 , ρ24 and ρ34 .
In this case, the internal representation is given as(u1 , u2 , . . . , um , v1 , v2 , . . . , vm , w1 , w2 , . . . , wm , x1 , x2 , . . . , xm )where n = 4m is a required argument, and where (ui , vi , wi , xi ) are fourvariate iid Normal.
Hyperparameter spesification and default values
doc Gaussian random effect in dim=4 with Wishart priorhyper
theta1
hyperid 28001
name log precision1
short.name prec1
initial 4
fixed FALSE
prior wishart4d
param 11 1 1 1 1 0 0 0 0 0 0
to.theta function(x) log(x)from.theta function(x) exp(x)theta2
hyperid 28002
name log precision2
short.name prec2
initial 4
fixed FALSE
prior none
param
to.theta function(x) log(x)8from.theta function(x) exp(x)theta3hyperid 28003
name log precision3
short.name prec3
initial 4
fixed FALSE
prior none
param
to.theta function(x) log(x)from.theta function(x) exp(x)theta4
hyperid 28004
name log precision4
short.name prec4
initial 4
fixed FALSE
prior none
param
to.theta function(x) log(x)from.theta function(x) exp(x)theta5
hyperid 28005
name logit correlation12
short.name cor12
initial 0
fixed FALSE
prior none
param
to.theta function(x) log((1 + x) / (1 - x))from.theta function(x) 2 * exp(x) / (1 + exp(x)) - 1
theta6
hyperid 28006
name logit correlation13
short.name cor13
initial 0
fixed FALSE
prior none
param
to.theta function(x) log((1 + x) / (1 - x))from.theta function(x) 2 * exp(x) / (1 + exp(x)) - 1
theta7
hyperid 28007
name logit correlation14
9

short.name cor14
initial 0
fixed FALSE
prior none
param
to.theta function(x) log((1 + x) / (1 - x))from.theta function(x) 2 * exp(x) / (1 + exp(x)) - 1
theta8hyperid 28008
name logit correlation23
short.name cor23
initial 0
fixed FALSE
prior none
paramto.theta function(x) log((1 + x) / (1 - x))from.theta function(x) 2 * exp(x) / (1 + exp(x)) - 1
theta9hyperid 28009
name logit correlation24
short.name cor24
initial 0
fixed FALSE
prior none
param
to.theta function(x) log((1 + x) / (1 - x))from.theta function(x) 2 * exp(x) / (1 + exp(x)) - 1
theta10hyperid 28010
name logit correlation34
short.name cor34
initial 0
fixed FALSE
prior none
param
to.theta function(x) log((1 + x) / (1 - x))from.theta function(x) 2 * exp(x) / (1 + exp(x)) - 1
constr FALSE
nrow.ncol FALSE
augmented TRUE
aug.factor 1
aug.constr 1 2 3 410n.div.by 4
n.required TRUE
set.default.values TRUE
pdf iid123d

The case p = 5
The case p = 5 follows by a direct extention of p = 3 and p = 4, and is therefore not included.
Hyperparameter spesification and default values
doc Gaussian random effect in dim=5 with Wishart priorhyper
theta1
hyperid 29001
name log precision1
short.name prec1
initial 4
fixed FALSE
prior wishart5d
param 16 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0
to.theta function(x) log(x)from.theta function(x) exp(x)theta2
hyperid 29002
name log precision2
short.name prec2
initial 4
fixed FALSE
prior none
param
to.theta function(x) log(x)from.theta function(x) exp(x)theta3
hyperid 29003
name log precision3
short.name prec3
initial 4
fixed FALSE
prior none
param
to.theta function(x) log(x)11from.theta function(x) exp(x)theta4
hyperid 29004
name log precision4
short.name prec4
initial 4
fixed FALSE
prior none
param
to.theta function(x) log(x)from.theta function(x) exp(x)theta5
hyperid 29005
name log precision5
short.name prec5
initial 4
fixed FALSE
prior none
param
to.theta function(x) log(x)from.theta function(x) exp(x)theta6
hyperid 29006
name logit correlation12
short.name cor12
initial 0
fixed FALSE
prior none
param
to.theta function(x) log((1 + x) / (1 - x))from.theta function(x) 2 * exp(x) / (1 + exp(x)) - 1
theta7
hyperid 29007
name logit correlation13
short.name cor13
initial 0
fixed FALSE
prior none
param
to.theta function(x) log((1 + x) / (1 - x))from.theta function(x) 2 * exp(x) / (1 + exp(x)) - 1
theta8hyperid 29008
name logit correlation14
12

short.name cor14
initial 0
fixed FALSE
prior none
param
to.theta function(x) log((1 + x) / (1 - x))from.theta function(x) 2 * exp(x) / (1 + exp(x)) - 1
theta9hyperid 29009
name logit correlation15
short.name cor15
initial 0
fixed FALSE
prior none
param
to.theta function(x) log((1 + x) / (1 - x))from.theta function(x) 2 * exp(x) / (1 + exp(x)) - 1
theta10hyperid 29010
name logit correlation23
short.name cor23
initial 0
fixed FALSE
prior none
param
to.theta function(x) log((1 + x) / (1 - x))from.theta function(x) 2 * exp(x) / (1 + exp(x)) - 1
theta11
hyperid 29011
name logit correlation24
short.name cor24
initial 0
fixed FALSE
prior none
param
to.theta function(x) log((1 + x) / (1 - x))from.theta function(x) 2 * exp(x) / (1 + exp(x)) - 1
theta12hyperid 29012
name logit correlation25
short.name cor25
initial 0
fixed FALSE
prior none13

paramto.theta function(x) log((1 + x) / (1 - x))from.theta function(x) 2 * exp(x) / (1 + exp(x)) - 1
theta13
hyperid 29013
name logit correlation34
short.name cor34
initial 0
fixed FALSE
prior none
param
to.theta function(x) log((1 + x) / (1 - x))from.theta function(x) 2 * exp(x) / (1 + exp(x)) - 1
theta14hyperid 29014
name logit correlation35
short.name cor35
initial 0
fixed FALSE
prior none
param
to.theta function(x) log((1 + x) / (1 - x))from.theta function(x) 2 * exp(x) / (1 + exp(x)) - 1
theta15
hyperid 29015
name logit correlation45
short.name cor45
initial 0
fixed FALSE
prior noneparamto.theta function(x) log((1 + x) / (1 - x))from.theta function(x) 2 * exp(x) / (1 + exp(x)) - 1
constr FALSE
nrow.ncol FALSE
augmented TRUE
aug.factor 1
aug.constr 1 2 3 4 5
n.div.by 5
n.required TRUE
set.default.values TRUE
pdf iid123d14

NotesThe model iid1d is similar to the model iid (and included for completeness only). The prior for
iid1d is fixed to be Wishart-distributed, which reduces to a Gamma-distribution for the precision
with parameters
a = r/2
andb = R11 /2
hence
y ~ f(i, model="iid1d", hyper = list(theta=list(param=c(3, 4))))is equivalent toy ~ f(i, model="iid", hyper = list(theta=list(param=c(1.5, 2), prior="loggamma")))15