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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.

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