Hello,
My problem is the following one:
I have 2 function A and B. The parameters m is in [0.001,30]. We have tau_1=1 and tau_2=1.
I wonder if there is a way plot the corrélation between my function A and B on SAS?
thank you for your help
The distribution of M determines the correlation between A(m) and B(m). If you choose M ~ lognormal you will get a different answer from if you choose M ~ gamma or M ~ exponential.
Since you didn't specify the distribution of M, the following DATA step chooses equally spaced values in [1,30] along with some small values. This should give the general idea of how to do the computation:
/* evaluate A(m) and B(m) for range of m
THE LOCATIONS OF m THAT YOU CHOOSE AFFECT THE CORRELATION */
data AB;
tau2 = 2;
do tau1 = 0.0001, 0.001, 0.01, 0.1, 1 to 30;
/* probably want a DISTRIBUTION for m */
do m = 0.0001, 0.001, 0.01, 0.1, 1 to 30;
c1 = -m/tau1;
c2 = -m/tau2;
A = (1 - exp(c1)) / c1 - exp(c1);
B = c2**2 * exp(c2);
output;
end;
end;
drop c1 c2;
run;
/* compute correlation matrices for each tau1 value */
proc corr data=AB noprint
outp=OutCorr(where=(_TYPE_="CORR") rename=(B=Corr));
by tau1;
var A B;
run;
/* we only want the correlation coefficient; extract the R[1,2] cell */
data Corr;
set OutCorr;
if mod(_N_,2)=1; /* Keep odd-numbered rows; delete even rows */
drop _TYPE_ _NAME_ A;
run;
title "Corr(A,B), tau2=2";
proc sgplot data=Corr;
series x=tau1 y=Corr;
run;
If you choose a distribution for M, then the inner loop will be
do i = 1 to 10000;
m = rand("disrib_name", params);
c1= ..; c2=..; etc;
end;
This might help:
I will move the post to stats section of forum also.
Thank you for your reply.
I have a technical question about the correlation matrix:
Do you know how to keep only the value of the corr between C_0 and P_0, C_1 and P_1, C_2 and P_2... in a table?
Am afraid I can't help you, hopefully in this forum area a Stato will be able to help. I am merely a programmer
@madix wrote:
Thank you for your reply.
I have a technical question about the correlation matrix:
Do you know how to keep only the value of the corr between C_0 and P_0, C_1 and P_1, C_2 and P_2... in a table?
It wouldn't hurt to show the code you used to generate that.
Assuming you used Proc Corr and want Pearson correlation statistics then the option OUTP=datassetname will place the statistics into a dataset named on the option.
I am not sure exactly what you mean by "between C_0 and P_0, C_1 and P_1, C_2 and P_2" but you should be able to transform the resulting dataset to have the contents and structure you want.
Why not show the relation between the two functions as:
proc fcmp outlib=sasuser.fcmp.math;
function A(m);
return ((1-exp(-m))/m - exp(-m));
endsub;
function B(m);
return (m**2 * exp(-m));
endsub;
run;
options cmplib=sasuser.fcmp;
data test;
do lm = log(.001) to log(30) by log(30/0.001)/100;
m = exp(lm);
A = A(m);
B = B(m);
output;
end;
run;
proc sgplot data=test;
series x=a y=b / markers
markerattrs=(symbol=circlefilled size=5)
lineattrs=(thickness=2);
run;
Could you clarify your statement? There are many kinds of correlations. Are you looking for cross-correlation of time series?
Interesting Relationship...
First thank you for all your reply.
For the correlation I meant the cov(X,Y) by std_X and std_y.
I would like to plot the correlation of the function A(m) and B(m) for m in [0.000001,30], tau1 fixed equal to 2 and tau2 in [0.0001,30].
the x axis will be tau2 and the y axis will be corr(A,B)
So there are no random variables in your problem? The variable M is not random with a distribution?
Do you have SAS/IML software or do you require the solution to use Base SAS?
The distribution of M determines the correlation between A(m) and B(m). If you choose M ~ lognormal you will get a different answer from if you choose M ~ gamma or M ~ exponential.
Since you didn't specify the distribution of M, the following DATA step chooses equally spaced values in [1,30] along with some small values. This should give the general idea of how to do the computation:
/* evaluate A(m) and B(m) for range of m
THE LOCATIONS OF m THAT YOU CHOOSE AFFECT THE CORRELATION */
data AB;
tau2 = 2;
do tau1 = 0.0001, 0.001, 0.01, 0.1, 1 to 30;
/* probably want a DISTRIBUTION for m */
do m = 0.0001, 0.001, 0.01, 0.1, 1 to 30;
c1 = -m/tau1;
c2 = -m/tau2;
A = (1 - exp(c1)) / c1 - exp(c1);
B = c2**2 * exp(c2);
output;
end;
end;
drop c1 c2;
run;
/* compute correlation matrices for each tau1 value */
proc corr data=AB noprint
outp=OutCorr(where=(_TYPE_="CORR") rename=(B=Corr));
by tau1;
var A B;
run;
/* we only want the correlation coefficient; extract the R[1,2] cell */
data Corr;
set OutCorr;
if mod(_N_,2)=1; /* Keep odd-numbered rows; delete even rows */
drop _TYPE_ _NAME_ A;
run;
title "Corr(A,B), tau2=2";
proc sgplot data=Corr;
series x=tau1 y=Corr;
run;
If you choose a distribution for M, then the inner loop will be
do i = 1 to 10000;
m = rand("disrib_name", params);
c1= ..; c2=..; etc;
end;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.
Find more tutorials on the SAS Users YouTube channel.