<?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: how to plot Exact Clopper Pearson confidence interval in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-plot-confidence-interval/m-p/638765#M189962</link>
    <description>&lt;P&gt;Thank you!!:)&lt;/P&gt;</description>
    <pubDate>Thu, 09 Apr 2020 18:31:16 GMT</pubDate>
    <dc:creator>yuwentaiwan</dc:creator>
    <dc:date>2020-04-09T18:31:16Z</dc:date>
    <item>
      <title>how to plot confidence interval</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-plot-confidence-interval/m-p/638453#M189856</link>
      <description>&lt;P&gt;&lt;FONT&gt;&lt;FONT&gt;克洛珀·皮爾森（Clopper Pearson），&lt;/FONT&gt;&lt;/FONT&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="未命名.png" style="width: 784px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/38057iE77B9171B08221D7/image-size/large?v=v2&amp;amp;px=999" role="button" title="未命名.png" alt="未命名.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT&gt;&lt;FONT&gt;這是n = 19，r = 3。&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT&gt;&lt;FONT&gt;我該如何繪製這張照片。&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT&gt;&lt;FONT&gt;謝謝！！&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data propci;

if sided = 1 then do;
zalpha=probit(1-(alpha));
end;
else if sided = 2 then do;
zalpha=probit(1-(alpha/2));
end;

** Exact Clopper Pearson;
x = round (n*p,0.1);

* Calculate the lower limit.;

v1 = 2*(n-x+1);
v2 = 2*x;

if sided = 1 then do;
a = 1-(alpha);
end;
else if sided = 2 then do;
a = 1-(alpha/2); 
end;

coef = (n-x+1)/x;
fscore = finv(a,v1,v2);
exact_lcl = 1/(1+coef*fscore);

* Calculate the upper limit.;

v11 = 2*(x+1);
v22 = 2*(n-x);
fscore2 = finv(a,v11,v22);
coef2 = (x+1)/(n-x);
numer = coef2*fscore2;
exact_ucl = numer/(1+numer);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 09 Apr 2020 02:55:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-plot-confidence-interval/m-p/638453#M189856</guid>
      <dc:creator>yuwentaiwan</dc:creator>
      <dc:date>2020-04-09T02:55:53Z</dc:date>
    </item>
    <item>
      <title>Re: how to plot Exact Clopper Pearson confidence interval</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-plot-confidence-interval/m-p/638512#M189876</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/315727"&gt;@yuwentaiwan&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for posting the nice graph.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is my reproduction with SAS. I've added a label to the x-axis.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="clopper_pearson.png" style="width: 624px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/38087i480C2FBCBA32EBAD/image-size/large?v=v2&amp;amp;px=999" role="button" title="clopper_pearson.png" alt="clopper_pearson.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Here's the program which created it:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Set parameters */

%let n=19; /* number of Bernoulli trials */
%let ph=3; /* observed number of successes ("p hat") */
%let alpha=0.05;

/* Compute probabilities */

data prob;
do _n_=0 to 1000;
  p=_n_/1000;
  p1=cdf('binom',&amp;amp;ph,p,&amp;amp;n);
  p2=cdf('binom',&amp;amp;ph-1,p,&amp;amp;n);
  output;
end;
run;

/* Compute Clopper-Pearson confidence interval */

data fdat;
c=1; n=&amp;amp;ph;    output;
c=2; n=&amp;amp;n-&amp;amp;ph; output;
run;

ods select none;
ods output binomial=bcl;
proc freq data=fdat;
weight n;
tables c / binomial alpha=&amp;amp;alpha;
run;
ods select all;

data _null_;
set bcl;
if name1=:'XL' then call symputx('lcl',put(nvalue1,6.4));
if name1=:'XU' then call symputx('ucl',put(nvalue1,9.7));
run;

/* Create the graph */

ods html style=journal2;
title bold "h(p) = P[X &amp;lt;= &amp;amp;ph] or h(p) = P[X &amp;lt;= %eval(&amp;amp;ph-1)] for X ~ Bin(&amp;amp;n, p)";

proc sgplot data=prob;
series x=p y=p1 / legendlabel="P[X&amp;lt;=&amp;amp;ph]";
series x=p y=p2 / legendlabel="P[X&amp;lt;=%eval(&amp;amp;ph-1)]" lineattrs=(pattern=2);
xaxis offsetmin=0.04 offsetmax=0.04;
yaxis offsetmin=0.04 offsetmax=0.04 label='h(p)';
dropline x=&amp;amp;lcl y=%sysevalf(1-&amp;amp;alpha/2) / dropto=both label="&amp;amp;lcl" lineattrs=(color=black);
dropline x=&amp;amp;ucl y=%sysevalf(&amp;amp;alpha/2)   / dropto=both label="&amp;amp;ucl" lineattrs=(color=black);
keylegend / location=inside position=top across=1 linelength=20;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;As you can see, the parameters &lt;FONT face="courier new,courier"&gt;n&lt;/FONT&gt;, &lt;FONT face="courier new,courier"&gt;ph&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;alpha&lt;/FONT&gt; are macro variable values. For certain parameter combinations the placement, e.g., of the legend should be modified in order to avoid collisions. The above code implements the &lt;EM&gt;two-sided&lt;/EM&gt;&amp;nbsp;Clopper-Pearson confidence interval (I used PROC FREQ rather than a DATA step to compute it). Please let me know if you need help with the one-sided case.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Apr 2020 07:59:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-plot-confidence-interval/m-p/638512#M189876</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-04-09T07:59:35Z</dc:date>
    </item>
    <item>
      <title>Re: how to plot Exact Clopper Pearson confidence interval</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-plot-confidence-interval/m-p/638765#M189962</link>
      <description>&lt;P&gt;Thank you!!:)&lt;/P&gt;</description>
      <pubDate>Thu, 09 Apr 2020 18:31:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-plot-confidence-interval/m-p/638765#M189962</guid>
      <dc:creator>yuwentaiwan</dc:creator>
      <dc:date>2020-04-09T18:31:16Z</dc:date>
    </item>
  </channel>
</rss>

