mvnormal Generate multivariate normal samples mvnormal

SAS Macro Programs: mvnormal

$Version: 0.6-0 (28 Jan 2007)
Michael Friendly
York University


The mvnormal macro ( [download] get mvnormal.sas)

Generate multivariate normal samples

The MVNORMAL macro generates random samples from multivariate normal distributions with a specified covariance matrix and one or more specified mean vectors.

Method

The macro uses the CALL VNORMAL routine in SAS/IML to generate the samples.

Usage

The MVNORMAL macro is defined with keyword parameters. The arguments may be listed within parentheses in any order, separated by commas. For example:

  %mvnormal(data=mycorr, var=X1 X2 X3 X4);

Parameters

DATA=
The name of the input data set containing either correlations (and standard deviations) or variances and covariances, as specified by the TYPE= parameter. This must be in a form similar to that produced by PROC CORR with the OUTP= option, and possibly the COV option as well. For a correlation matrix, this will contain correlations (_TYPE_='CORR') and standard deviations (_TYPE_='STD'); a covariance matrix will contain observations of _TYPE_='COV'.
VAR=
A list of names of variables to be generated. Mut be an explicit list of blank-separated names, rather than an abbreviated list like X1-X5.
TYPE=
Type of input data set: CORR or COV. [Default: TYPE=COV]
MEANS=
Name of an input dataset containing mean vector(s) for the VAR= variables. One group of N obsrvations is generated for each observation in the MEANS= dataset.
CLASS=
Name of class/group variable in means data set. The MEANS= dataset should contain one observation for each group.
N=
Sample size (for each group). [Default: N=10]
SEED=
Seed for random number generator. If not specified, the time of day is used as the seed.
OUT=
The name of the output data set [Default: OUT=SAMPLE]

Example

%include macros(mvnormal);        *-- or include in an autocall library;
 *-- common correlation matrix for all groups;
 data corr;
  _type_ = 'CORR';
  input _type_ _name_ $ X1 X2 X3;
 cards;
 CORR  X1    1    .5   .3
 CORR  X2   .5     1   .2
 CORR  X3   .3    .2    1
 STD    .   10     5    7
 ;
 data means;
  input gp group $  _type_ $  X1 X2 X3;
 cards;
 1  A  MEAN   10  10  10
 2  B  MEAN   20  20  20
 3  C  MEAN   30  30  30

 %mvnormal(data=corr, type=CORR, var=X1 X2 X3
  ,means=means
  ,class=group
  );

See also

dummy Macro to create dummy variables
jitter Add noise to numeric variables to prevent overplotting
mpower Retrospective power analysis for multivariate GLMs