<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to create variables using random samples generated by given correlated matrix in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-create-variables-using-random-samples-generated-by-given/m-p/601273#M4902</link>
    <description>You're generating standard normal variables but you want to create a categorical variable? Seeing any issue with that statement there?</description>
    <pubDate>Sun, 03 Nov 2019 23:30:59 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2019-11-03T23:30:59Z</dc:date>
    <item>
      <title>How to create variables using random samples generated by given correlated matrix</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-create-variables-using-random-samples-generated-by-given/m-p/601223#M4897</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I read a message about "generate 1,000 random observations from a multivariate normal distribution with a specified mean and covariance structure" using proc iml&amp;nbsp;Y = RandNormal(&amp;amp;n, j(1,ncol(C),0), C).&amp;nbsp; See link&amp;nbsp;&lt;A href="https://blogs.sas.com/content/iml/2011/01/12/sampling-from-the-multivariate-normal-distribution.html" target="_blank"&gt;https://blogs.sas.com/content/iml/2011/01/12/sampling-from-the-multivariate-normal-distribution.html&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Sample is &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;IMG src="https://blogs.sas.com/content/iml/files/2011/08/t_mvnormal.png" border="0" /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Could can anyone please show&amp;nbsp; me how could I create variables, such as X1, X2, X3, Y based this random sample created? Y is binary dependent variables (1/0).&amp;nbsp; Xs include both continuous and character predictors, with positive or negative value, for example, age (0, 100), time during (- infinite, + infinite), gender (1/0).....&lt;/SPAN&gt;&lt;SPAN&gt;I need to build logistic regression using the simulated variables.&amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Also can I sample both dependent and independent&amp;nbsp;variable together? I mean by one correlation matrix.&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks so much!&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Best,&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Heather&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 03 Nov 2019 13:38:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-create-variables-using-random-samples-generated-by-given/m-p/601223#M4897</guid>
      <dc:creator>HappySASUE</dc:creator>
      <dc:date>2019-11-03T13:38:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to create variables using random samples generated by given correlated matrix</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-create-variables-using-random-samples-generated-by-given/m-p/601245#M4898</link>
      <description>&lt;P&gt;Have you seen this post:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/iml/2014/06/25/simulate-logistic-data.html" target="_blank"&gt;https://blogs.sas.com/content/iml/2014/06/25/simulate-logistic-data.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does it answer your question?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If not, do you have the covariance matrix or do you need to just generate random variables to simulate a logistic regression?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/188012"&gt;@HappySASUE&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I read a message about "generate 1,000 random observations from a multivariate normal distribution with a specified mean and covariance structure" using proc iml&amp;nbsp;Y = RandNormal(&amp;amp;n, j(1,ncol(C),0), C).&amp;nbsp; See link&amp;nbsp;&lt;A href="https://blogs.sas.com/content/iml/2011/01/12/sampling-from-the-multivariate-normal-distribution.html" target="_blank" rel="noopener"&gt;https://blogs.sas.com/content/iml/2011/01/12/sampling-from-the-multivariate-normal-distribution.html&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Sample is &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;IMG src="https://blogs.sas.com/content/iml/files/2011/08/t_mvnormal.png" border="0" /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Could can anyone please show&amp;nbsp; me how could I create variables, such as X1, X2, X3, Y based this random sample created? Y is binary dependent variables (1/0).&amp;nbsp; Xs include both continuous and character predictors, with positive or negative value, for example, age (0, 100), time during (- infinite, + infinite), gender (1/0).....&lt;/SPAN&gt;&lt;SPAN&gt;I need to build logistic regression using the simulated variables.&amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Also can I sample both dependent and independent&amp;nbsp;variable together? I mean by one correlation matrix.&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thanks so much!&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Best,&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Heather&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 03 Nov 2019 18:05:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-create-variables-using-random-samples-generated-by-given/m-p/601245#M4898</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-11-03T18:05:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to create variables using random samples generated by given correlated matrix</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-create-variables-using-random-samples-generated-by-given/m-p/601249#M4899</link>
      <description>&lt;P&gt;Hi I have not read this link&amp;nbsp; yet. Let me read it first. thanks a lot!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 03 Nov 2019 19:04:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-create-variables-using-random-samples-generated-by-given/m-p/601249#M4899</guid>
      <dc:creator>HappySASUE</dc:creator>
      <dc:date>2019-11-03T19:04:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to create variables using random samples generated by given correlated matrix</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-create-variables-using-random-samples-generated-by-given/m-p/601253#M4900</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I read the blog. It sample random variable using ranfun and Bernoulli.&amp;nbsp; For my question, I have a correlation and covariance matrix calculated from a real dataset (proc corr).&amp;nbsp; and I plan to &lt;SPAN&gt;generate random variables using this matrix.&amp;nbsp; As Dr. Wicklin explain in his blog:&amp;nbsp;&lt;A href="https://blogs.sas.com/content/iml/2011/01/12/sampling-from-the-multivariate-normal-distribution.html" target="_blank" rel="noopener"&gt;https://blogs.sas.com/content/iml/2011/01/12/sampling-from-the-multivariate-normal-distribution.html.&amp;nbsp;&amp;nbsp;&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;After generate the standard normal variables,&amp;nbsp;these are not the real data.&amp;nbsp; I am not sure whether I can use these variable fit the logistic or OSL model directly? For example binary variable, such as gender, I need to "transfer back" to 1/0,&amp;nbsp; and variable&amp;nbsp;age I can't use negative value -- but how can I do that?&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 03 Nov 2019 19:59:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-create-variables-using-random-samples-generated-by-given/m-p/601253#M4900</guid>
      <dc:creator>HappySASUE</dc:creator>
      <dc:date>2019-11-03T19:59:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to create variables using random samples generated by given correlated matrix</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-create-variables-using-random-samples-generated-by-given/m-p/601254#M4901</link>
      <description>&lt;P&gt;In general, the blog by Rick Wicklin talks about continuous variables. So you could use this to compute random multivariate normal values of age and time, given a specific correlation or covariance between age and time. As far as the categorical variable gender is concerned, you can generate at that at random, or you can generate that based upon some function of the randomly generated age and time. There really isn't a concept here of a correlation matrix between the continuous and categorical variables. So you will have to define how to compute gender from age and time, or how to compute gender ignoring age and time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And of course the binary Y-variable can also be generated as a random function of the three x-variables, or generated independently of the x-variables. Again, that's something you will have to define, exactly how you think this should be done.&lt;/P&gt;</description>
      <pubDate>Sun, 03 Nov 2019 21:24:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-create-variables-using-random-samples-generated-by-given/m-p/601254#M4901</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-11-03T21:24:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to create variables using random samples generated by given correlated matrix</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-create-variables-using-random-samples-generated-by-given/m-p/601273#M4902</link>
      <description>You're generating standard normal variables but you want to create a categorical variable? Seeing any issue with that statement there?</description>
      <pubDate>Sun, 03 Nov 2019 23:30:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-create-variables-using-random-samples-generated-by-given/m-p/601273#M4902</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-11-03T23:30:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to create variables using random samples generated by given correlated matrix</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-create-variables-using-random-samples-generated-by-given/m-p/601285#M4903</link>
      <description>&lt;P&gt;Yes, that's what I want to know, but you r right, doesn't make sense......thanks.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Nov 2019 02:26:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-create-variables-using-random-samples-generated-by-given/m-p/601285#M4903</guid>
      <dc:creator>HappySASUE</dc:creator>
      <dc:date>2019-11-04T02:26:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to create variables using random samples generated by given correlated matrix</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-create-variables-using-random-samples-generated-by-given/m-p/601286#M4904</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Hi Paige ,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thank you for your explanation.&amp;nbsp; I get your meaning, but since this is my first time to do this, could you please&amp;nbsp;show me some examples, on how to "think a function"--you don't need to give me any detailed description, only some study case, or links you happen to know.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thank you!&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Best,&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Heather&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Nov 2019 02:32:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-create-variables-using-random-samples-generated-by-given/m-p/601286#M4904</guid>
      <dc:creator>HappySASUE</dc:creator>
      <dc:date>2019-11-04T02:32:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to create variables using random samples generated by given correlated matrix</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-create-variables-using-random-samples-generated-by-given/m-p/601349#M4905</link>
      <description>&lt;P&gt;Is Y determined as a function of X1 X2 X3 plus some randomness? If so, what function? Or is it completely random, making it independent of X1 X2 X3?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is the categorical variable independent of age and time? Or is the some dependence based on covariance/correlation? If so, what? Or is it completely random, making it independent of time and age?&lt;/P&gt;</description>
      <pubDate>Mon, 04 Nov 2019 11:46:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-create-variables-using-random-samples-generated-by-given/m-p/601349#M4905</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-11-04T11:46:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to create variables using random samples generated by given correlated matrix</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-create-variables-using-random-samples-generated-by-given/m-p/601358#M4906</link>
      <description>&lt;P&gt;You could try ROOT() in IML .Search it at Rick's blog you will find it .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1) firstly simulate some random data by RAND().&lt;/P&gt;
&lt;P&gt;2) root=ROOT(COV) .&lt;/P&gt;
&lt;P&gt;3)&amp;nbsp; the data you need = 1)*2)&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Nov 2019 12:45:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-create-variables-using-random-samples-generated-by-given/m-p/601358#M4906</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-11-04T12:45:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to create variables using random samples generated by given correlated matrix</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-create-variables-using-random-samples-generated-by-given/m-p/601369#M4907</link>
      <description>&lt;P&gt;Some of your questions are somewhat advanced. All are answered in Chapters 8-12 of &lt;EM&gt;Simulating Data with SAS&lt;/EM&gt; (Wicklin, 2013).&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Chapter 8 discusses simulating multivariate data from a specified distribution.&lt;/LI&gt;
&lt;LI&gt;Chapter 9 discusses simulating data when each component is from a different marginal distribution, such as positive values, binary values, etc.&lt;/LI&gt;
&lt;LI&gt;Chapter 10 discusses linear regression models.&lt;/LI&gt;
&lt;LI&gt;Chapter 11 discusses generalized linear models such as logistic models.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;For simulation, it is important to model either a set of data or a process with known properties. You haven't specified&amp;nbsp;any relationships between the variables, so I will just make some up. I assume you know how to construct a covariance matrix for the MVN data in your data. The following program simulates using the basic ideas in the blog post &lt;A href="https://blogs.sas.com/content/iml/2014/06/25/simulate-logistic-data.html" target="_self"&gt;"&lt;SPAN&gt;Simulating data for a logistic regression model.&lt;/SPAN&gt;"&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let N = 150;                                     /* N = sample size */
proc iml;
call randseed(1);     
mu = {45  0  0};   /* population mean */
Sigma = {10     0.1   0,
         0.1   1000   0.05,
         0      0.05  1};
/* X = (x1, x2, x3) ~ MVN(mu,Sigma). Then 
   and x3 is transformed to binary by x3 = (x3 &amp;gt; 0)  */
X = randnormal(&amp;amp;N, mu, Sigma); 
X[,3] = (X[,3] &amp;gt; 0);

/* Logistic model with parameters */
Intercept = -90;
beta = {2, -0.4, 3};
eta = Intercept + X*beta;           /* 2. linear model */
mu = logistic(eta);                 /* 3. transform by inverse logit */

/* 4. Simulate binary response. Notice that the 
      "probability of success" is a vector (SAS/IML 12.1)            */
y = j(&amp;amp;N,1);                             /* allocate response vector */
call randgen(y, "Bernoulli", mu);        /* simulate binary response */
 
/* 5. Write y and x1-x2 to data set*/
varNames = {"y"  "Age" "Time" "Gender"};
Out = y || X;                              /* simulated response in 1st column */
create LogisticData from Out[c=varNames];  /* no data is written yet */
append from Out;                           /* output this sample */
close LogisticData;
quit;

proc logistic data=LogisticData plots(only)=fitplot;
   class Gender;
   model y = Age Time Gender;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 04 Nov 2019 13:52:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-create-variables-using-random-samples-generated-by-given/m-p/601369#M4907</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2019-11-04T13:52:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to create variables using random samples generated by given correlated matrix</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-create-variables-using-random-samples-generated-by-given/m-p/601401#M4908</link>
      <description>&lt;P&gt;Thank you all so much for your input and time. I think I had a better idea to handle my questions.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Nov 2019 15:09:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-create-variables-using-random-samples-generated-by-given/m-p/601401#M4908</guid>
      <dc:creator>HappySASUE</dc:creator>
      <dc:date>2019-11-04T15:09:39Z</dc:date>
    </item>
  </channel>
</rss>

