Integrate over Multivariate Normal Random Effects
Source:R/RcppExports.R
, R/rimplementation.R
integratemvn.Rd
Used in the process of Monte Carlo integration over multivariate normal random effects. This generates the random draws from the multivariate normal distribution and multiplies these by the data. Not intended to be called directly by most users.
Arguments
- X
A numeric matrix of the data to be multiplied by the random effects
- k
An integer, the number of random samples to be used for numerical integration
- sd
A numeric vector of the standard deviations
- chol
A numeric matrix, which should be the Cholesky decomposition of the correlation matrix of the multivariate normal distribution.
Examples
integratemvn(
X = matrix(1, 1, 2),
k = 100L,
sd = c(10, 5),
chol = chol(matrix(c(1, .5, .5, 1), 2)))
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7]
#> [1,] -14.86666 -25.55203 4.631492 26.06817 -20.06263 5.665929 -22.75901
#> [,8] [,9] [,10] [,11] [,12] [,13] [,14]
#> [1,] -0.5884317 -11.84926 -18.27126 -3.710103 5.120226 -27.80911 -9.845854
#> [,15] [,16] [,17] [,18] [,19] [,20] [,21] [,22]
#> [1,] 29.08115 -10.01901 24.16488 -1.240444 9.300215 17.27063 30.05174 16.96633
#> [,23] [,24] [,25] [,26] [,27] [,28] [,29]
#> [1,] -3.209405 -2.383373 4.884374 -4.34767 -13.49295 -1.487253 -7.688684
#> [,30] [,31] [,32] [,33] [,34] [,35] [,36] [,37]
#> [1,] 22.25427 -15.09408 23.33501 -10.09009 25.14779 22.54285 20.57214 28.58868
#> [,38] [,39] [,40] [,41] [,42] [,43] [,44]
#> [1,] -35.81922 -27.71959 14.32333 -9.976609 5.760523 -1.679895 23.25297
#> [,45] [,46] [,47] [,48] [,49] [,50] [,51] [,52]
#> [1,] -6.661844 -10.12444 -8.080113 1.671866 1.7321 -2.361823 -2.702599 13.58119
#> [,53] [,54] [,55] [,56] [,57] [,58] [,59]
#> [1,] 0.4572433 23.7002 -18.50748 2.445694 -13.72456 -7.414783 -32.04514
#> [,60] [,61] [,62] [,63] [,64] [,65] [,66] [,67]
#> [1,] -6.199215 6.896648 -0.6617123 25.66971 -8.842455 5.85318 9.737446 23.24091
#> [,68] [,69] [,70] [,71] [,72] [,73] [,74]
#> [1,] -6.290939 -2.844827 2.441021 14.44578 -21.43414 2.656589 -7.702801
#> [,75] [,76] [,77] [,78] [,79] [,80] [,81] [,82]
#> [1,] 10.12788 -19.14044 0.5856207 3.2317 -9.838038 5.750681 4.113926 6.182884
#> [,83] [,84] [,85] [,86] [,87] [,88] [,89] [,90]
#> [1,] 3.559588 -1.824327 7.843043 -18.74854 25.48781 10.7277 -6.35526 -15.57408
#> [,91] [,92] [,93] [,94] [,95] [,96] [,97] [,98]
#> [1,] -13.73073 -16.02937 5.82532 1.030885 20.36749 -12.597 -2.909576 5.58369
#> [,99] [,100]
#> [1,] -0.8818947 12.82357
integratemvn(matrix(1, 1, 1), 100L, c(5), matrix(1))
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7]
#> [1,] -0.7135463 -3.868053 -1.429865 -10.98098 -4.673939 1.79188 -6.649585
#> [,8] [,9] [,10] [,11] [,12] [,13] [,14]
#> [1,] -2.183614 7.213287 -0.7813409 3.108335 1.111544 0.9794934 -1.298759
#> [,15] [,16] [,17] [,18] [,19] [,20] [,21]
#> [1,] -7.232891 -2.691704 -1.159137 3.419207 -3.942242 4.067266 -3.413771
#> [,22] [,23] [,24] [,25] [,26] [,27] [,28]
#> [1,] -4.618486 -4.198757 -0.7053725 -5.384133 4.313505 0.9841081 3.23278
#> [,29] [,30] [,31] [,32] [,33] [,34] [,35] [,36]
#> [1,] 1.216483 2.608451 -2.683926 4.585647 -1.117844 1.227422 -3.25 -1.754925
#> [,37] [,38] [,39] [,40] [,41] [,42] [,43] [,44]
#> [1,] 4.000767 -0.9185378 -2.593659 3.76151 -5.178962 4.23241 -4.10077 1.139821
#> [,45] [,46] [,47] [,48] [,49] [,50] [,51]
#> [1,] 4.703518 -3.290894 4.427245 1.802808 -7.594683 1.531875 -4.104768
#> [,52] [,53] [,54] [,55] [,56] [,57] [,58] [,59]
#> [1,] -1.973999 2.368651 -3.06232 10.34562 2.40824 -2.504566 0.9807011 1.455059
#> [,60] [,61] [,62] [,63] [,64] [,65] [,66]
#> [1,] -2.870225 -1.742344 -3.628227 3.91523 3.90477 -0.005043495 -0.5758349
#> [,67] [,68] [,69] [,70] [,71] [,72] [,73]
#> [1,] -3.761433 -0.9176727 2.169821 -3.315807 2.119115 3.00131 -2.501317
#> [,74] [,75] [,76] [,77] [,78] [,79] [,80]
#> [1,] -0.2393959 -1.44501 8.910665 -8.468943 -0.3637739 -1.713302 -4.410945
#> [,81] [,82] [,83] [,84] [,85] [,86] [,87] [,88]
#> [1,] 4.032317 3.794963 1.43345 -6.844909 4.286983 -2.401059 -1.241125 -4.201715
#> [,89] [,90] [,91] [,92] [,93] [,94] [,95]
#> [1,] -0.2670129 1.380881 -1.700239 -5.576915 -1.137803 -3.720332 -2.143973
#> [,96] [,97] [,98] [,99] [,100]
#> [1,] 4.997765 3.420575 6.634333 -7.055321 7.623981