Sample a covariance Matrix from the Posterior Inverse Wishart distribution.
Note this Inverse wishart rescaled to match the original scale of the covariance matrix.
cvPost( nu, omega, n = 1L, omegaIsChol = FALSE, returnChol = FALSE, type = c("invWishart", "lkj", "separation"), diagXformType = c("log", "identity", "variance", "nlmixrSqrt", "nlmixrLog", "nlmixrIdentity") )
nu |
Degrees of Freedom (Number of Observations) for covariance matrix simulation. |
omega |
Either the estimate of covariance matrix or the estimated standard deviations in matrix form each row forming the standard deviation simulated values |
n |
Number of Matrices to sample. By default this is 1.
This is only useful when |
omegaIsChol |
is an indicator of if the omega matrix is in the Cholesky decomposition. This is only used when codetype="invWishart" |
returnChol |
Return the Cholesky decomposition of the covariance matrix sample. This is only used when codetype="invWishart" |
type |
The type of covariance posterior that is being simulated. This can be:
|
diagXformType |
Diagonal transformation type. These could be:
The nlmixr transformations only make sense when there is no off-diagonal correlations modeled. |
If your covariance matrix is a 1x1 matrix, this uses an scaled inverse chi-squared which is equivalent to the Inverse Wishart distribution in the uni-directional case.
In general, the separation strategy is preferred for diagonal
matrices. If the dimension of the matrix is below 10, lkj
is numerically faster than separation
method. However, the
lkj
method has densities too close to zero (XXXX) when the
dimension is above 10. In that case, though computationally more
expensive separation
method performs better.
For matrices with modeled covariances, the easiest method to use is the inverse Wishart which allows the simulation of correlation matrices (XXXX). This method is more well suited for well behaved matrices, that is the variance components are not too low or too high. When modeling nonlinear mixed effects modeling matrices with too high or low variances are considered sub-optimal in describing a system. With these rules in mind, it is reasonable to use the inverse Wishart.
a matrix (n=1) or a list of matrices (n > 1)
Matthew L.Fidler & Wenping Wang
Alvarez I, Niemi J and Simpson M. (2014) Bayesian Inference for a Covariance Matrix. Conference on Applied Statistics in Agriculture. https://newprairiepress.org/cgi/viewcontent.cgi?article=1004&context=agstatconference
Wang1 Z, Wu Y, and Chu H. (2018) On Equivalence of the LKJ distribution and the restricted Wishart distribution. arXiv:1809.04746
## Sample a single covariance. draw1 <- cvPost(3, matrix(c(1,.3,.3,1),2,2)) ## Sample 3 covariances set.seed(42) draw3 <- cvPost(3, matrix(c(1,.3,.3,1),2,2), n=3) ## Sample 3 covariances, but return the cholesky decomposition set.seed(42) draw3c <- cvPost(3, matrix(c(1,.3,.3,1),2,2), n=3, returnChol=TRUE) ## Sample 3 covariances with lognormal standard deviations via LKJ ## correlation sample cvPost(3,sapply(1:3,function(...){rnorm(10)}), type="lkj") ## or return cholesky decomposition cvPost(3,sapply(1:3,function(...){rnorm(10)}), type="lkj", returnChol=TRUE) ## Sample 3 covariances with lognormal standard deviations via separation ## strategy using inverse Wishart correlation sample cvPost(3,sapply(1:3,function(...){rnorm(10)}), type="separation") ## or returning the cholesky decomposition cvPost(3,sapply(1:3,function(...){rnorm(10)}), type="separation", returnChol=TRUE)
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.