BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
madix
Obsidian | Level 7

fonction 1.PNGfonction2.PNG

 

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

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

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;

 

SGPlot2.png

View solution in original post

10 REPLIES 10
madix
Obsidian | Level 7

Thank you for your reply.

 

I have a technical question about the correlation matrix:

corr.PNG

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?

 

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Am afraid I can't help you, hopefully in this forum area a Stato will be able to help.  I am merely a programmer Smiley Happy

ballardw
Super User

@madix wrote:

Thank you for your reply.

 

I have a technical question about the correlation matrix:

corr.PNG

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.

PGStats
Opal | Level 21

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;

SGPlot2.png

 

PG
Rick_SAS
SAS Super FREQ

Could you clarify your statement? There are many kinds of correlations. Are you looking for cross-correlation of time series?

PGStats
Opal | Level 21

Interesting Relationship...

 

myfile.gif

 

PG
madix
Obsidian | Level 7

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)

Rick_SAS
SAS Super FREQ

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?

Rick_SAS
SAS Super FREQ

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;

 

SGPlot2.png

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
What is ANOVA?

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.

Discussion stats
  • 10 replies
  • 1696 views
  • 5 likes
  • 5 in conversation