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

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 1055 views
  • 0 likes
  • 2 in conversation