<?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: SAS function for the skellam distribution in Statistical Procedures</title>
    <link>https://communities.sas.com/t5/Statistical-Procedures/SAS-function-for-the-skellam-distribution/m-p/616770#M29721</link>
    <description>&lt;P&gt;Calling&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 12 Jan 2020 11:03:44 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2020-01-12T11:03:44Z</dc:date>
    <item>
      <title>SAS function for the skellam distribution</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/SAS-function-for-the-skellam-distribution/m-p/616696#M29719</link>
      <description>&lt;P&gt;I am looking for a function that will calculate the CDF of the skellam distribution. I didn't find the skellam distribution in the list of available SAS CDF functions. I realize I could code it but before I do that (and then test it...!), I thought I'd ask if the function is available.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Sat, 11 Jan 2020 16:53:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/SAS-function-for-the-skellam-distribution/m-p/616696#M29719</guid>
      <dc:creator>BillT</dc:creator>
      <dc:date>2020-01-11T16:53:03Z</dc:date>
    </item>
    <item>
      <title>Re: SAS function for the skellam distribution</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/SAS-function-for-the-skellam-distribution/m-p/616720#M29720</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/38935"&gt;@BillT&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As far as I see, this distribution is not directly available in SAS. But, as you said, it's possible to code it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For starters (and for curiosity), I've written this code for the &lt;EM&gt;P&lt;/EM&gt;DF (and leave the cumulative summation for the CDF to you):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Compute pdf of the Skellam distribution */

%let mu1=5; /* parameter 1 */
%let mu2=2; /* parameter 2 */
%let c=7;   /* compute pdf for mean +/- c*sd */

data skellam(keep=x p);
m=&amp;amp;mu1-&amp;amp;mu2; /* mean */
t=&amp;amp;mu1+&amp;amp;mu2;
s=sqrt(t);   /* sd */
do x=floor(m-&amp;amp;c*s) to ceil(m+&amp;amp;c*s);
  p=exp(-t)*divide(&amp;amp;mu1,&amp;amp;mu2)**(x/2)*ibessel(abs(x),2*sqrt(&amp;amp;mu1*&amp;amp;mu2),0);
  output;
end;
run;

proc print data=skellam;
format p 16.14; /* e20.; */
run;

/* Simulate differences of independent Poisson random variables */

data sim;
call streaminit(27182818);
do i=1 to 1e6;
  x=rand('poisson',&amp;amp;mu1)-rand('poisson',&amp;amp;mu2);
  output;
end;
run;

proc means data=sim;
var x;
run; /* check mean and sd */

proc freq data=sim;
tables x / out=emp;
run;

/* Compare theoretical and empirical results */

data cmp(keep=x p f);
merge skellam
      emp(in=e);
by x;
if e then f=percent/100;
else f=0;
run;

proc sgplot data=cmp;
scatter x=x y=p;
scatter x=x y=f;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The plot looks good.&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for posting such an inspiring question!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit: I've used the formulas from Wikipedia:&amp;nbsp;&lt;A href="https://en.wikipedia.org/wiki/Skellam_distribution" target="_blank" rel="noopener"&gt;https://en.wikipedia.org/wiki/Skellam_distribution&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 11 Jan 2020 19:51:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/SAS-function-for-the-skellam-distribution/m-p/616720#M29720</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-01-11T19:51:17Z</dc:date>
    </item>
    <item>
      <title>Re: SAS function for the skellam distribution</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/SAS-function-for-the-skellam-distribution/m-p/616770#M29721</link>
      <description>&lt;P&gt;Calling&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 12 Jan 2020 11:03:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/SAS-function-for-the-skellam-distribution/m-p/616770#M29721</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-01-12T11:03:44Z</dc:date>
    </item>
    <item>
      <title>Re: SAS function for the skellam distribution</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/SAS-function-for-the-skellam-distribution/m-p/616775#M29722</link>
      <description>&lt;P&gt;Since&amp;nbsp;&lt;SPAN class="login-bold"&gt;&lt;A class="lia-link-navigation lia-page-link lia-user-name-link" href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733" target="_self"&gt;FreelanceReinha&lt;WBR /&gt;rd&lt;/A&gt;&amp;nbsp;has already provided the PDF, the only step left is to accumulate the PDF to form the CDF. As shown in the article &lt;A href="https://blogs.sas.com/content/iml/2015/03/06/custom-pdf-cdf.html" target="_self"&gt;"Create a customer PDF and CDF in SAS,"&amp;nbsp;&lt;/A&gt;&lt;/SPAN&gt;&lt;SPAN class="login-bold"&gt;there are two ways to proceed, depending upon how much precision you need.&amp;nbsp; In my article, I use the SAS/IML language, but the &lt;A href="https://blogs.sas.com/content/iml/2015/03/04/approximate-cdf.html" target="_self"&gt;"easy" way&lt;/A&gt; can also be implemented in the DATA step by using the LAG function.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 12 Jan 2020 11:28:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/SAS-function-for-the-skellam-distribution/m-p/616775#M29722</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2020-01-12T11:28:51Z</dc:date>
    </item>
    <item>
      <title>Re: SAS function for the skellam distribution</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/SAS-function-for-the-skellam-distribution/m-p/617092#M29732</link>
      <description>&lt;P&gt;Thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;. This is much appreciated!! works great. Now onto the second half..the CDF.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jan 2020 00:16:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/SAS-function-for-the-skellam-distribution/m-p/617092#M29732</guid>
      <dc:creator>BillT</dc:creator>
      <dc:date>2020-01-14T00:16:14Z</dc:date>
    </item>
    <item>
      <title>Re: SAS function for the skellam distribution</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/SAS-function-for-the-skellam-distribution/m-p/617510#M29745</link>
      <description>&lt;P&gt;to calculate the cumulative probabilities, I added a line before the 'output' statement of the skellam datastep:&lt;BR /&gt;'cp+p;'&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jan 2020 16:22:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/SAS-function-for-the-skellam-distribution/m-p/617510#M29745</guid>
      <dc:creator>BillT</dc:creator>
      <dc:date>2020-01-15T16:22:42Z</dc:date>
    </item>
    <item>
      <title>Re: SAS function for the skellam distribution</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/SAS-function-for-the-skellam-distribution/m-p/617529#M29746</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/38935"&gt;@BillT&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;to calculate the cumulative probabilities, I added a line before the 'output' statement of the skellam datastep:&lt;BR /&gt;'cp+p;'&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This should be fine. If in doubt, just increase the value of macro variable &lt;FONT face="courier new,courier"&gt;c&lt;/FONT&gt;. As soon as the largest computed &lt;FONT face="courier new,courier"&gt;cp&lt;/FONT&gt; values are equal to 1 (within the accuracy limits), you see that the omitted lower tail of the distribution (i.e., the sum of the &lt;FONT face="courier new,courier"&gt;p&lt;/FONT&gt; values for &lt;FONT face="courier new,courier"&gt;x&amp;lt;floor(m-&amp;amp;c*s)&lt;/FONT&gt;) was negligible.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jan 2020 17:12:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/SAS-function-for-the-skellam-distribution/m-p/617529#M29746</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-01-15T17:12:23Z</dc:date>
    </item>
  </channel>
</rss>

