I want to simulate two parameters a* and b satisfying the following conditions. How should I simulate these two parameter so that the correlation of them is 0.8. Thanks much for the help!
I'm very sorry. That was a mistake on my part because I copied/pasted from another source.
From your follow-up post, I assume that N(0,2) means "mean=0 and stdDev=2." If so, the correct covariance matrix should be
COV a 0.015 0.196
COV b 0.196 4
which is the matrix in the second part of the problem. I will edit my solution. Thanks.
Thanks much for the information.
Flowing example you provided, I made up my outcorr data, which looks like following table
I use the following code
proc import datafile="....\outcorr.csv"
dbms=csv out=outcorr replace; run;
%let N = 60; /* sample size */
%let NumSamples = 100; /* number of samples */
proc simnormal data=work.outcorr outsim=SimMVN
numreal = %sysevalf(&N*&NumSamples)
seed = 12345; /* random number seed */
var a b;
run;
However, there is following error message
I am seeing the "outcorr" data has been normally read in. Do you have any idea of what caused this error message?
Again thanks much!
How was OUTCORR created? Can you show us (screen capture is okay) OUTCORR?
I will throw this question over to @Rick_SAS to see if he has any ideas why you are getting an error.
You can either use a TYPE=CORR or a TYPE=COV matrix as an input matrix to PROC SIMNORMAL. Here is both ways:
data outcorr(type=CORR);
input _TYPE_ $ 1-4 _NAME_ $ 5-6 a b;
datalines ;
MEAN 0 0
STD 0.1225 2
CORR a 1 0.8
CORR b 0.8 1
run;
proc simnormal data=work.outcorr outsim=SimMVN
numreal = %sysevalf(&N*&NumSamples)
seed = 12345; /* random number seed */
var a b;
run;
Or (the harder way, because you have to form the covariance matrix yourself😞
data outcorr(type=COV);
input _TYPE_ $ 1-4 _NAME_ $ 5-6 a b;
datalines ;
MEAN 0 0
COV a 0.015 0.196
COV b 0.196 4
run;
%let N = 60; /* sample size */
%let NumSamples = 100; /* number of samples */
proc simnormal data=work.outcorr outsim=SimMVN
numreal = %sysevalf(&N*&NumSamples)
seed = 12345; /* random number seed */
var a b;
run;
I want to make sure that the OP wants bivariate normal data. The initial post states
a ~ (0, 0.1225)
b ~ (0,2)
I do not know what that notation means. People seem to be interpreting it as
a ~ N(0, 0.1225)
b ~ N(0,2)
which seems likely, but worth verifying with the instructor of the class.
Thank you SOOO much for your quick response!
Yes, your code worked. The standard expression should be the following as you pointed out
a ~ N(0, 0.1225)
b ~ N(0, 2)
Could you please explain how did you get the numbers in the covariance matrix as following?
COV a 1.915 0.3873
COV b 0.3873 4.321
I'm very sorry. That was a mistake on my part because I copied/pasted from another source.
From your follow-up post, I assume that N(0,2) means "mean=0 and stdDev=2." If so, the correct covariance matrix should be
COV a 0.015 0.196
COV b 0.196 4
which is the matrix in the second part of the problem. I will edit my solution. Thanks.
Thank you!
when I changed it to
COV a 0.015 0.196
COV b 0.196 4
and run the code, it has the following error message
Please ignore my last message. the error message resolved.
I very much appreciate your help and expertise. Again thanks much!
@Rick_SAS wrote:
Here is the correct DATA step to create the input matrix for PROC SIMNORMAL:
data outcorr(type=COV); input _TYPE_ $ 1-4 _NAME_ $ 5-6 a b; datalines ; MEAN 0 0 STD 0.1225 2 COV a 1.915 0.3873 COV b 0.3873 4.321 run; %let N = 60; /* sample size */ %let NumSamples = 100; /* number of samples */ proc simnormal data=work.outcorr outsim=SimMVN numreal = %sysevalf(&N*&NumSamples) seed = 12345; /* random number seed */ var a b; run;
I want t make sure that the OP wants bivariate normal data. The initial post states
a ~ (0, 0.1225)
b ~ (0,2)
I do not know what that notation means. People seem to be interpreting it as
a ~ N(0, 0.1225)
b ~ N(0,2)
which seems likely, but worth verifying with the instructor of the class.
Well, that seems like an obvious error to me, now that you have pointed it out. COV matrix not CORR matrix. Thanks, @Rick_SAS
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.