Simulating in SAS - AnalyticBridge 2019-06-26T05:43:53Z https://www.analyticbridge.datasciencecentral.com/forum/topics/simulating-in-sas?groupUrl=sasandstatisticalprogramming&xg_source=activity&feed=yes&xn_auth=no Sorry my answer is a bit late… tag:www.analyticbridge.datasciencecentral.com,2011-02-26:2004291:Comment:91349 2011-02-26T14:21:55.157Z Randa Al-Teraifi https://www.analyticbridge.datasciencecentral.com/profile/RandaAlTeraifi <p>Sorry my answer is a bit late but hope other people find it helpful.</p> <p> </p> <p>/*  This program generates 300 observations of the variables y<sub>1</sub>, y<sub>2</sub>, y<sub>3</sub>, y<sub>4</sub> .  Beginning with the correlation matrix R and a vector of means m = (m<sub>1</sub>,m<sub>2</sub>,m<sub>3</sub>,m<sub>4</sub>)' and standard deviations s = (s<sub>1</sub>,s<sub>2</sub>,s<sub>3</sub>,s<sub>4</sub>)' read in as variables using a CARDS statement. </p> The means were… <p>Sorry my answer is a bit late but hope other people find it helpful.</p> <p> </p> <p>/*  This program generates 300 observations of the variables y<sub>1</sub>, y<sub>2</sub>, y<sub>3</sub>, y<sub>4</sub> .  Beginning with the correlation matrix R and a vector of means m = (m<sub>1</sub>,m<sub>2</sub>,m<sub>3</sub>,m<sub>4</sub>)' and standard deviations s = (s<sub>1</sub>,s<sub>2</sub>,s<sub>3</sub>,s<sub>4</sub>)' read in as variables using a CARDS statement. </p> The means were arbitrarily selected as those in Liu and Gould 2002. The standard deviation vector and the correlation matrix were obtained from the data used by Allison et al (2003). <br /> <p>*/</p> <p> </p> <p>data   MVN_par;                        /* data for the parameter for the multivariate normal data*/</p> <p>input  r<sub>1</sub> r<sub>2</sub> r<sub>3</sub> r<sub>4</sub> means vars ;   /* these can be adjusted to cater for the other two scenarios*/  </p> <p>cards;                                    </p> <p>1     0.986   0.967   0.949   92  14.3            /* These can be extended to an  n by n correlation</p> <p>0.986  1      0.992   0.980   88  14                  matrix and n-dimensional means and standard</p> <p>0.967  0.992   1      0.995   85  14.2              deviations vectors</p> <p>run;</p> <p> </p> <p>proc iml;</p> <p>use MVN_par;</p> <p>read all var {r<sub>1</sub> r<sub>2</sub> r<sub>3</sub> r<sub>4</sub>} into R;</p> <p>read all var {means}       into mu;</p> <p>read all var {vars}        into sigma;</p> <p>p = ncol(R);                                            /* p is the number of variables generated*/</p> <p>diag_sig = diag(sigma);</p> <p>DRD = diag_sig * R * diag_sig` ;         /* D is the a diagonal matrix whose element are</p> <p>                                                                   the standard deviations of each y<sub>i</sub> */</p> <p>U = half(DRD);</p> <p>do i = 1 to 300;                                      /*  this can be replaced with k to generate the</p> <p>                                                                  dataset with k patients. */</p> <p> </p> <p>z = rannor(j(p,1,1234));                        /* Generating random numbers. Z<sub>i</sub> i = 1,2,...,p</p> <p>                                                                  independent and have N(0,1)distribution.</p> <p>                                                                  The var-cov matrix for Z' is the identity matrix.*/</p> <p>yprime = y`;</p> <p>yall = yall // yprime;</p> <p>end;</p> <p>varnames = {y<sub>1</sub> y<sub>2</sub> y<sub>3</sub> y<sub>4</sub>};                      /* naming the variables*/</p> <p>create my_MVN from yall (|colname = varnames|);</p> <p>append from yall;</p> <p>proc print  data = my_MVN; </p> <p> </p> <p> </p> <p> </p> create crosstab (proc freq) a… tag:www.analyticbridge.datasciencecentral.com,2010-03-24:2004291:Comment:64107 2010-03-24T10:49:57.594Z Jozo Kovac https://www.analyticbridge.datasciencecentral.com/profile/JozoKovac create crosstab (proc freq) and consider CHISQ.<br /> dont forget to discretize numeric variables (proc rank groups=5; ...) .<br /> here's example from sas doc:<br /> proc freq data=Color order=data;<br /> tables Eyes*(Hair Sex Country) / expected cellchi2 norow nocol chisq;<br /> output out=ChiSqData n nmiss pchi lrchi;<br /> weight Count;<br /> title 'Chi-Square Tests for 3 by 5 Table of Eye and Hair Color and...';<br /> run; create crosstab (proc freq) and consider CHISQ.<br /> dont forget to discretize numeric variables (proc rank groups=5; ...) .<br /> here's example from sas doc:<br /> proc freq data=Color order=data;<br /> tables Eyes*(Hair Sex Country) / expected cellchi2 norow nocol chisq;<br /> output out=ChiSqData n nmiss pchi lrchi;<br /> weight Count;<br /> title 'Chi-Square Tests for 3 by 5 Table of Eye and Hair Color and...';<br /> run;