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,] -2.532922 -11.0255 -15.62315 -5.945561 12.3833 31.16333 -12.28061
#>           [,8]      [,9]     [,10]    [,11]    [,12]    [,13]    [,14]   [,15]
#> [1,] -23.60515 -24.30755 -7.039234 18.30881 7.519073 5.127029 3.787549 -8.3329
#>        [,16]     [,17]     [,18]    [,19]    [,20]    [,21]    [,22]     [,23]
#> [1,] 2.07574 -2.274109 -12.91986 18.12975 16.03091 1.773234 1.738388 -12.16543
#>         [,24]    [,25]     [,26]     [,27]    [,28]    [,29]     [,30]
#> [1,] 9.148699 10.18332 -2.478298 -1.564364 7.167047 -12.6017 -22.06056
#>          [,31]    [,32]    [,33]    [,34]    [,35]    [,36]     [,37]     [,38]
#> [1,] -13.17943 6.621935 8.112899 11.15757 11.53846 5.243993 -17.33807 -4.115552
#>          [,39]      [,40]     [,41]    [,42]     [,43]     [,44]    [,45]
#> [1,] -25.67939 -0.4109835 -30.72972 6.685414 -2.307672 0.3308937 3.971339
#>         [,46]    [,47]    [,48]   [,49]     [,50]     [,51]     [,52]    [,53]
#> [1,] 7.484046 11.34228 2.704572 11.4301 -3.942935 -9.846664 -3.099096 25.08547
#>          [,54]    [,55]    [,56]     [,57]     [,58]     [,59]      [,60]
#> [1,] -17.57852 3.780591 7.547444 -15.60536 -20.48252 -0.905266 -0.1616197
#>          [,61]    [,62]    [,63]     [,64]     [,65]    [,66]     [,67]
#> [1,] -27.81639 11.22293 2.907226 -11.31305 -8.809451 21.82451 -15.82794
#>          [,68]     [,69]    [,70]    [,71]     [,72]    [,73]     [,74]
#> [1,] -13.44247 -5.663045 2.559502 5.545465 -3.633395 5.463712 0.7750582
#>         [,75]   [,76]     [,77]      [,78]      [,79]     [,80]     [,81]
#> [1,] 11.02672 6.18859 -11.75193 -0.5271864 -0.5454928 -3.076516 0.1512587
#>         [,82]    [,83]     [,84]     [,85]     [,86]     [,87]    [,88]
#> [1,] -8.71869 1.359214 -3.714129 -18.99422 -1.972561 -9.098939 6.458838
#>         [,89]    [,90]     [,91]     [,92]    [,93]    [,94]    [,95]   [,96]
#> [1,] 10.20245 25.89387 -2.376868 -17.50103 1.166735 10.46323 1.445334 19.2387
#>          [,97]     [,98]   [,99]   [,100]
#> [1,] -18.41725 -32.36873 6.37611 26.72262

integratemvn(matrix(1, 1, 1), 100L, c(5), matrix(1))
#>          [,1]     [,2]     [,3]     [,4]      [,5]     [,6]     [,7]     [,8]
#> [1,] 1.700232 3.721869 2.218648 5.665324 -6.470933 4.254986 5.293128 1.715151
#>           [,9]     [,10]     [,11]     [,12]     [,13]     [,14]    [,15]
#> [1,] -2.875418 -4.254758 -8.830165 -9.135963 -2.302593 -3.053092 1.134457
#>           [,16]     [,17]      [,18]     [,19]    [,20]      [,21]    [,22]
#> [1,] -0.3289744 -6.947195 -0.2379369 -4.484426 3.682915 -0.5820785 4.888476
#>         [,23]    [,24]     [,25]     [,26]     [,27]     [,28]    [,29]
#> [1,] -3.87221 4.812574 -1.152856 -7.658283 0.8673464 -3.135211 7.857057
#>           [,30]    [,31]    [,32]   [,33]     [,34]    [,35]    [,36]     [,37]
#> [1,] -0.6703977 2.120208 9.590751 3.46392 -2.603151 1.765105 5.112677 -4.737641
#>           [,38]     [,39]      [,40]     [,41]      [,42]     [,43]       [,44]
#> [1,] -0.5822274 -2.594275 -0.5253295 -5.067429 -0.8061459 -2.389436 -0.08090759
#>         [,45]    [,46]    [,47]    [,48]     [,49]    [,50]     [,51]   [,52]
#> [1,] -2.20671 4.415764 1.310574 1.322545 -6.894872 -1.02668 -6.362873 1.93159
#>           [,53]    [,54]    [,55]     [,56]    [,57]     [,58]    [,59]
#> [1,] -0.9568204 -2.01197 2.759349 -1.643193 5.414086 -3.214495 1.172826
#>          [,60]      [,61]     [,62]     [,63]    [,64]     [,65]     [,66]
#> [1,] -1.424341 -0.1561199 0.9745042 -3.850841 2.550673 0.3709918 -1.656451
#>          [,67]   [,68]       [,69]     [,70]    [,71]    [,72]     [,73]
#> [1,] -1.894241 5.98995 -0.01753994 -4.587137 3.826585 10.40862 -2.775133
#>          [,74]    [,75]    [,76]      [,77]     [,78]    [,79]      [,80]
#> [1,] -5.902626 10.83661 3.175362 -0.5511688 -1.149656 3.457253 -0.2388521
#>         [,81]    [,82]    [,83]    [,84]    [,85]     [,86]     [,87]    [,88]
#> [1,] 1.055833 14.60076 0.621296 0.494413 4.921946 -8.119916 -4.521406 5.901008
#>         [,89]   [,90]     [,91]     [,92]      [,93]    [,94]    [,95]    [,96]
#> [1,] 0.164206 13.1067 -3.386494 0.1996253 -0.1355221 7.000752 2.967639 7.940031
#>         [,97]     [,98]     [,99]    [,100]
#> [1,] 4.831914 -4.256031 -2.377087 -1.578515