Skip to contents

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.

Usage

integratemvn(X, k, sd, chol)

integratemvnR(X, k, sd, chol)

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.

Value

A numeric matrix with random values

Functions

  • integratemvnR(): Pure R implementation of integratemvn().

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,] -22.75901 -0.5884317 -11.84926 -18.27126 -3.710103 5.120226 -27.80911
#>           [,8]     [,9]     [,10]    [,11]     [,12]    [,13]    [,14]    [,15]
#> [1,] -9.845854 29.08115 -10.01901 24.16488 -1.240444 9.300215 17.27063 30.05174
#>         [,16]     [,17]     [,18]    [,19]    [,20]     [,21]     [,22]
#> [1,] 16.96633 -3.209405 -2.383373 4.884374 -4.34767 -13.49295 -1.487253
#>          [,23]    [,24]     [,25]    [,26]     [,27]    [,28]    [,29]    [,30]
#> [1,] -7.688684 22.25427 -15.09408 23.33501 -10.09009 25.14779 22.54285 20.57214
#>         [,31]     [,32]     [,33]    [,34]     [,35]    [,36]     [,37]
#> [1,] 28.58868 -35.81922 -27.71959 14.32333 -9.976609 5.760523 -1.679895
#>         [,38]     [,39]     [,40]     [,41]    [,42]  [,43]     [,44]     [,45]
#> [1,] 23.25297 -6.661844 -10.12444 -8.080113 1.671866 1.7321 -2.361823 -2.702599
#>         [,46]     [,47]   [,48]     [,49]    [,50]     [,51]     [,52]
#> [1,] 13.58119 0.4572433 23.7002 -18.50748 2.445694 -13.72456 -7.414783
#>          [,53]     [,54]    [,55]      [,56]    [,57]     [,58]   [,59]
#> [1,] -32.04514 -6.199215 6.896648 -0.6617123 25.66971 -8.842455 5.85318
#>         [,60]    [,61]     [,62]     [,63]    [,64]    [,65]     [,66]    [,67]
#> [1,] 9.737446 23.24091 -6.290939 -2.844827 2.441021 14.44578 -21.43414 2.656589
#>          [,68]    [,69]     [,70]     [,71]  [,72]     [,73]    [,74]    [,75]
#> [1,] -7.702801 10.12788 -19.14044 0.5856207 3.2317 -9.838038 5.750681 4.113926
#>         [,76]    [,77]     [,78]    [,79]     [,80]    [,81]   [,82]    [,83]
#> [1,] 6.182884 3.559588 -1.824327 7.843043 -18.74854 25.48781 10.7277 -6.35526
#>          [,84]     [,85]     [,86]   [,87]    [,88]    [,89]   [,90]     [,91]
#> [1,] -15.57408 -13.73073 -16.02937 5.82532 1.030885 20.36749 -12.597 -2.909576
#>        [,92]      [,93]    [,94]    [,95]     [,96]    [,97]    [,98]     [,99]
#> [1,] 5.58369 -0.8818947 12.82357 2.015811 -4.984218 1.831256 9.372498 -2.468395
#>        [,100]
#> [1,] 8.403141

integratemvn(matrix(1, 1, 1), 100L, c(5), matrix(1))
#>           [,1]      [,2]     [,3]       [,4]     [,5]     [,6]      [,7]
#> [1,] -6.649585 -2.183614 7.213287 -0.7813409 3.108335 1.111544 0.9794934
#>           [,8]      [,9]     [,10]     [,11]    [,12]     [,13]    [,14]
#> [1,] -1.298759 -7.232891 -2.691704 -1.159137 3.419207 -3.942242 4.067266
#>          [,15]     [,16]     [,17]      [,18]     [,19]    [,20]     [,21]
#> [1,] -3.413771 -4.618486 -4.198757 -0.7053725 -5.384133 4.313505 0.9841081
#>        [,22]    [,23]    [,24]     [,25]    [,26]     [,27]    [,28] [,29]
#> [1,] 3.23278 1.216483 2.608451 -2.683926 4.585647 -1.117844 1.227422 -3.25
#>          [,30]    [,31]      [,32]     [,33]   [,34]     [,35]   [,36]    [,37]
#> [1,] -1.754925 4.000767 -0.9185378 -2.593659 3.76151 -5.178962 4.23241 -4.10077
#>         [,38]    [,39]     [,40]    [,41]    [,42]     [,43]    [,44]     [,45]
#> [1,] 1.139821 4.703518 -3.290894 4.427245 1.802808 -7.594683 1.531875 -4.104768
#>          [,46]    [,47]    [,48]    [,49]   [,50]     [,51]     [,52]    [,53]
#> [1,] -1.973999 2.368651 -3.06232 10.34562 2.40824 -2.504566 0.9807011 1.455059
#>          [,54]     [,55]     [,56]   [,57]   [,58]        [,59]      [,60]
#> [1,] -2.870225 -1.742344 -3.628227 3.91523 3.90477 -0.005043495 -0.5758349
#>          [,61]      [,62]    [,63]     [,64]    [,65]   [,66]     [,67]
#> [1,] -3.761433 -0.9176727 2.169821 -3.315807 2.119115 3.00131 -2.501317
#>           [,68]    [,69]    [,70]     [,71]      [,72]     [,73]     [,74]
#> [1,] -0.2393959 -1.44501 8.910665 -8.468943 -0.3637739 -1.713302 -4.410945
#>         [,75]    [,76]   [,77]     [,78]    [,79]     [,80]     [,81]     [,82]
#> [1,] 4.032317 3.794963 1.43345 -6.844909 4.286983 -2.401059 -1.241125 -4.201715
#>           [,83]    [,84]     [,85]     [,86]     [,87]     [,88]     [,89]
#> [1,] -0.2670129 1.380881 -1.700239 -5.576915 -1.137803 -3.720332 -2.143973
#>         [,90]    [,91]    [,92]     [,93]    [,94]     [,95]     [,96]    [,97]
#> [1,] 4.997765 3.420575 6.634333 -7.055321 7.623981 0.0240864 -2.539978 3.131355
#>          [,98]     [,99]   [,100]
#> [1,] -1.738087 -3.202446 5.212741