Date: Tue, 19 May 2009 06:29:41 -0500 Reply-To: "Data _null_;" Sender: "SAS(r) Discussion" From: "Data _null_;" Subject: Re: variance covariance matrix Comments: To: Umrao In-Reply-To: <3bf42769-5971-4c06-919c-1786f3ee19b8@i28g2000prd.googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1 It's a bit fiddley but it works. There are surely other methods that I don't know. data cov(type='COV'); length _type_ _name_ \$8; retain _type_ 'COV'; input v1-v5; _name_ = cats('v',_n_); cards; 0.644607 0.1680246 1.483855 1.6281761 0.7427545 0.1680246 0.0626773 0.2708275 0.1894284 0.2474915 1.483855 0.2708275 4.8090391 5.3790562 1.8120638 1.6281761 0.1894284 5.3790562 8.7463271 0.6100965 0.7427545 0.2474915 1.8120638 0.6100965 2.2213662 ;;; run; proc factor noprint data=cov corr outstat=stats; run; *proc print; run; data corr; set stats; where _type_ eq 'CORR'; array v[*] v:; do _n_ = 1 to dim(v); if v[_n_] = 1 then v[_n_] = .; end; run; data covCorr; update cov corr; by _name_; run; proc print; run; On 5/19/09, Umrao wrote: > I have a variance-covariance matrix COV. The diagonal numbers are the > variances and the off diagonal numbers are the covriances. > > COV={0.644607 0.1680246 1.483855 1.6281761 > 0.7427545, > 0.1680246 0.0626773 0.2708275 0.1894284 0.2474915, > 1.483855 0.2708275 4.8090391 5.3790562 > 1.8120638, > 1.6281761 0.1894284 5.3790562 8.7463271 > 0.6100965, > 0.7427545 0.2474915 1.8120638 > 0.6100965 2.2213662}; > > Is there any procedure to convert the off diagonal numbers that are > the covariances into correlations. > > i.e., for the second element int he first row i whant to calculate the > value as 0.1680246/sqrt(0.644607*0.0626773) > this i have to do for all the offdiagonal elements. > The new matrix becomes a variance-correlation matrix as > > varcorr={0.644607 0.835930597 0.842781127 0.685710831 0.620708515, > 0.835930597 0.0626773 0.493296992 0.255845094 0.663277199, > 0.842781127 0.493296992 4.8090391 0.829400075 > 0.554414079, > 0.685710831 0.255845094 0.829400075 8.7463271 > 0.13841259, > 0.620708515 0.663277199 0.554414079 0.13841259 2.2213662}; > > > I have to apply the formula for correlation= cov(x,y)/sqrt{var(x)*var > (y)} to all the offdiagonal elements of the variance-covariance > matrix COV. >

Back to: Top of message | Previous page | Main SAS-L page