[R] Question on where samples are grouped in rmvnorm{mvtnorm}

Petr Savicky savicky at praha1.ff.cuni.cz
Sun May 1 12:10:13 CEST 2011


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.



More information about the R-help mailing list