R/RandomEffects.R
rRxNorm.Rd
Sample from the conditional parameter distribution given the data and hyperparameters of the Multivariate-Normal Random-Effects (mNormRE) model (see Details).
rRxNorm(n, x, V, lambda, Sigma)
Integer number of random samples to generate.
Data observations. Either a vector of length q
or a n x q
matrix. In the latter case each row is a different vector.
Observation variances. Either a matrix of size q x q
or a q x q x n
array.
Prior means. Either a vector of length q
or an n x q
matrix. In the latter case each row is a different mean. Defaults to zeros.
Prior variances. Either a matrix of size q x q
or a q x q x n
array. Defaults to identity matrix.
Consider the hierarchical multivariate normal model
$$
\begin{array}{rcl}
\boldsymbol{\mu} & \sim & \mathcal{N}(\boldsymbol{\lambda}, \boldsymbol{\Sigma}) \\
\boldsymbol{x} \mid \boldsymbol{\mu} & \sim & \mathcal{N}(\boldsymbol{\mu}, \boldsymbol{V}).
\end{array}
$$
The Multivariate-Normal Random-Effects model \(\boldsymbol{\mu} \sim \textrm{RxNorm}(\boldsymbol{x}, \boldsymbol{V}, \boldsymbol{\lambda}, \boldsymbol{\Sigma})\) on the random vector \(\boldsymbol{\mu}_q\) is defined as the posterior distribution \(p(\boldsymbol{\mu} \mid \boldsymbol{x}, \boldsymbol{\lambda}, \boldsymbol{\Sigma})\). This distribution is multivariate normal; for the mathematical specification of its parameters please see vignette("mniw-distributions", package = "mniw")
.
# data specification
q <- 5
y <- rnorm(q)
V <- rwish(1, diag(q), q+1)
# prior specification
lambda <- rep(0,q)
A <- diag(q)
n <- 10
# random sampling
rRxNorm(n, y, V, lambda, A)
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] -0.3210119 0.25012776 -1.0832082 0.1766702 1.0026878
#> [2,] -0.8477048 -0.06033919 0.7138509 -0.2359336 1.1328197
#> [3,] -0.4833820 -0.37569205 -0.4355352 1.7421929 0.4572355
#> [4,] -1.8244862 -0.36354547 -0.4464338 0.2354824 1.4738239
#> [5,] -0.5469371 0.59287225 -0.4616895 1.9233230 1.5036275
#> [6,] -0.6298590 0.74612003 0.1798659 0.3189405 1.3068775
#> [7,] -1.3084676 -0.22138653 -0.7239478 1.7016159 -0.1686089
#> [8,] 0.3120142 0.07852389 -1.2650215 2.1253076 0.9593281
#> [9,] 0.3511071 0.02076032 -0.1073949 0.5507978 0.9456339
#> [10,] -1.6875222 1.21051823 -1.1897823 1.5921019 0.6289171