BookmarkSubscribeRSS Feed
BlueNose
Quartz | Level 8

Hello all,

I would like to simulate data of a bivariate "table" distribution.

I want to generate a vector of values (0,1,2,3,4,5) with probabilities (p(0), p(1), p(2), p(3), p(4), p(5)). Then I want to generate another such vector, with a correlation of let's say 0.8 to the first vector.

How do I do that ?

Thank you in advance.

1 REPLY 1
Rick_SAS
SAS Super FREQ

Although your message sounds like you might be wanting to use conditional probability, I suspect that you are trying to generate two vectors jointly from a correlated multivariate ordinal distribution.   This is described in Section 9.4 of Simulating Data with SAS, and further described in the Appendix B. Using the modules described in the book, the code looks like this:

/* read in programs from Simulating Data with SAS */
%include "C:\Downloads\Wicklin2013\RandMVOrd.sas";
proc iml;
load module=_all_;

/* define the probabilities of X1 and X2 */
/*   X1   X2 */
P = {0.1  0.1,    /* P(0) */
     0.2  0.2,    /* P(1) */
  0.2  0.2,    /* P(2) */
  0.2  0.2,    /* P(3) */
  0.2  0.2,    /* P(4) */
  0.1  0.1 };  /* P(5) */
/* define the correlation between X1 and X2 */
Delta = {1   0.8,
         0.8 1.0 };
  
/* generate two vectors of 100 observations */  
call randseed(54321);
X = RandMVOrdinal(100, P, Delta);

/* test the process by computing sample correlation */
corr = corr(X);
print corr;

        corr

           1 0.7709831

  0.7709831         1

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 1 reply
  • 1332 views
  • 0 likes
  • 2 in conversation