Chee Chen
2011-May-01 03:39 UTC
[R] Question on where samples are grouped in rmvnorm{mvtnorm}
Dear All, For function: rmvnorm{mvtnorm} in (library mvtnorm, not splus2R), if I generate 2 bivariate normal samples as follows:> rmvnorm(2,mean=rep(0,2),sigma=diag(2))[,1] [,2] [1,] 2.0749459 1.4932752 [2,] -0.9886333 0.3832266 Where is the first sample, it is stored in the first row or the first column? Does this function store samples row-wise or column-wise? Thank you, -Chee [[alternative HTML version deleted]]
Petr Savicky
2011-May-01 10:10 UTC
[R] Question on where samples are grouped in rmvnorm{mvtnorm}
On Sat, Apr 30, 2011 at 11:39:43PM -0400, Chee Chen wrote:> Dear All, > For function: rmvnorm{mvtnorm} in (library mvtnorm, not splus2R), if I generate 2 bivariate normal samples as follows: > > rmvnorm(2,mean=rep(0,2),sigma=diag(2)) > [,1] [,2] > [1,] 2.0749459 1.4932752 > [2,] -0.9886333 0.3832266 > > Where is the first sample, it is stored in the first row or the first column? > Does this function store samples row-wise or column-wise?Hi. The call rmvnorm(3,mean=rep(0,2),sigma=diag(2)) produces [,1] [,2] [1,] 2.5795462 0.7862570 [2,] 0.2630356 0.3879757 [3,] -0.5035942 0.5804228 which shows that the samples are rows. The arrangement that rows are the vectors of observations and columns are variables is typical in R. The examples in ?rmvnorm demonstrate this, since the mean is computed using colMeans() and variance using var(). See also ?var. Hope this helps. Petr Savicky.
Uwe Ligges
2011-May-01 16:01 UTC
[R] Question on where samples are grouped in rmvnorm{mvtnorm}
On 01.05.2011 05:39, Chee Chen wrote:> Dear All, > For function: rmvnorm{mvtnorm} in (libraryNo, it is a package, not a library!> mvtnorm, not splus2R), if I generate 2 bivariate normal samples as follows: >> rmvnorm(2,mean=rep(0,2),sigma=diag(2)) > [,1] [,2] > [1,] 2.0749459 1.4932752 > [2,] -0.9886333 0.3832266>> Where is the first sample, it is stored in the first row or the first column? > Does this function store samples row-wise or column-wise?Hmmm, you could do something to find out which is much faster than writing this message: Try to generate 3 bivariate samples and look if you got 3 rows or 3 columns now! Uwe Ligges> Thank you, > -Chee > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
Reasonably Related Threads
- Generating an autocorrelated binary variable
- Why ?rmvnorm not working
- inconsistency in return value of peaks() {splus2R} (PR#13988)
- scoping problem when calling lm(precomputed formula, weights) from function (PR#11540)
- help (using ?) does not handle trailing whitespace (PR#11537)