<?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: Permutation test on correlations in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Permutation-test-on-correlations/m-p/917051#M361228</link>
    <description>&lt;P&gt;I would check the documentation for PROC IML and the HISTOGRAM function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could also create an output data set from your IML, and then run that through PROC SGPLOT, which will give you many options for controlling the appearance.&lt;/P&gt;</description>
    <pubDate>Tue, 20 Feb 2024 20:24:56 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2024-02-20T20:24:56Z</dc:date>
    <item>
      <title>Permutation test on correlations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Permutation-test-on-correlations/m-p/917034#M361220</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying (and struggling) to understand SAS syntax. I wanted to do a permutation test on the Pearsons correlation coefficient, and copied the below code&lt;SPAN&gt;(from the SAS page) into my editor.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;I thought I had it figured out, but nothing happens, or at least I don't get an output.&lt;/P&gt;&lt;P&gt;Can you tell me why?&lt;/P&gt;&lt;P&gt;the below code will in my understanding only do the permutation test on teh tobacco and cancer variable. But what if I would like to run the same test with on the correlation between alcohol and Tobacco and again on cancer and alcohol?&lt;/P&gt;&lt;P&gt;Can I do that fairly simple?&lt;/P&gt;&lt;P&gt;Thanks a lot&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="sas"&gt;OPTIONS LINESIZE=95;

DATA   test;
INFILE 'C:\Users\XXXXXXXXXXX.PRN'  FIRSTOBS=2;
INPUT  Cancer Tobacco Alcohol;

PROC PRINT;
RUN;

proc iml;
use test;
   read all var "tobacco" into X;
   read all var "cancer" into Y;
close;
 
start CorrCoeff(X, Y, method="Pearson");
   return ( corr(X||Y, method)[1,2] );   /* CORR returns a matrix; extract the correlation of the pair */
finish;
 
/* permutation test for correlation between two variables */
call randseed(12544);        /* set a random number seed */
B = 10000;                   /* total number of permutations */
PCorr = j(B, 1, .);          /* allocate vector for Pearson correlations */
PCorrObs = CorrCoeff(X, Y);  /* correlation for original data */
PCorr[1] = PCorrObs; 
do i = 2 to B;
   permY = ranperm(Y)`;      /* permute order of Y */
   PCorr[i] = CorrCoeff(X, permY); /* correlation between X and permuted Y */
end;
&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Feb 2024 18:57:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Permutation-test-on-correlations/m-p/917034#M361220</guid>
      <dc:creator>Martin_blaedel</dc:creator>
      <dc:date>2024-02-20T18:57:54Z</dc:date>
    </item>
    <item>
      <title>Re: Permutation test on correlations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Permutation-test-on-correlations/m-p/917038#M361223</link>
      <description>&lt;P&gt;Are there errors in the log?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;What output are you expecting? You would need a PRINT statement to see your data sets written to the output window or results window; you would need to use the CREATE statement to create a SAS data set with results.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Feb 2024 19:08:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Permutation-test-on-correlations/m-p/917038#M361223</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-02-20T19:08:01Z</dc:date>
    </item>
    <item>
      <title>Re: Permutation test on correlations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Permutation-test-on-correlations/m-p/917044#M361224</link>
      <description>&lt;P&gt;No errors on the log.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yeah, that is a good question I think I was expecting perhaps a permutation distribution curve, and/or a table with the p value.&amp;nbsp;&lt;/P&gt;&lt;P&gt;But I kind of suspect what you say about adding a print statement could solve some of the problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried at some point but perhaps I did it wrong. will try again.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Feb 2024 19:13:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Permutation-test-on-correlations/m-p/917044#M361224</guid>
      <dc:creator>Martin_blaedel</dc:creator>
      <dc:date>2024-02-20T19:13:28Z</dc:date>
    </item>
    <item>
      <title>Re: Permutation test on correlations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Permutation-test-on-correlations/m-p/917050#M361227</link>
      <description>&lt;P&gt;Hi again&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now I have corrected the code and i get my histogram. The code looks like the below now. However, I would like to control the incrementation on the X axis on the permutation distribution graph.&lt;/P&gt;&lt;P&gt;Do you by any chance know how to do that?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc iml;
use test;
   read all var "alcohol" into X;
   read all var "cancer" into Y;
close;
 
start CorrCoeff(X, Y, method="Pearson");
   return ( corr(X||Y, method)[1,2] );   /* CORR returns a matrix; extract the correlation of the pair */
finish;
 
/* permutation test for correlation between two variables */
call randseed(12544);        /* set a random number seed */
B = 10000;                   /* total number of permutations */
PCorr = j(B, 1, .);          /* allocate vector for Pearson correlations */
PCorrObs = CorrCoeff(X, Y);  /* correlation for original data */
PCorr[1] = PCorrObs; 
do i = 2 to B;
   permY = ranperm(Y)`;      /* permute order of Y */
   PCorr[i] = CorrCoeff(X, permY); /* correlation between X and permuted Y */
end;

print PCorrObs;
run;


pVal = sum( abs(PCorr)&amp;gt;= abs(PCorrObs) ) / B;   /* proportion of permutations with extreme corr */
print pVal;
 
title "Permutation Test with H0:corr(alcohol,Cancer)=0";
title2 "Distribution of Pearson Correlation (B=1000)";
refStmt = "refline " + char(PCorrObs) + " / axis=x lineattrs=(color=red);";
call histogram(PCorr) other=refStmt label="Pearson Correlation";

run;
quit;

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Feb 2024 20:15:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Permutation-test-on-correlations/m-p/917050#M361227</guid>
      <dc:creator>Martin_blaedel</dc:creator>
      <dc:date>2024-02-20T20:15:14Z</dc:date>
    </item>
    <item>
      <title>Re: Permutation test on correlations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Permutation-test-on-correlations/m-p/917051#M361228</link>
      <description>&lt;P&gt;I would check the documentation for PROC IML and the HISTOGRAM function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could also create an output data set from your IML, and then run that through PROC SGPLOT, which will give you many options for controlling the appearance.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Feb 2024 20:24:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Permutation-test-on-correlations/m-p/917051#M361228</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-02-20T20:24:56Z</dc:date>
    </item>
    <item>
      <title>Re: Permutation test on correlations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Permutation-test-on-correlations/m-p/917052#M361229</link>
      <description>&lt;P&gt;Thanks - those are great ideas.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will start by looking into that documentation.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Feb 2024 20:28:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Permutation-test-on-correlations/m-p/917052#M361229</guid>
      <dc:creator>Martin_blaedel</dc:creator>
      <dc:date>2024-02-20T20:28:47Z</dc:date>
    </item>
  </channel>
</rss>

