
Sample from the multivariate normal via mvtnorm
Source:R/extenders_spatial.R
morie_mvnorm_sample.RdThin extender over mvtnorm::rmvnorm that draws \(n\)
observations from the multivariate normal distribution with a
given mean vector and covariance matrix.
Arguments
- n
Integer; the number of multivariate observations to draw.
- mean
Numeric vector of length
ncol(sigma)giving the mean (defaults to a zero vector).- sigma
Numeric positive-(semi)definite covariance matrix.
- ...
Further arguments forwarded to
mvtnorm::rmvnorm(e.g.method,pre0.9_9994,checkSymmetry).
Value
A list with $method = "mvtnorm::rmvnorm" and
$raw (a numeric matrix of dimension
\(n \times \mathrm{ncol}(\Sigma)\)).
Examples
# \donttest{
if (requireNamespace("mvtnorm", quietly = TRUE)) {
set.seed(1)
S <- matrix(c(1, 0.4, 0.4, 1), 2, 2)
morie_mvnorm_sample(100, mean = c(0, 0), sigma = S)
}
#> $method
#> [1] "mvtnorm::rmvnorm"
#>
#> $raw
#> [,1] [,2]
#> [1,] -0.57571949 0.05177905
#> [2,] -0.49207087 1.39090346
#> [3,] 0.15492763 -0.73584007
#> [4,] 0.62799423 0.82233717
#> [5,] 0.50124221 -0.18130894
#> [6,] 1.55954086 0.69049148
#> [7,] -1.06062087 -2.29490914
#> [8,] 1.09202161 0.18584844
#> [9,] 0.17698609 0.92061940
#> [10,] 0.92523838 0.74915716
#> [11,] 1.05939074 0.95339410
#> [12,] -0.33345160 -1.93215459
#> [13,] 0.59528369 0.07169160
#> [14,] -0.45299810 -1.47155932
#> [15,] -0.38267462 0.31143496
#> [16,] 1.30901947 0.17697178
#> [17,] 0.36850130 0.02653495
#> [18,] -1.43279968 -0.68758735
#> [19,] -0.39809122 -0.13861950
#> [20,] 1.23274595 0.97182335
#> [21,] -0.21281742 -0.28163111
#> [22,] 0.79599351 0.68731746
#> [23,] -0.81877538 -0.83329091
#> [24,] 0.51391027 0.82680934
#> [25,] 0.07004239 0.83956850
#> [26,] 0.26466547 -0.51777963
#> [27,] 0.10318445 -1.03584662
#> [28,] 1.80741075 2.23140652
#> [29,] -0.57280220 -1.09713687
#> [30,] 0.53010918 -0.01580659
#> [31,] 2.34294168 0.45226138
#> [32,] 0.68091133 0.16833189
#> [33,] -0.68902275 0.03295209
#> [34,] -1.46745840 1.06587045
#> [35,] 0.59390618 2.15809441
#> [36,] 0.32043038 -0.59781986
#> [37,] 0.40699873 -0.78961678
#> [38,] -1.16764437 0.02916917
#> [39,] -0.43371538 -0.08948677
#> [40,] -0.04767162 -0.56189713
#> [41,] -0.58429171 -0.24851171
#> [42,] 0.84195741 -1.25073462
#> [43,] 0.64944264 0.44727615
#> [44,] 0.97852743 -0.08056601
#> [45,] 0.41678461 0.33706310
#> [46,] -0.28429724 1.07154735
#> [47,] 1.27898585 0.92252501
#> [48,] 1.66746545 0.87091127
#> [49,] -1.36678782 -0.82199323
#> [50,] -1.29550133 -0.71361504
#> [51,] -0.59867618 -0.08551940
#> [52,] -0.85942015 -0.03141471
#> [53,] -0.27970321 1.59627071
#> [54,] 0.88754685 1.03740555
#> [55,] 0.71976627 1.72518556
#> [56,] -0.71664490 -0.58179403
#> [57,] 1.26912659 -0.34434169
#> [58,] -0.28326077 -0.42689205
#> [59,] -0.37026858 -0.33860340
#> [60,] 0.44753375 -0.07262249
#> [61,] -0.22088917 1.21133720
#> [62,] -0.24673827 -0.21960966
#> [63,] 0.04752725 0.67716361
#> [64,] -0.07970168 -0.05187025
#> [65,] -0.73353329 -0.45670003
#> [66,] -0.06142539 -0.56418117
#> [67,] 0.21006242 -1.37777575
#> [68,] -0.01382009 -1.44140770
#> [69,] -0.40256011 -0.57862886
#> [70,] -0.64996426 -0.18892587
#> [71,] -1.63359121 0.76064274
#> [72,] -1.72455576 -0.79392276
#> [73,] -1.24578080 -0.96297470
#> [74,] 2.04669460 0.44345694
#> [75,] -1.59435924 -1.86880272
#> [76,] 0.43689904 0.07380923
#> [77,] -0.50123679 -0.97474291
#> [78,] -1.67575644 -1.35641501
#> [79,] 0.85200373 -0.40384636
#> [80,] -0.97331008 1.54700864
#> [81,] 0.36737554 -0.14676105
#> [82,] 1.21726043 1.08398302
#> [83,] -0.15545292 2.03305030
#> [84,] -0.54068556 -1.44655129
#> [85,] -0.09895160 0.17365836
#> [86,] 2.28091107 0.57511285
#> [87,] 0.43159593 0.01784377
#> [88,] -0.33405040 -0.10223312
#> [89,] 1.19501795 2.19239281
#> [90,] 1.25250828 1.39233534
#> [91,] -1.00433092 0.71157034
#> [92,] -0.08448755 -1.39136756
#> [93,] 0.47759736 -0.04895591
#> [94,] 1.27717583 -0.45069319
#> [95,] -0.61035010 -0.99447084
#> [96,] -0.09123330 0.35734782
#> [97,] -0.54665966 0.66335433
#> [98,] -1.39671319 -1.27270152
#> [99,] 1.20321094 -0.69997708
#> [100,] 0.32542713 -0.28886735
#>
# }