The Multivariate Normal 1 The Normal Distribution 2

The Multivariate Normal 1

The Normal Distribution 2

The Multivariate Normal 3

Subsets of a MVN are also MVN with mean gotten by taking the correct elements from µ and variance gotten by taking the correct rows and columns from ∑ 4

Linear Combinations of MVNs are also MVNs 5

PROC SIMNORM 6

Simulation with PROC SIMNORM %let obs = 1000; %let seed=54321; /* create a TYPE=COV data set */ data ACov(type=COV); input _TYPE_ $ 1 -8 _NAME_ $ 9 -16 x 1 x 2 x 3; datalines; COV x 1 3 2 1 COV x 2 2 4 0 COV x 3 1 0 5 MEAN 1 2 3 run; proc simnormal data=ACov outsim=MVN nr = &obs /* size of sample */ seed = &seed; /* random number seed */ var x 1 -x 3; run; 7

Create scatter plot matrix of simulated data proc corr data=MVN COV plots(maxpoints=NONE)=matrix(histogram); var x: ; run; 8

Where to get variance-covariance 9

Variance-covariance from existing Data %let vars=age bmi sbp dbp; proc corr data=fram. frex 4 outp=cov 1 cov noprint; var &vars; run; proc contents data=cov 1; run; proc print data=cov 1; run; 10

Read type=corr dataset in IML proc iml; use cov 1; read all var close cov 1; _num_ where(_TYPE_="COV") where(_TYPE_="CORR") where(_TYPE_="MEAN") where(_TYPE_="STD" ) into cov[r=_NAME_ c=Var. Names]; corr; mean; std; print cov, mean, std, corr; quit; 11

Simulate using Proc Sim. Norm %let n = 1000; %let seed=54321; proc simnormal data=Cov 1 outsim=MVN nr = &n seed = &seed; var &vars; run; proc corr data=MVN COV plots(maxpoints=NONE)=matrix(histogram); var &vars; run; 12

Converting Between Correlation and Covariance Matrices 13

Converting Between Correlation and Covariance Matrices proc iml; /*convert covariance to correlation example matrix from sas help*/ S = {1. 0 8. 1, 1. 0 16. 0 18. 0, 8. 1 18. 0 81. 0 }; print s; D = sqrt(diag(S)); print d; r=inv(d)*s*inv(d); print r; cov=d*r*d; print s, cov; /*SAS functions in the IMLMLIB library cov 2 corr 2 cov*/ corr=cov 2 corr(s); print corr; cov 1=corr 2 cov(r, vecdiag(d)); print cov 1; quit; 14

When is a correlation matrix not a correlation matrix? proc iml; /*a correlation*/ d = {1. 0 0. 3 0. 6, 0. 3 1. 0 0. 6, 0. 6 1. 0}; eigval_d = eigval(d); print d, eigval_d; /*not a correlation*/ C = {1. 0 0. 3 0. 9, 0. 3 1. 0 0. 9, 0. 9 1. 0}; eigval_c = eigval(C); print c, eigval_c; quit; 15

Checking whether a matrix is symetric and positive definite proc iml; A = { 2 -1 0, -1 2 -1, 0 -1 2 }; /* finite-precision test of whether a matrix is symmetric */ start Sym. Check(A); B = (A + A`)/2; scale = max(abs(A)); delta = scale * constant("SQRTMACEPS"); return( all( abs(B-A)< delta ) ); finish; /* test a matrix for symmetry */ Is. Sym = Sym. Check(A); print Is. Sym; /*check for positive semi-definite using root*/ G = root(A, "No. Error"); if G=. then print "The matrix is not positive semidefinite"; /* check for positive-definite using eigval function*/ eigval = eigval(A); print eigval; if any(eigval<0) then print "The matrix is not positive semidefinite"; else if all(eigval>0) then print "Matrix is positive-definite"; else print "Matrix is Positive Semi-definite"; quit; 16
- Slides: 16